Skip to content

Commit

Permalink
get documentation or types for operators
Browse files Browse the repository at this point in the history
fixes #66
  • Loading branch information
archaeron committed Sep 19, 2015
1 parent 2beedd9 commit e7f110a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Fixed

- get documentation or types for operators [#66](https://github.com/idris-hackers/atom-language-idris/issues/66)

## v0.3.0

### Added
Expand Down
11 changes: 6 additions & 5 deletions lib/idris-controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ StatusIndicator = require './views/status-indicator-view'
Logger = require './Logger'
IdrisModel = require './idris-model'
Ipkg = require './utils/ipkg'
Symbol = require './utils/symbol'

class IdrisController

Expand All @@ -32,10 +33,11 @@ class IdrisController
@model.stop()
@statusbar.destroy()

# get the word or operator under the cursor
getWordUnderCursor: (editorView) ->
editor = editorView.model
options =
wordRegex: /^[ ]*$|[^\s\/\\\(\)":,\.;<>~!@#\$%\^&\*\|\+=\[\]\{\}`\?\-…]+/g
wordRegex: /(^[ ]*$|[^\s\/\\\(\)":,\.;<>~!@#\$%\^&\*\|\+=\[\]\{\}`\?\-…]+)|(\?[-!#\$%&\*\+\.\/<=>@\\\^\|~:]+|[-!#\$%&\*\+\.\/<=>@\\\^\|~:][-!#\$%&\*\+\.\/<=>@\\\^\|~:\?]*)+/g
cursorPosition = editor.getLastCursor().getCurrentWordBufferRange options
editor.getTextInBufferRange cursorPosition

Expand Down Expand Up @@ -88,7 +90,7 @@ class IdrisController
.subscribe successHandler, @displayErrors

getDocsForWord: ({target}) =>
word = @getWordUnderCursor target
word = Symbol.serializeWord @getWordUnderCursor(target)

successHandler = ({responseType, msg}) =>
[type, highlightingInfo] = msg
Expand All @@ -109,7 +111,7 @@ class IdrisController
editor = target.model
@saveFile editor
uri = editor.getURI()
word = @getWordUnderCursor target
word = Symbol.serializeWord @getWordUnderCursor(target)

successHandler = ({responseType, msg}) =>
[type, highlightingInfo] = msg
Expand Down Expand Up @@ -237,7 +239,6 @@ class IdrisController
editor.insertText param2[1]
editor.insertNewlineBelow()


@model
.load uri
.filter ({responseType}) -> responseType == 'return'
Expand Down Expand Up @@ -316,7 +317,7 @@ class IdrisController
.subscribe successHandler, @displayErrors

printDefinition: ({target}) =>
word = @getWordUnderCursor target
word = Symbol.serializeWord @getWordUnderCursor(target)

successHandler = ({responseType, msg}) =>
[type, highlightingInfo] = msg
Expand Down
19 changes: 19 additions & 0 deletions lib/utils/symbol.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
operatorRegex = ///(
\?[-!#\$%&\*\+\.\/<=>@\\\^\|~:]+ # starts with ?, has at least one more opchar
| [-!#\$%&\*\+\.\/<=>@\\\^\|~:][-!#\$%&\*\+\.\/<=>@\\\^\|~:\?]* # doesn't start with ?
) ///

isOperator = (chars) ->
!! chars.match(operatorRegex)

# puts parenthesis around a word if it's an operator
serializeWord = (word) ->
if isOperator word
"(#{word})"
else
word

module.exports =
operatorRegex: operatorRegex
isOperator: isOperator
serializeWord: serializeWord

0 comments on commit e7f110a

Please sign in to comment.