diff --git a/CHANGELOG.md b/CHANGELOG.md index 12e9db8..1889829 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/idris-controller.coffee b/lib/idris-controller.coffee index adacdcc..d5c2dec 100644 --- a/lib/idris-controller.coffee +++ b/lib/idris-controller.coffee @@ -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 @@ -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 @@ -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 @@ -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 @@ -237,7 +239,6 @@ class IdrisController editor.insertText param2[1] editor.insertNewlineBelow() - @model .load uri .filter ({responseType}) -> responseType == 'return' @@ -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 diff --git a/lib/utils/symbol.coffee b/lib/utils/symbol.coffee new file mode 100644 index 0000000..688e7fa --- /dev/null +++ b/lib/utils/symbol.coffee @@ -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