Skip to content
This repository was archived by the owner on Feb 1, 2019. It is now read-only.

Commit 81c2c08

Browse files
li-boxuangitmate-bot
authored andcommitted
diagnostic.py: Check row and column number
Row and column number should be zero-based integer, not null Fixes #37
1 parent 59660ef commit 81c2c08

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

coala_langserver/diagnostic.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,32 @@ def output_to_diagnostics(output):
1515
origin = problem['origin']
1616
real_message = '[{}] {}: {}'.format(section, origin, message)
1717
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
1834
res.append({
1935
'severity': severity,
2036
'range': {
2137
'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
2540
},
2641
'end': {
27-
'line': code['end']['line'] - 1,
28-
'character': code['end']['column']
42+
'line': end_line,
43+
'character': end_char
2944
}
3045
},
3146
'source': 'coala',

0 commit comments

Comments
 (0)