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/internal/lsp/protocol: use AnnotatedTextEdit for TextDocumentEdit.Edits #58583

Closed
hyangah opened this issue Feb 17, 2023 · 3 comments
Assignees
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Feb 17, 2023

In 3.16, LSP introduced support for AnnotatedTextEdit that allows annotations to a text edit and
supports UX that optionally asks user for confirmation before applying the change.

TextDocumentEdit.Edits is defined an array of TextEdit | AnnotatedTextEdit according to the spec,
but Gopls is currently accepting only TextEdit type. It would be nice if gopls uses AnnotatedTextEdit instead of TextEdit
so we can experiment and start developing features with the AnnotatedTextEdit.

Given that AnnotatedTextEdit is a simple extension of TextEdit with one extra field (annotationId),
I think we can consider to replace all references of TextEdit in gopls with AnnotatedTextEdit while marking the annotatedId field omitempty.

Alternatively, I saw some internal non-TS/JS LSP implementations work around this OR type issue by a type corresponding to TextEdit

type TextEdit struct {
  Range Range `json:"range"`
  NewText string `json:"newText"`
  AnnotationID ChangeAnnotationIdentifier `json:"annotationId,omitempty"`
}

cc @pjweinb

@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 Feb 17, 2023
@gopherbot gopherbot added this to the Unreleased milestone Feb 17, 2023
@hyangah hyangah added FeatureRequest and removed Documentation gopls Issues related to the Go language server, gopls. labels Feb 17, 2023
@pjweinb
Copy link

pjweinb commented Feb 17, 2023 via email

@hyangah
Copy link
Contributor Author

hyangah commented Feb 21, 2023

You are right that the general replacement doesn't work.
As the LSP maintainer pointed out (microsoft/language-server-protocol#998 (comment)) AnnotatedTextEdit is applicable only in a certain context (i.e. workspace edit)
and for completion items or formatting this may not make much sense.

This unlocks more advanced workspace edits shown in
microsoft/vscode#77728 (comment)

  • users can see the diffs when involving many file changes,
  • users can select individual changes per file
  • editor can group text edits based on the concise annotation

I think this will help us enhance gopls's workspace edit feature - various renaming that results in multiple file changes/moves.

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 21, 2023
@hyangah hyangah added the gopls Issues related to the Go language server, gopls. label Mar 3, 2023
@hyangah hyangah modified the milestones: Unreleased, gopls/later Mar 7, 2023
@findleyr findleyr modified the milestones: gopls/backlog, gopls/v0.15.0 Feb 12, 2024
@findleyr
Copy link
Contributor

Per chat -- this was done in https://go.dev/cl/547295

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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. 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