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: document code actions that gopls supports #54115

Closed
findleyr opened this issue Jul 28, 2022 · 6 comments
Closed

x/tools/gopls: document code actions that gopls supports #54115

findleyr opened this issue Jul 28, 2022 · 6 comments
Assignees
Labels
Documentation gopls Issues related to the Go language server, gopls. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Contributor

From discussion on gophers slack: it would be nice if gopls documented supported code actions, similar to how it documents other parameterized features (such as inlay hints: https://github.com/golang/tools/blob/master/gopls/doc/inlayHints.md).

Supported code actions are provided part of the initialize handshake, but we could document more precisely what we support.

@findleyr findleyr added this to the gopls/later milestone Jul 28, 2022
@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 Jul 28, 2022
@gopherbot gopherbot modified the milestones: gopls/later, Unreleased Jul 28, 2022
@advinsuryavanshi
Copy link

can i work on this...?

@findleyr
Copy link
Contributor Author

@advinsuryavanshi yes, contributions are very welcome!

However, be warned that we may want more than just pure documentation here. As much as possible, we try to generate our documentation from the gopls source. This prevents duplication, and helps ensure that documentation doesn't go stale. It also makes it easier to compile our documentation into JSON that can be read by editors. You can see examples of this in x/tools/gopls/doc/generate.go.

I haven't thought too much about code actions, but we should try to do something similar, basing our documentation off of x/tools/internal/lsp/source.DefaultOptions().SupportedCodeActions. One way to enforce that we have documentation would be to change the type of SupportedCodeActions. For example:

	SupportedCodeActions map[FileKind]map[protocol.CodeActionKind]string // file kind -> action kind -> description

In the future we could also go further and try to refactor such that code actions are parameterized, similarly to inlay hints (see x/tools/internal/lsp/source.AllInlayHints), but I don't think it is wise to undertake that refactoring now.

CC @suzmue @jamalc who may have opinions, having just done this for inlay hints.

@findleyr findleyr modified the milestones: Unreleased, gopls/later Aug 1, 2022
@jeanbza
Copy link
Member

jeanbza commented Aug 26, 2022

Just piping in to ask a naive question: is this intended to replace (the presumedly manually maintained) https://github.com/golang/tools/blob/master/gopls/doc/commands.md ?

If so, maybe linking to https://github.com/golang/tools/blob/master/internal/lsp/command/interface.go is a good easy first step: seems pretty self-explanatory, and only seems to lack the name of each command (RunTests vs gopls.run_tests). But maybe that can just be added to the comment.

Hacky solutions, but ones that might yield results quicker than trying to auto-generate documentation.

@adonovan adonovan added the Refactoring Issues related to refactoring tools label Apr 24, 2023
@findleyr
Copy link
Contributor Author

findleyr commented Sep 22, 2023

@jadekler sorry for missing your question. Code actions may return either workspace edits or commands, so there is a lot of overlap with the command documentation but they are distinct. I think the point of documenting code actions is that users can bind keys to specific code action workflows.

I recently refactored the code action code somewhat for performance reasons (https://go.dev/cl/511995), after which it is slightly easier to see which code action kinds are supported.

I don't think we need to block this issue on perfectly parameterizing the code action logic. If anyone wants to help out on this, I think it would be suitable to start out with manual documentation:

In the future, it would be nice to have a code action dispatcher similarly to what we have for the executeCommand request. At that point perhaps we could automate documentation.

@adonovan is currently working on refactoring (doing some very exciting work on inlining!), so now is a good time to start revisiting this code and documentation.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/583316 mentions this issue: gopls/doc: document all of gopls' features

gopherbot pushed a commit to golang/tools that referenced this issue Jun 28, 2024
This CL enumerates and documents each LSP feature
supported by gopls so that users can find out:
- what the tool is capable of,
- how to use it,
- what settings affect the feature, and
- whether their LSP client supports a given feature.

We plan to provide Code Actions to open the relevant
section of the manual, e.g. "Refactor > Describe refactorings..."

To review the markdown, cherrypick this CL then
run this command from x/tools:

 $ go run rsc.io/cmd/mdweb@latest -a localhost:9876 &
   open http://localhost:9876/gopls/doc/features/README.md

The topic of completion is left for another day,
as is support for go.mod files.

Updates golang/go#54115

Change-Id: I8f7de7571bfe0355b3597487efbc0d7aae7a12d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/583316
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 13, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/618616 mentions this issue: gopls/doc/features: add index of supported Code Actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation gopls Issues related to the Go language server, gopls. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants