Skip to content

Commit c411974

Browse files
authored
Merge branch 'master' into improve-keymap-defaults
2 parents edd1a3b + 3c10161 commit c411974

File tree

12 files changed

+118
-38
lines changed

12 files changed

+118
-38
lines changed

DEVELOPMENT.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Development Guide
2+
3+
## Getting started
4+
5+
The easiest way is to get the source of the `language-idris` package via the `apm`-tooling:
6+
7+
```bash
8+
apm dev language-idris
9+
```
10+
11+
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
12+
13+
```bash
14+
atom -d .
15+
```
16+
17+
## Development process
18+
19+
Atom is basically a browser and when doing development it can be useful to open the dev console.
20+
21+
<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.
22+
23+
You can edit the sourcecode in another atom window:
24+
25+
```
26+
$~/github/language-idris> atom .
27+
```
28+
29+
Anytime you want to restart your project with the latest changes, you can just reload the window using `Window: Reload`.
30+
31+
## Code Structure
32+
33+
```bash
34+
~/github/language-idris/lib (master %)$ tree
35+
.
36+
├── idris-controller.coffee
37+
├── idris-ide-mode.coffee
38+
├── idris-model.coffee
39+
├── language-idris.coffee
40+
├── utils
41+
│   ├── Logger.coffee
42+
│   ├── dom.coffee
43+
│   ├── editor.coffee
44+
│   ├── highlighter.coffee
45+
│   ├── ipkg.coffee
46+
│   ├── js.coffee
47+
│   ├── parse.coffee
48+
│   ├── sexp-formatter.coffee
49+
│   └── symbol.coffee
50+
└── views
51+
├── apropos-view.coffee
52+
├── holes-view.coffee
53+
├── information-view.coffee
54+
├── panel-view.coffee
55+
└── repl-view.coffee
56+
```
57+
58+
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`.
59+
60+
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.
61+
62+
63+
## Specs
64+
65+
There are (too) few tests defined in the spec directory. You can execute them using `Window: Run package specs`.

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,4 @@ There is more information available in a in a [separate documentation](https://g
5454

5555
## Development
5656

57-
To work on this plugin you need to clone it into your atom directory
58-
and rename the folder to `language-idris` or the package settings won't get picked up.
59-
Then you need an `apm install` from the `language-idris` folder to install the dependencies.
60-
61-
Or you can execute `apm dev language-idris`. This will install the package in a separate directory and you need to start
62-
Atom in dev-mode to load the development packages (`atom -d your/folder`).
57+
see the [Development Guide](DEVELOPMENT.md)

grammars/language-idris.cson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ patterns:
106106
}
107107
{
108108
name: 'keyword.operator.function.infix.idris'
109-
begin: '`'
109+
begin: '`(?![\{|\(])'
110110
beginCaptures:
111111
0:
112112
name: 'punctuation.definition.entity.idris'

keymaps/language-idris.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"ctrl-i t": "language-idris:type-of",
1515
"ctrl-i w": "language-idris:make-with",
1616
"ctrl-i enter": "language-idris:open-repl",
17+
"escape": "language-idris:close-information-view"
1718

1819
"ctrl-alt-a": "language-idris:legacy-keymap-notice",
1920
"ctrl-alt-b": "language-idris:legacy-keymap-notice",
@@ -44,6 +45,7 @@
4445
"cmd-i t": "language-idris:type-of",
4546
"cmd-i w": "language-idris:make-with",
4647
"cmd-i enter": "language-idris:open-repl",
48+
"escape": "language-idris:close-information-view"
4749

4850
"cmd-alt-a": "language-idris:legacy-keymap-notice",
4951
"cmd-alt-b": "language-idris:legacy-keymap-notice",

lib/idris-controller.coffee

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'atom-message-panel'
33
InformationView = require './views/information-view'
44
HolesView = require './views/holes-view'
5-
Logger = require './Logger'
5+
Logger = require './utils/Logger'
66
IdrisModel = require './idris-model'
77
Ipkg = require './utils/ipkg'
88
Symbol = require './utils/symbol'
@@ -31,6 +31,7 @@ class IdrisController
3131
'language-idris:add-proof-clause': @runCommand @doAddProofClause
3232
'language-idris:browse-namespace': @runCommand @doBrowseNamespace
3333
'language-idris:legacy-keymap-notice': migrations.showKeymapDeprecationNotice
34+
'language-idris:close-information-view': @hideAndClearMessagePanel
3435

3536
isIdrisFile: (uri) ->
3637
uri?.match? /\.idr$/
@@ -72,14 +73,14 @@ class IdrisController
7273
@statusbar.destroy()
7374

7475
# clear the message panel and optionally display a new title
75-
clearMessagePanel: (title) ->
76+
clearMessagePanel: (title) =>
7677
@messages.attach()
7778
@messages.show()
7879
@messages.clear()
7980
@messages.setTitle title, true if title?
8081

8182
# hide the message panel
82-
hideAndClearMessagePanel: () ->
83+
hideAndClearMessagePanel: () =>
8384
@clearMessagePanel()
8485
@messages.hide()
8586

@@ -191,6 +192,7 @@ class IdrisController
191192
@saveFile editor
192193
uri = editor.getURI()
193194
word = Symbol.serializeWord editorHelper.getWordUnderCursor(editor)
195+
194196
@clearMessagePanel 'Idris: Searching type of <tt>' + word + '</tt> ...'
195197

196198
successHandler = ({ responseType, msg }) =>
@@ -239,11 +241,13 @@ class IdrisController
239241
@saveFile editor
240242
uri = editor.getURI()
241243
line = editor.getLastCursor().getBufferRow()
242-
word = editorHelper.getWordUnderCursor editor
244+
# by adding a clause we make sure that the word is
245+
# not treated as a symbol
246+
word = ' ' + editorHelper.getWordUnderCursor editor
243247

244248
@clearMessagePanel 'Idris: Add clause ...'
245249

246-
successHandler = ({ responseType, msg }) =>
250+
successHandler = ({ responseType, msg }) =>
247251
[clause] = @prefixLiterateClause msg
248252

249253
@hideAndClearMessagePanel()
@@ -322,12 +326,14 @@ class IdrisController
322326
editor.moveToBeginningOfLine()
323327
editor.moveUp()
324328

325-
326-
@model
327-
.load uri
328-
.filter ({ responseType }) -> responseType == 'return'
329-
.flatMap => @model.makeWith line + 1, word
330-
.subscribe successHandler, @displayErrors
329+
if (word?.length)
330+
@model
331+
.load uri
332+
.filter ({ responseType }) -> responseType == 'return'
333+
.flatMap => @model.makeWith line + 1, word
334+
.subscribe successHandler, @displayErrors
335+
else
336+
@clearMessagePanel "Idris: Illegal position to make a with view"
331337

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

402408
editor.transact ->
403409
# Delete old line, insert the new case block
410+
editor.moveToBeginningOfLine()
404411
editor.deleteLine()
405412
editor.insertText clause
406413
# And move the cursor to the beginning of
@@ -447,18 +454,22 @@ class IdrisController
447454
[res] = msg
448455

449456
@hideAndClearMessagePanel()
450-
451-
editor.transact ->
452-
# Move the cursor to the beginning of the word
453-
editor.moveToBeginningOfWord()
454-
# Because the ? in the Holes isn't part of
455-
# the word, we move left once, and then select two
456-
# words
457-
editor.moveLeft()
458-
editor.selectToEndOfWord()
459-
editor.selectToEndOfWord()
460-
# And then replace the replacement with the guess..
461-
editor.insertText res
457+
console.log res
458+
if (res.startsWith("?"))
459+
# proof search returned a new hole
460+
@clearMessagePanel 'Idris: Searching proof was not successful.'
461+
else
462+
editor.transact ->
463+
# Move the cursor to the beginning of the word
464+
editor.moveToBeginningOfWord()
465+
# Because the ? in the Holes isn't part of
466+
# the word, we move left once, and then select two
467+
# words
468+
editor.moveLeft()
469+
editor.selectToEndOfWord()
470+
editor.selectToEndOfWord()
471+
# And then replace the replacement with the guess..
472+
editor.insertText res
462473

463474
@model
464475
.load uri

lib/idris-ide-mode.coffee

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Logger = require './Logger'
1+
Logger = require './utils/Logger'
22
sexpFormatter = require './utils/sexp-formatter'
3-
parse = require './parse'
3+
parse = require './utils/parse'
44
{ EventEmitter } = require 'events'
55
{ spawn } = require 'child_process'
66

@@ -26,8 +26,12 @@ class IdrisIdeMode extends EventEmitter
2626
else
2727
[]
2828

29+
tabLength = atom.config.get('editor.tabLength', scope: ['source.idris'])
30+
configParams = ['--ide-mode', '--indent-with=' + tabLength,
31+
'--indent-clause=' + tabLength]
32+
2933
parameters =
30-
['--ide-mode'].concat pkgs, options
34+
configParams.concat pkgs, options
3135

3236
options =
3337
if compilerOptions.src

lib/idris-model.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IdrisIdeMode = require './idris-ide-mode'
2-
Logger = require './Logger'
2+
Logger = require './utils/Logger'
33
Rx = require 'rx-lite'
44
JS = require './utils/js'
55
path = require 'path'

lib/Logger.coffee renamed to lib/utils/Logger.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fs = require 'fs'
2-
sexpFormatter = require './utils/sexp-formatter'
2+
sexpFormatter = require './sexp-formatter'
33

44
class Logger
55
logFile: "log.log"

lib/utils/ipkg.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Rx = require 'rx-lite'
44

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

99
# Find all ipkg-files in a directory and returns
1010
# an observable of an array of files

lib/parse.coffee renamed to lib/utils/parse.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{ parse, text, lang } = require 'bennu'
22
{ stream } = require 'nu-stream'
33

4+
# this module defines the parse required to deal with S-Expressions
5+
# as used for the communication with the Idris IDE
6+
47
streamToString = (s) -> stream.toArray(s).join ''
58

69
# bool

0 commit comments

Comments
 (0)