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 @@ -15,17 +15,32 @@ def output_to_diagnostics(output):
15
15
origin = problem ['origin' ]
16
16
real_message = '[{}] {}: {}' .format (section , origin , message )
17
17
for code in problem ['affected_code' ]:
18
+ """
19
+ Line position and character offset should be zero-based
20
+ according to LSP, but row and column positions of coala
21
+ are None or one-based number.
22
+ coala uses None for convenience. None for column means the
23
+ whole line while None for line means the whole file.
24
+ """
25
+ def convert_offset (x ): return x - 1 if x else x
26
+ start_line = convert_offset (code ['start' ]['line' ])
27
+ start_char = convert_offset (code ['start' ]['column' ])
28
+ end_line = convert_offset (code ['end' ]['line' ])
29
+ end_char = convert_offset (code ['end' ]['column' ])
30
+ if start_char is None or end_char is None :
31
+ start_char = 0
32
+ end_line = start_line + 1
33
+ end_char = 0
18
34
res .append ({
19
35
'severity' : severity ,
20
36
'range' : {
21
37
'start' : {
22
- # Trick: VS Code starts from 0?
23
- 'line' : code ['start' ]['line' ] - 1 ,
24
- 'character' : code ['start' ]['column' ]
38
+ 'line' : start_line ,
39
+ 'character' : start_char
25
40
},
26
41
'end' : {
27
- 'line' : code [ 'end' ][ 'line' ] - 1 ,
28
- 'character' : code [ 'end' ][ 'column' ]
42
+ 'line' : end_line ,
43
+ 'character' : end_char
29
44
}
30
45
},
31
46
'source' : 'coala' ,
You can’t perform that action at this time.
0 commit comments