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

fix: LSP CodeAction sometimes results in "error: column is beyond end of line" #817

Merged
merged 2 commits into from
Jun 29, 2024

Conversation

a-h
Copy link
Owner

@a-h a-h commented Jun 28, 2024

In #801 we saw a report of "error: column is beyond end of line" coming back from the LSP.

This turned out to be hard to reproduce without the specific set of files, and also because different editors, extensions, and versions of gopls interact differently with the LSP.

However, investigating the issue, I spotted that CodeAction doesn't do any rewriting of the templ source positions to the target Go positions. This means that sometimes, the templ source position would indeed be past the end of a Go source code line, but the behaviour would be hard to reproduce, since it would require the specific CodeAction to have been executed, and it may require a specific version of gopls etc.

I use Neovim where to run a code action I have to press space followed by c and a. However, in VS Code, it's likely that some extensions are calling this LSP feature regularly - maybe even every time a cursor moves position, or a file is edited, meaning that those users are much more likely to spot this issue.

It looks to me like CodeAction can't ever have worked up until this point, since the rewrites weren't properly done, and also, because gopls ignores actions on generated code, based on magic comments in the file.

This PR does a few things:

  • Correctly rewrites the templ LSP position to the Go LSP position so that the gopls error doesn't happen.
  • Removes any results provided by the CodeAction results from gopls, since we haven't got tests for the behaviour and can't guarantee it.
  • Lays the groundwork for future support of specific code actions by introducing a unit test for the behaviour, and adding a feature to the generator to disable the Code generated comment, but doesn't enable it yet, because it may introduce other defects and we need to do more testing before that gets switched on.

I think that this will fix #801

@a-h a-h requested a review from joerdav June 28, 2024 16:32
@a-h a-h merged commit 01d3361 into main Jun 29, 2024
7 checks passed
@a-h a-h deleted the issue_801 branch June 29, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v0.2.717] error: column is beyond end of line
1 participant