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: deprecate 'Structured' hover kind #70233

Open
findleyr opened this issue Nov 6, 2024 · 13 comments
Open

x/tools/gopls: deprecate 'Structured' hover kind #70233

findleyr opened this issue Nov 6, 2024 · 13 comments
Labels
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

@findleyr
Copy link
Member

findleyr commented Nov 6, 2024

The 'Structured' hover kind does not serve human readable hover content. Rather, it serves JSON describing the hover.
https://github.com/golang/tools/blob/master/gopls/doc/settings.md#hoverkind-enum

gopls should conform to the semantics of the LSP: hover is intended to be human readable. If we want to delegate hover presentation to the client, we must by definition have a thick client, in which case the client can just use a separate command via workspace/executeCommand. By analogy, tsserver has a command for structured hover info: https://github.com/microsoft/TypeScript/blob/55f1248a2052eebdea6bc0e2eef754df89a44bf7/src/server/protocol.ts#L2015.

CC @adonovan

@findleyr findleyr added this to the gopls/v0.18.0 milestone Nov 6, 2024
@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 Nov 6, 2024
@adonovan
Copy link
Member

adonovan commented Nov 8, 2024

I vaguely recall that the sole thick client of the Hover JSON output is one of the Vims. (The feature was added in the CL attached to #33352. Paging @myitcv for awareness.)

@myitcv
Copy link
Member

myitcv commented Dec 9, 2024

Paging @myitcv for awareness.

Thanks, @adonovan - we're actually using what I believe the gopls default is in this space, "FullDocumentation":

https://github.com/govim/govim/blob/6280deb8b406332ed0c9f0eea59671d954b815ab/cmd/govim/gopls_client.go#L159

@adonovan
Copy link
Member

[govim is] actually using what I believe the gopls default is in this space, "FullDocumentation":

Great, let's remove kind=structured then.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/635226 mentions this issue: gopls/internal/settings: drop experimental hoverKind=Structured

@bhcleek
Copy link
Contributor

bhcleek commented Feb 21, 2025

FWIW, vim-go was using Structured.

@findleyr
Copy link
Member Author

@bhcleek very sorry about the breakage :(.

This was, I think, perhaps the first time we've just removed a setting without a probationary release where it is a warning. We really thought the only user was govim -- I'm afraid the similar naming of the clients may have been part of the confusion. Lesson (re)learned.

What can we do to help? We can revert the deprecation temporarily, though that might be messy (I'll try). If instead you can fix forward, that may be cleanest.

Going forward If you need structured information from hover, we can can add a custom command. As described in the release notes, it was a mistake to shoehorn a JSON API into hover.

@bhcleek
Copy link
Contributor

bhcleek commented Feb 21, 2025

I can probably refactor vim-go to get what I need, but I won't be able to get to it immediately.

IIRC, I'd relied on Structured, because FullDocumentation was missing some things vim-go needed and the structure of the documentation result when FullDocumentation was used did not come with guarantees; parsing free form text is tricky, especially if the server doesn't guarantee its form across versions.

@findleyr
Copy link
Member Author

Reopening and moving to the v0.19.0 milestone, since this deletion is being reverted.

@findleyr findleyr reopened this Feb 21, 2025
@findleyr findleyr modified the milestones: gopls/v0.18.0, gopls/v0.19.0 Feb 21, 2025
@bhcleek
Copy link
Contributor

bhcleek commented Mar 8, 2025

@findleyr

Would it be possible to change the plaintext hover content to use two newlines between the identifier and the beginning of its documentation?

I'm also wondering what determines where single newlines are placed within the actual documentation after the identifier.

edit: strike wondering after checking actual godoc source for fmt.Println and realizing I'd assumed something based on how the pkg.go.dev renders it.

@bhcleek
Copy link
Contributor

bhcleek commented Mar 9, 2025

@findleyr nevermind, I think I've found a way forward.

@bhcleek
Copy link
Contributor

bhcleek commented Mar 10, 2025

@findleyr I got most of what I needed done, but there's one aspect of the structured content that I've been unable to find a good answer for. The structured output includes linkPath and linkAnchor fields. Vim-go uses those fields to construct documentation links, notably for opening a browser.

Interestingly, the markdown format provides the links I'd need with FullDocumentation, but I can't mix plaintext and markdown, because the format has to be chosen in the initialize method, and markdown is otherwise not well suited for vim-go's needs.

I was hoping that textdocument/documentLink would provide a useful alternative, but it seems to only provide links for the imports.

Do you have any suggestions?

@findleyr
Copy link
Member Author

Would it suffice to include the links in plaintext mode, in the footer? That seems reasonable.

For users that don't want links, we could we could extend the "linksInHover" setting to plaintext:
https://github.com/golang/tools/blob/master/gopls/doc/settings.md#linksinhover-enum

I don't think we should use documentLink for this.

@bhcleek
Copy link
Contributor

bhcleek commented Mar 18, 2025

Yes, I think that could work for vim-go's purposes as long as:

  1. only the link for the documentation being provided is provided
  2. there is some guarantee about where in the plaintext the link will be found (e.g. last line?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

5 participants