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: import autocomplete appends suggestion instead of replacing #42748

Closed
RomanKornev opened this issue Nov 20, 2020 · 6 comments
Closed

Comments

@RomanKornev
Copy link

@RomanKornev RomanKornev commented Nov 20, 2020

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

  • Run go version to get version of Go
    • go version go1.15.2 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • Version: 1.51.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.18.1
  • Run go env to get the go development environment details
    • GO111MODULE=""
      GOARCH="amd64"
      GOBIN=""
      GOCACHE="/Users/df/Library/Caches/go-build"
      GOENV="/Users/df/Library/Application Support/go/env"
      GOEXE=""
      GOFLAGS=""
      GOHOSTARCH="amd64"
      GOHOSTOS="darwin"
      GOINSECURE=""
      GOMODCACHE="/Users/df/go/pkg/mod"
      GONOPROXY=""
      GONOSUMDB=""
      GOOS="darwin"
      GOPATH="/Users/df/go"
      GOPRIVATE=""
      GOPROXY="https://proxy.golang.org,direct"
      GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
      GOSUMDB="sum.golang.org"
      GOTMPDIR=""
      GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
      GCCGO="gccgo"
      AR="ar"
      CC="clang"
      CXX="clang++"
      CGO_ENABLED="1"
      GOMOD=""
      CGO_CFLAGS="-g -O2"
      CGO_CPPFLAGS=""
      CGO_CXXFLAGS="-g -O2"
      CGO_FFLAGS="-g -O2"
      CGO_LDFLAGS="-g -O2"
      PKG_CONFIG="pkg-config"
      GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gd/ck6ncspn19115_7mxytyzw840000gp/T/go-build892077481=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

"go.useLanguageServer": true,

Describe the bug

Autocompleting import mat produces import mat"math/"

Steps to reproduce the behavior:

  1. Type import mat
  2. Enter or Tab
  3. See import mat"math/" instead of import "math"

Screenshots or recordings

image

@hyangah
Copy link
Contributor

@hyangah hyangah commented Nov 20, 2020

@RomanKornev thanks for the report.
@stamblerre I could reproduce with the gopls built on the master (post v0.5.3)
I think it's related to the fact that the original import statement is missing "" so invalid.


[Trace - 10:12:46.016 AM] Sending notification 'textDocument/didChange'.
Params: {"textDocument":{"uri":"file:///Users/hakim/hello/a.go","version":10},"contentChanges":[{"range":{"start":{"line":2,"character":8},"end":{"line":2,"character":8}},"rangeLength":0,"text":"a"}]}


[Trace - 10:12:46.017 AM] Sending request 'textDocument/completion - (27)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/hello/a.go"},"position":{"line":2,"character":9},"context":{"triggerKind":3}}

...
[Trace - 10:12:46.120 AM] Received response 'textDocument/completion - (27)' in 103ms.
Result: {"isIncomplete":true,"items":[{"label":"\"math\"","kind":9,"detail":"\"math\"","preselect":true,"sortText":"00000","filterText":"\"math\"","insertTextFormat":2,"textEdit":{"range":{"start":{"line":2,"character":9},"end":{"line":2,"character":9}},"newText":"\"math\""}},{"label":"\"math/\"","kind":9,"detail":"\"math/\"","sortText":"00001","filterText":"\"math/\"","insertTextFormat":2,"textEdit":{"range":{"start":{"line":2,"character":9},"end":{"line":2,"character":9}},"newText":"\"math/\""}}]}

@hyangah hyangah changed the title Language server: Import autocomplete appends suggestion instead of replacing x/tools/gopls: Import autocomplete appends suggestion instead of replacing Nov 20, 2020
@hyangah hyangah transferred this issue from golang/vscode-go Nov 20, 2020
@gopherbot gopherbot added this to the Unreleased milestone Nov 20, 2020
@stamblerre stamblerre changed the title x/tools/gopls: Import autocomplete appends suggestion instead of replacing x/tools/gopls: import autocomplete appends suggestion instead of replacing Nov 20, 2020
@muirdm
Copy link

@muirdm muirdm commented Dec 5, 2020

@stamblerre do you want to suppress completions in this case or fix the insertion? Without quotes they could be typing the optional name of the import, so popping up the completions wouldn't make sense.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 6, 2020

Suppressing completions sounds like it might be easiest, but it would be helpful to add the quotes for people who are new to Go. I think people who are typing a named import would know to ignore the completion results, so I think adding the quotes should be fine. What do you think?

@muirdm
Copy link

@muirdm muirdm commented Dec 6, 2020

I would vote for suppression. It's a fluke completions show up at all, and it would require some finagling to fix the insertion. It's a good point about new Gophers, but as long as a squiggly shows up with a useful message I think they will be okay.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 7, 2020

Sounds good--suppression sounds like a better path forward.

msAlcantara added a commit to msAlcantara/tools that referenced this issue Dec 28, 2020
Autocompleting a import without quotes appends to the completion,
producing this result: `import math "math/"`.
This commit changes to skip completions when typing a import without
quotes, because the users can be typing the alias of the import.

Fixes: golang/go#42748
@gopherbot
Copy link

@gopherbot gopherbot commented Dec 28, 2020

Change https://golang.org/cl/280652 mentions this issue: internal/lsp: fix autocomplete appends on imports

msAlcantara added a commit to msAlcantara/tools that referenced this issue Dec 29, 2020
Autocompleting a import without quotes appends to the completion,
producing this result: `import math "math/"`.
This commit changes to skip completions when typing a import without
quotes, because the users can be typing the alias of the import.

Fixes: golang/go#42748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants