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: switch to utf-8 based offset #63470

Closed
hyangah opened this issue Oct 9, 2023 · 4 comments
Closed

x/tools/gopls: switch to utf-8 based offset #63470

hyangah opened this issue Oct 9, 2023 · 4 comments
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Oct 9, 2023

LSP 3.17 and newer introduced general.positionEncodings and started to provide a way for client/server to agree and operate on UTF-8. https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocuments
For backwards compatibility, LSP spec recommends URF-16 as the mendatory encoding though.

I think we can utilize the telemetry here to monitor the clients' encoding supports. If most editors are ready to handle utf-8, we can consider to use utf-8.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Oct 9, 2023
@gopherbot gopherbot added this to the Unreleased milestone Oct 9, 2023
@findleyr
Copy link
Contributor

findleyr commented Oct 9, 2023

I'm not sure we'll ever do this, since we already have the machinery in place to support UTF-16. https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocuments is a little unclear whether servers must support UTF-16, though it says that all clients must.

@hyangah
Copy link
Contributor Author

hyangah commented Oct 9, 2023

The potential benefit of this is the maintenance cost. Most of the Go tools are written to work with utf-8.
As seen in https://go-review.git.corp.google.com/c/tools/+/533755/1/gopls/internal/lsp/fake/editor.go line 1566 and also during the vulncheck analysis logic, it causes confusion and inefficiency (for correct UTF-16 conversion, the gopls has to read the file contents. This can be problematic for workspace-level position computation).

@adonovan
Copy link
Member

I think Rob's point is that the performance benefit of speaking UTF-8 with willing clients is not worth the complexity cost of having two different ways of doing things, and that UTF-8 only becomes a net win if we can stop supporting UTF-16, which doesn't seem likely ever to happen.

@hyangah
Copy link
Contributor Author

hyangah commented Oct 12, 2023

My point was to measure whether how many clients depend on only utf-16. According to the spec, utf-16 support mandate is for the backwards compatibility. If we find most clients support utf-8, we can discuss potentially dropping utf-16 support even though the spec says it is mandatory for backwards compatibility - my argument was - if there is no client depending on it, what would be the point of maintaining it and suffering?

On the other hand, I learned that VS code still supports only utf-16. And assuming conversion requires the source code, I doubt vscode that needs to work with many different extensions and maybe purely on client side without source code, can easily adopt utf-8 will happen near future. lol.

Closing.

Looks like we have a couple of places we don't do the conversion correctly. (e.g. gc details)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants