Skip to content

Commit

Permalink
Merge branch 'master' into improve-keymap-defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ulidtko committed Feb 1, 2019
2 parents edd1a3b + 3c10161 commit c411974
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 38 deletions.
65 changes: 65 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Development Guide

## Getting started

The easiest way is to get the source of the `language-idris` package via the `apm`-tooling:

```bash
apm dev language-idris
```

This will install the package in the folder `~/github/language-idris`. You will then be able to use the development version of `language-idris` by invoking atom from any directory containing some idris files using

```bash
atom -d .
```

## Development process

Atom is basically a browser and when doing development it can be useful to open the dev console.

<kbd>Alt</kbd>+<kbd>Cmd</kbd><kbd>i</kbd> opens the developer console on Mac OS X. This enables you to see console logging output and exceptions.

You can edit the sourcecode in another atom window:

```
$~/github/language-idris> atom .
```

Anytime you want to restart your project with the latest changes, you can just reload the window using `Window: Reload`.

## Code Structure

```bash
~/github/language-idris/lib (master %)$ tree
.
├── idris-controller.coffee
├── idris-ide-mode.coffee
├── idris-model.coffee
├── language-idris.coffee
├── utils
│   ├── Logger.coffee
│   ├── dom.coffee
│   ├── editor.coffee
│   ├── highlighter.coffee
│   ├── ipkg.coffee
│   ├── js.coffee
│   ├── parse.coffee
│   ├── sexp-formatter.coffee
│   └── symbol.coffee
└── views
├── apropos-view.coffee
├── holes-view.coffee
├── information-view.coffee
├── panel-view.coffee
└── repl-view.coffee
```

The best point to get started is to dig into `idris-controller.coffee`. Almost all defined commands talk to a spawned idris process using the [Idris IDE protocol](http://docs.idris-lang.org/en/latest/reference/ide-protocol.html). This protocol communicates with Idris via S-Exp Expressions. If you want to see this communication have a look at `utils/Logger.coffee`.

In order to send a command to idris, you will probably need some information from the current editor context. There are plenty of examples in the code and a helper package in the `utils` section. Once you have a reply you will probably need to format it. This can be done via one of the `highlighters`. Again, this is something which occurs again and again in the code.


## Specs

There are (too) few tests defined in the spec directory. You can execute them using `Window: Run package specs`.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,4 @@ There is more information available in a in a [separate documentation](https://g

## Development

To work on this plugin you need to clone it into your atom directory
and rename the folder to `language-idris` or the package settings won't get picked up.
Then you need an `apm install` from the `language-idris` folder to install the dependencies.

Or you can execute `apm dev language-idris`. This will install the package in a separate directory and you need to start
Atom in dev-mode to load the development packages (`atom -d your/folder`).
see the [Development Guide](DEVELOPMENT.md)
2 changes: 1 addition & 1 deletion grammars/language-idris.cson
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ patterns:
}
{
name: 'keyword.operator.function.infix.idris'
begin: '`'
begin: '`(?![\{|\(])'
beginCaptures:
0:
name: 'punctuation.definition.entity.idris'
Expand Down
2 changes: 2 additions & 0 deletions keymaps/language-idris.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ctrl-i t": "language-idris:type-of",
"ctrl-i w": "language-idris:make-with",
"ctrl-i enter": "language-idris:open-repl",
"escape": "language-idris:close-information-view"

"ctrl-alt-a": "language-idris:legacy-keymap-notice",
"ctrl-alt-b": "language-idris:legacy-keymap-notice",
Expand Down Expand Up @@ -44,6 +45,7 @@
"cmd-i t": "language-idris:type-of",
"cmd-i w": "language-idris:make-with",
"cmd-i enter": "language-idris:open-repl",
"escape": "language-idris:close-information-view"

"cmd-alt-a": "language-idris:legacy-keymap-notice",
"cmd-alt-b": "language-idris:legacy-keymap-notice",
Expand Down
57 changes: 34 additions & 23 deletions lib/idris-controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'atom-message-panel'
InformationView = require './views/information-view'
HolesView = require './views/holes-view'
Logger = require './Logger'
Logger = require './utils/Logger'
IdrisModel = require './idris-model'
Ipkg = require './utils/ipkg'
Symbol = require './utils/symbol'
Expand Down Expand Up @@ -31,6 +31,7 @@ class IdrisController
'language-idris:add-proof-clause': @runCommand @doAddProofClause
'language-idris:browse-namespace': @runCommand @doBrowseNamespace
'language-idris:legacy-keymap-notice': migrations.showKeymapDeprecationNotice
'language-idris:close-information-view': @hideAndClearMessagePanel

isIdrisFile: (uri) ->
uri?.match? /\.idr$/
Expand Down Expand Up @@ -72,14 +73,14 @@ class IdrisController
@statusbar.destroy()

# clear the message panel and optionally display a new title
clearMessagePanel: (title) ->
clearMessagePanel: (title) =>
@messages.attach()
@messages.show()
@messages.clear()
@messages.setTitle title, true if title?

# hide the message panel
hideAndClearMessagePanel: () ->
hideAndClearMessagePanel: () =>
@clearMessagePanel()
@messages.hide()

Expand Down Expand Up @@ -191,6 +192,7 @@ class IdrisController
@saveFile editor
uri = editor.getURI()
word = Symbol.serializeWord editorHelper.getWordUnderCursor(editor)

@clearMessagePanel 'Idris: Searching type of <tt>' + word + '</tt> ...'

successHandler = ({ responseType, msg }) =>
Expand Down Expand Up @@ -239,11 +241,13 @@ class IdrisController
@saveFile editor
uri = editor.getURI()
line = editor.getLastCursor().getBufferRow()
word = editorHelper.getWordUnderCursor editor
# by adding a clause we make sure that the word is
# not treated as a symbol
word = ' ' + editorHelper.getWordUnderCursor editor

@clearMessagePanel 'Idris: Add clause ...'

successHandler = ({ responseType, msg }) =>
successHandler = ({ responseType, msg }) =>
[clause] = @prefixLiterateClause msg

@hideAndClearMessagePanel()
Expand Down Expand Up @@ -322,12 +326,14 @@ class IdrisController
editor.moveToBeginningOfLine()
editor.moveUp()


@model
.load uri
.filter ({ responseType }) -> responseType == 'return'
.flatMap => @model.makeWith line + 1, word
.subscribe successHandler, @displayErrors
if (word?.length)
@model
.load uri
.filter ({ responseType }) -> responseType == 'return'
.flatMap => @model.makeWith line + 1, word
.subscribe successHandler, @displayErrors
else
@clearMessagePanel "Idris: Illegal position to make a with view"

# construct a lemma from a hole
doMakeLemma: ({ target }) =>
Expand Down Expand Up @@ -401,6 +407,7 @@ class IdrisController

editor.transact ->
# Delete old line, insert the new case block
editor.moveToBeginningOfLine()
editor.deleteLine()
editor.insertText clause
# And move the cursor to the beginning of
Expand Down Expand Up @@ -447,18 +454,22 @@ class IdrisController
[res] = msg

@hideAndClearMessagePanel()

editor.transact ->
# Move the cursor to the beginning of the word
editor.moveToBeginningOfWord()
# Because the ? in the Holes isn't part of
# the word, we move left once, and then select two
# words
editor.moveLeft()
editor.selectToEndOfWord()
editor.selectToEndOfWord()
# And then replace the replacement with the guess..
editor.insertText res
console.log res
if (res.startsWith("?"))
# proof search returned a new hole
@clearMessagePanel 'Idris: Searching proof was not successful.'
else
editor.transact ->
# Move the cursor to the beginning of the word
editor.moveToBeginningOfWord()
# Because the ? in the Holes isn't part of
# the word, we move left once, and then select two
# words
editor.moveLeft()
editor.selectToEndOfWord()
editor.selectToEndOfWord()
# And then replace the replacement with the guess..
editor.insertText res

@model
.load uri
Expand Down
10 changes: 7 additions & 3 deletions lib/idris-ide-mode.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Logger = require './Logger'
Logger = require './utils/Logger'
sexpFormatter = require './utils/sexp-formatter'
parse = require './parse'
parse = require './utils/parse'
{ EventEmitter } = require 'events'
{ spawn } = require 'child_process'

Expand All @@ -26,8 +26,12 @@ class IdrisIdeMode extends EventEmitter
else
[]

tabLength = atom.config.get('editor.tabLength', scope: ['source.idris'])
configParams = ['--ide-mode', '--indent-with=' + tabLength,
'--indent-clause=' + tabLength]

parameters =
['--ide-mode'].concat pkgs, options
configParams.concat pkgs, options

options =
if compilerOptions.src
Expand Down
2 changes: 1 addition & 1 deletion lib/idris-model.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IdrisIdeMode = require './idris-ide-mode'
Logger = require './Logger'
Logger = require './utils/Logger'
Rx = require 'rx-lite'
JS = require './utils/js'
path = require 'path'
Expand Down
2 changes: 1 addition & 1 deletion lib/Logger.coffee → lib/utils/Logger.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fs = require 'fs'
sexpFormatter = require './utils/sexp-formatter'
sexpFormatter = require './sexp-formatter'

class Logger
logFile: "log.log"
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/ipkg.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Rx = require 'rx-lite'

optionsRegexp = /opts\s*=\s*\"([^\"]*)\"/
sourcedirRegexp = /sourcedir\s*=\s*([a-zA-Z/0-9.]+)/
pkgsRegexp = /pkgs\s*=\s*([a-zA-Z/0-9., ]+)/
pkgsRegexp = /pkgs\s*=\s*(([a-zA-Z/0-9., ]+\s{0,1})*)/

# Find all ipkg-files in a directory and returns
# an observable of an array of files
Expand Down
3 changes: 3 additions & 0 deletions lib/parse.coffee → lib/utils/parse.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{ parse, text, lang } = require 'bennu'
{ stream } = require 'nu-stream'

# this module defines the parse required to deal with S-Expressions
# as used for the communication with the Idris IDE

streamToString = (s) -> stream.toArray(s).join ''

# bool
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "language-idris",
"main": "./lib/language-idris",
"version": "0.4.10",
"version": "0.5.0",
"private": true,
"description": "A plugin for developing with Idris",
"repository": "https://github.com/idris-hackers/atom-language-idris",
Expand Down
2 changes: 1 addition & 1 deletion spec/parse-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sexpFormatter = require '../lib/utils/sexp-formatter'
parse = require '../lib/parse'
parse = require '../lib/utils/parse'
runP = require('bennu').parse.run

test1 = "(:protocol-version 1 0)"
Expand Down

0 comments on commit c411974

Please sign in to comment.