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

diagnostic.py: Correct row and column number convention #39

Merged
merged 1 commit into from
Apr 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions coala_langserver/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set the column to 0 or the whole line if the bear returns None?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, I should be careful about that.
According to LSP specification, if there is an issue with whole line x, the output format should be as follows:

{
    start: { line: x, character: 0 }
    end : { line: x + 1, character : 0 }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thus I think we should check if endline == startline.

}
},
'source': 'coala',
Expand Down