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

x/tools/gopls: fix handling of end of file in internal/span #41029

Open
dandua98 opened this issue Aug 25, 2020 · 3 comments
Open

x/tools/gopls: fix handling of end of file in internal/span #41029

dandua98 opened this issue Aug 25, 2020 · 3 comments

Comments

@dandua98
Copy link

@dandua98 dandua98 commented Aug 25, 2020

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 from span 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.

@gopherbot gopherbot added this to the Unreleased milestone Aug 25, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Aug 25, 2020
@stamblerre stamblerre added this to the gopls/v.0.5.0 milestone Aug 25, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Aug 26, 2020

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.

@stamblerre stamblerre removed this from the gopls/v0.5.0 milestone Aug 27, 2020
@stamblerre stamblerre added this to the gopls/v1.0.0 milestone Aug 27, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Sep 9, 2020

Given that we have a reasonable work-around for this in completion, removing from the 1.0 milestone.

@findleyr
Copy link
Contributor

@findleyr findleyr commented May 12, 2021

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.

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

Successfully merging a pull request may close this issue.

None yet
4 participants