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

Commit

Permalink
diagnostic.py: Check row and column number
Browse files Browse the repository at this point in the history
Row and column number should be zero-based integer, not null

Fixes #37
  • Loading branch information
li-boxuan committed Apr 4, 2018
1 parent 45d39b9 commit 1c094c9
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions coala_langserver/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,32 @@ def output_to_diagnostics(output):
origin = problem['origin']
real_message = '[{}] {}: {}'.format(section, origin, message)
for code in problem['affected_code']:
"""
Line position and character offset should be zero-based
according to LSP, but row and column positions of coala
are None or one-based number.
coala uses None for convenience. None for column means the
whole line while None for line means the whole file.
"""
def convert_offset(x): return x - 1 if x else x
start_line = convert_offset(code['start']['line'])
start_char = convert_offset(code['start']['column'])
end_line = convert_offset(code['end']['line'])
end_char = convert_offset(code['end']['column'])
if start_char is None or end_char is None:
start_char = 0
end_line = start_line + 1
end_char = 0
res.append({
'severity': severity,
'range': {
'start': {
# Trick: VS Code starts from 0?
'line': code['start']['line'] - 1,
'character': code['start']['column']
'line': start_line,
'character': start_char
},
'end': {
'line': code['end']['line'] - 1,
'character': code['end']['column']
'line': end_line,
'character': end_char
}
},
'source': 'coala',
Expand Down

0 comments on commit 1c094c9

Please sign in to comment.