From 22bcc5cefcc45f9328779a2b48a060cc7d2be6b7 Mon Sep 17 00:00:00 2001 From: zjhmale Date: Wed, 7 Sep 2016 11:07:34 +0800 Subject: [PATCH] highlight errors --- lib/idris-controller.coffee | 30 ++++++++++++++++++++++++-- lib/idris-model.coffee | 1 + styles/highlight.atom-text-editor.less | 21 ++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 styles/highlight.atom-text-editor.less diff --git a/lib/idris-controller.coffee b/lib/idris-controller.coffee index df2cd46..9341251 100644 --- a/lib/idris-controller.coffee +++ b/lib/idris-controller.coffee @@ -9,6 +9,7 @@ Symbol = require './utils/symbol' editorHelper = require './utils/editor' class IdrisController + errorMarkers: [] getCommands: -> 'language-idris:type-of': @runCommand @getTypeForWord @@ -28,6 +29,17 @@ class IdrisController isIdrisFile: (uri) -> uri?.match? /\.idr$/ + + createMarker: (editor, range, type) -> + marker = editor.markBufferRange(range, invalidate: 'never') + editor.decorateMarker marker, + type: type + class: 'highlight-idris-error' + marker + + destroyMarkers: () -> + for marker in @errorMarkers + marker.destroy() destroy: -> if @model @@ -44,6 +56,7 @@ class IdrisController editor.getTextInBufferRange cursorPosition initialize: (compilerOptions) -> + @destroyMarkers() if !@model @model = new IdrisModel @messages = new MessagePanelView @@ -416,9 +429,22 @@ class IdrisController className: 'idris-error' for warning in err.warnings + line = warning[1][0] + character = warning[1][1] @messages.add new LineMessageView - line: warning[1][0] - character: warning[1][1] + line: line + character: character message: warning[3] + + editor = atom.workspace.getActiveTextEditor() + if line > 0 && warning[0].replace("./", err.cwd + "/") == editor.getURI() + startPoint = warning[1] + startPoint[0] = startPoint[0] - 1 + endPoint = warning[2] + endPoint[0] = endPoint[0] - 1 + gutterMarker = @createMarker editor, [startPoint, endPoint], 'line-number' + lineMarker = @createMarker editor, [[line - 1, character - 1], [line, 0]], 'line' + @errorMarkers.push gutterMarker + @errorMarkers.push lineMarker module.exports = IdrisController diff --git a/lib/idris-model.coffee b/lib/idris-model.coffee index b087d95..e6aa6af 100644 --- a/lib/idris-model.coffee +++ b/lib/idris-model.coffee @@ -53,6 +53,7 @@ class IdrisModel message: ret[1] warnings: @warnings[id] highlightInformation: ret[2] + cwd: @compilerOptions.src subject.onCompleted() delete @subjects[id] when ':write-string' diff --git a/styles/highlight.atom-text-editor.less b/styles/highlight.atom-text-editor.less new file mode 100644 index 0000000..4c26af3 --- /dev/null +++ b/styles/highlight.atom-text-editor.less @@ -0,0 +1,21 @@ +@import "syntax-variables"; + +@red-color: @syntax-color-removed; + +atom-text-editor::shadow +{ + .gutter .line-number + { + &.highlight-idris-error + { + background-color: @red-color; + } + } + .line + { + &.highlight-idris-error + { + background-color: lighten(@red-color, 20%); + } + } +} \ No newline at end of file