This repository was archived by the owner on Feb 1, 2019. It is now read-only.
File tree 1 file changed +20
-5
lines changed
1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -20,17 +20,32 @@ def output_to_diagnostics(output):
20
20
origin = problem ['origin' ]
21
21
real_message = '[{}] {}: {}' .format (section , origin , message )
22
22
for code in problem ['affected_code' ]:
23
+ """
24
+ Line position and character offset should be zero-based
25
+ according to LSP, but row and column positions of coala
26
+ are None or one-based number.
27
+ coala uses None for convenience. None for column means the
28
+ whole line while None for line means the whole file.
29
+ """
30
+ def convert_offset (x ): return x - 1 if x else x
31
+ start_line = convert_offset (code ['start' ]['line' ])
32
+ start_char = convert_offset (code ['start' ]['column' ])
33
+ end_line = convert_offset (code ['end' ]['line' ])
34
+ end_char = convert_offset (code ['end' ]['column' ])
35
+ if start_char is None or end_char is None :
36
+ start_char = 0
37
+ end_line = start_line + 1
38
+ end_char = 0
23
39
res .append ({
24
40
'severity' : severity ,
25
41
'range' : {
26
42
'start' : {
27
- # Trick: VS Code starts from 0?
28
- 'line' : code ['start' ]['line' ] - 1 ,
29
- 'character' : code ['start' ]['column' ]
43
+ 'line' : start_line ,
44
+ 'character' : start_char
30
45
},
31
46
'end' : {
32
- 'line' : code [ 'end' ][ 'line' ] - 1 ,
33
- 'character' : code [ 'end' ][ 'column' ]
47
+ 'line' : end_line ,
48
+ 'character' : end_char
34
49
}
35
50
},
36
51
'source' : 'coala' ,
You can’t perform that action at this time.
0 commit comments