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

Commit 7e29998

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 f446f44 commit 7e29998

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
@@ -20,17 +20,32 @@ def output_to_diagnostics(output):
2020
origin = problem['origin']
2121
real_message = '[{}] {}: {}'.format(section, origin, message)
2222
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
2339
res.append({
2440
'severity': severity,
2541
'range': {
2642
'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
3045
},
3146
'end': {
32-
'line': code['end']['line'] - 1,
33-
'character': code['end']['column']
47+
'line': end_line,
48+
'character': end_char
3449
}
3550
},
3651
'source': 'coala',

0 commit comments

Comments
 (0)