You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The method DocumentUtils.offsetToLSPPos, which is used to translate document offsets into LSP positions, returns incorrect positions for lines that contain tabs. According to the specification:
A position inside a document (...) is expressed as a zero-based line and character offset.
The method instead tries to return a line and column number, which is not the same as a character offset. In doing so, it needs to compensate for tab widths:
int tabs = StringUtil.countChars(lineTextBeforeOffset, '\t');
int tabSize = getTabSize(editor);
int column = lineTextBeforeOffset.length() - tabs * (tabSize - 1);
return new Position(line, column);
This should just be
return new Position(line, lineTextBeforeOffset.length());
Additionally, the translation from offset to column is wrong in and of itself, since it subtracts the additional tab widths instead of adding them. This can lead to negative column numbers.
I'm confused as to how this issue has not been discovered or fixed yet since, by my estimation, it should wreak total havoc on all LSP functionality in files containing tabs, given that the positions come out wrong. This makes me suspect that it may have been compensated for in another layer, which is why I'm reluctant to submit a PR; I don't know if it will break other things.
Affected Versions:
0.95.0
The text was updated successfully, but these errors were encountered:
Description:
The method
DocumentUtils.offsetToLSPPos
, which is used to translate document offsets into LSP positions, returns incorrect positions for lines that contain tabs. According to the specification:The method instead tries to return a line and column number, which is not the same as a character offset. In doing so, it needs to compensate for tab widths:
This should just be
Additionally, the translation from offset to column is wrong in and of itself, since it subtracts the additional tab widths instead of adding them. This can lead to negative column numbers.
I'm confused as to how this issue has not been discovered or fixed yet since, by my estimation, it should wreak total havoc on all LSP functionality in files containing tabs, given that the positions come out wrong. This makes me suspect that it may have been compensated for in another layer, which is why I'm reluctant to submit a PR; I don't know if it will break other things.
Affected Versions:
0.95.0
The text was updated successfully, but these errors were encountered: