-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/gopls: fix handling of end of file in internal/span #41029
Comments
I think that, rather than changing the span package, we should do our best to work-around this in the cases where it comes up (so far, completion, and perhaps other features that insert edits like code actions). The work-around added in CL 249706 is not ideal because it is untested, so once we have support for completion in package declarations, we should see if we can improve and test it. /cc @findleyr since we discussed this, and it's relevant to #37702. |
Given that we have a reasonable work-around for this in completion, removing from the 1.0 milestone. |
I don't understand how this isn't just a bug. Presumably the limitation is driven by the behavior of token.File, which IIRC ignores a trailing newline. |
Change https://go.dev/cl/459736 mentions this issue: |
This change expands the dominion of safetoken to include calls to token.File{,Set}.Position{,For}, since all need workarounds similar to that in Offset. As a side benefit, we now have a centralized place to implement the workaround for other bugs such as golang/go#41029, the newline at EOF problem). Unfortunately the former callers of FileSet.Position must stipulate whether the Pos is a start or an end, as the same value may denote the position 1 beyond the end of one file, or the start of the following file in the file set. Hence the two different functions, {Start,End}Position. The static check has been expanded, as have the tests. Of course, this approach is not foolproof: gopls has many dependencies that call methods of File and FileSet directly. Updates golang/go#41029 Updates golang/go#57484 Updates golang/go#57490 Change-Id: Ia727e3f55ca2703dd17ff2cac05e786793ca38eb Reviewed-on: https://go-review.googlesource.com/c/tools/+/459736 Run-TryBot: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]>
I believe this is a non-issue now that we've switched to the new |
Package
span
currently treats end of file as start of a new line (https://github.com/golang/tools/blob/c024452afbcdebb4a0fbe1bb0eaea0d2dbff835b/internal/span/token.go#L117), which is inaccurate for files with end of file not being a newline. This affects completion on end of file line and we're currently considering a temporary fix there (https://go-review.googlesource.com/c/tools/+/249706). A better fix should come fromspan
itself and the package should check if a final new line is present before converting end of file to start of new line. Just removing this check breaks diff tests and is not a viable fix currently.The text was updated successfully, but these errors were encountered: