Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect LSP positions when line contains tabs #293

Open
p-lindberg opened this issue Feb 1, 2023 · 1 comment
Open

Incorrect LSP positions when line contains tabs #293

p-lindberg opened this issue Feb 1, 2023 · 1 comment
Labels

Comments

@p-lindberg
Copy link

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:

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

@payne911
Copy link
Contributor

payne911 commented May 5, 2023

it should wreak total havoc on all LSP functionality in files containing tabs

Probably because most people using IntelliJ have the IDE configuration that automatically replaces tabs by a given amount of spaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants