Skip to content

Commit dc084bf

Browse files
committed
highlight errors
1 parent 7a4bd7b commit dc084bf

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

lib/idris-controller.coffee

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Symbol = require './utils/symbol'
99
editorHelper = require './utils/editor'
1010

1111
class IdrisController
12+
errorMarkers: []
1213

1314
getCommands: ->
1415
'language-idris:type-of': @runCommand @getTypeForWord
@@ -28,6 +29,17 @@ class IdrisController
2829

2930
isIdrisFile: (uri) ->
3031
uri?.match? /\.idr$/
32+
33+
createMarker: (editor, range, type) ->
34+
marker = editor.markBufferRange(range, invalidate: 'never')
35+
editor.decorateMarker marker,
36+
type: type
37+
class: 'highlight-idris-error'
38+
marker
39+
40+
destroyMarkers: () ->
41+
for marker in @errorMarkers
42+
marker.destroy()
3143

3244
destroy: ->
3345
if @model
@@ -44,6 +56,7 @@ class IdrisController
4456
editor.getTextInBufferRange cursorPosition
4557

4658
initialize: (compilerOptions) ->
59+
@destroyMarkers()
4760
if !@model
4861
@model = new IdrisModel
4962
@messages = new MessagePanelView
@@ -416,10 +429,25 @@ class IdrisController
416429
className: 'idris-error'
417430

418431
for warning in err.warnings
432+
line = warning[1][0]
433+
character = warning[1][1]
434+
uri = warning[0].replace("./", err.cwd + "/")
435+
419436
@messages.add new LineMessageView
420-
line: warning[1][0]
421-
character: warning[1][1]
437+
line: line
438+
character: character
422439
message: warning[3]
423-
file: warning[0].replace("./", err.cwd + "/")
440+
file: uri
441+
442+
editor = atom.workspace.getActiveTextEditor()
443+
if line > 0 && uri == editor.getURI()
444+
startPoint = warning[1]
445+
startPoint[0] = startPoint[0] - 1
446+
endPoint = warning[2]
447+
endPoint[0] = endPoint[0] - 1
448+
gutterMarker = @createMarker editor, [startPoint, endPoint], 'line-number'
449+
lineMarker = @createMarker editor, [[line - 1, character - 1], [line, 0]], 'line'
450+
@errorMarkers.push gutterMarker
451+
@errorMarkers.push lineMarker
424452

425453
module.exports = IdrisController
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import "syntax-variables";
2+
3+
@red-color: @syntax-color-removed;
4+
5+
atom-text-editor::shadow
6+
{
7+
.gutter .line-number
8+
{
9+
&.highlight-idris-error
10+
{
11+
background-color: @red-color;
12+
}
13+
}
14+
.line
15+
{
16+
&.highlight-idris-error
17+
{
18+
background-color: lighten(@red-color, 20%);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)