Skip to content

x/tools/gopls: support InsertReplaceEdit completion items #61215

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

Closed
Zyl9393 opened this issue Jun 20, 2023 · 4 comments
Closed

x/tools/gopls: support InsertReplaceEdit completion items #61215

Zyl9393 opened this issue Jun 20, 2023 · 4 comments
Assignees
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls/completion Issues related to auto-completion in gopls. 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

@Zyl9393
Copy link

Zyl9393 commented Jun 20, 2023

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.20.1 windows/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • v0.12.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.79.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.39.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    gotests: D:\Projects\Code\Go\bin\gotests.exe (version: v1.6.0 built with go: go1.20.1)
    gomodifytags: D:\Projects\Code\Go\bin\gomodifytags.exe (version: v1.16.0 built with go: go1.20.1)
    impl: D:\Projects\Code\Go\bin\impl.exe (version: v1.1.0 built with go: go1.20.1)
    goplay: D:\Projects\Code\Go\bin\goplay.exe (version: v1.0.0 built with go: go1.20.1)
    dlv: D:\Projects\Code\Go\bin\dlv.exe (version: v1.20.1 built with go: go1.20.1)
    staticcheck: D:\Projects\Code\Go\bin\staticcheck.exe (version: v0.4.2 built with go: go1.20.1)
    gopls: D:\Projects\Code\Go\bin\gopls.exe (version: v0.12.2 built with go: go1.20.1)

Share the Go related settings you have added/edited

    "go.useLanguageServer": true,
    "go.lintOnSave": "off",

Describe the bug

VsCode setting "editor.suggest.insertMode": "insert" has no effect in Go code.

Steps to reproduce the behavior:

  1. Write some code:
package main

import "fmt"

type Sword struct {
	Blade
	Hilt
}

type Blade struct {
	Length    float64
	Sharpness float64
}

type Hilt struct {
	Girth float64
}

func main() {
	fmt.Println(Sword{Blade: Blade{Length: 0.8, Sharpness: 0.7}})
}
  1. On the line fmt.Println(Sword{Blade: Blade{Length: 0.8, Sharpness: 0.7}}), place cursor in front of the first occurrence of Blade.
  2. Type Hi to trigger autocompletion.
  3. Choose Hilt from the suggestions.
  4. Blade is replaced by Hilt yielding fmt.Println(Sword{Hilt: Blade{Length: 0.8, Sharpness: 0.7}}) instead of fmt.Println(Sword{HiltBlade: Blade{Length: 0.8, Sharpness: 0.7}}).
@hyangah
Copy link
Contributor

hyangah commented Jun 22, 2023

Gopls does not yet support InsertReplaceEdit feature (available from LSP3.16).
@findleyr Do you want to move this to the gopls issue tracker as a feature request?

@findleyr findleyr changed the title VsCode setting "editor.suggest.insertMode": "insert" has no effect x/tools/gopls: support InsertReplaceEdit completion items Jul 6, 2023
@findleyr
Copy link
Member

findleyr commented Jul 6, 2023

We should definitely support this; it's a pain point I run into frequently.

Transferring.

@findleyr findleyr transferred this issue from golang/vscode-go Jul 6, 2023
@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 6, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jul 6, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.13.0 Jul 6, 2023
@findleyr findleyr added the gopls/completion Issues related to auto-completion in gopls. label Jul 6, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.0, gopls/v0.15.0 Sep 27, 2023
@findleyr findleyr modified the milestones: gopls/v0.15.0, gopls/v0.16.0 Dec 12, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/585275 mentions this issue: gopls/internal/server: support InsertReplaceEdit completion

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/587135 mentions this issue: gopls/internal/protocol: customize InsertReplaceEdit JSON unmarshal

gopherbot pushed a commit to golang/tools that referenced this issue May 22, 2024
InsertReplaceEdit is used instead of TextEdit in CompletionItem
in editors that support it. These two types are alike in appearance
but can be differentiated by the presence or absence of
certain properties. UnmarshalJSON of the sum type tries to
unmarshal as TextEdit only if unmarshal as InsertReplaceEdit fails.
Due to this similarity, unmarshal with the different type never fails.

Add a custom JSON unmarshaller for InsertReplaceEdit,
so it fails when the required fields are missing. That makes
Or_CompletionItem_textEdit decode TextEdit type correctly.

For golang/go#40871
For golang/go#61215

Change-Id: I62471fa973fa376cad5eb3934522ff21c14e3647
Reviewed-on: https://go-review.googlesource.com/c/tools/+/587135
Reviewed-by: Peter Weinberger <pjw@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@adonovan adonovan added the FeatureRequest Issues asking for a new feature that does not need a proposal. label May 23, 2024
@hyangah hyangah self-assigned this May 23, 2024
@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.17.0 May 23, 2024
@hyangah hyangah modified the milestones: gopls/v0.17.0, gopls/v0.16.0 May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls/completion Issues related to auto-completion in gopls. 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