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: Bad behavior after updating gopls, duplicated suggestions and unexpected placeholders. #60959

Closed
miranquil opened this issue Jun 23, 2023 · 7 comments
Assignees
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

@miranquil
Copy link

miranquil commented Jun 23, 2023

gopls version

golang.org/x/tools/gopls v0.12.3
    golang.org/x/tools/gopls@v0.12.3 h1:u0wCI9uvt7mnmri6bFBIaWw1XCN6PN8hKv55Zwd+GbE=

go env

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/miranquil/Library/Caches/go-build"
GOENV="/Users/miranquil/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/miranquil/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/miranquil/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/miranquil/sdk/go1.19.5"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/miranquil/sdk/go1.19.5/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/miranquil/lumibay/donkey/go.mod"
GOWORK="/Users/miranquil/lumibay/donkey/go.work"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0n/d4s955_n0m748tnz3whw42n00000gn/T/go-build3368496042=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

First, I have a project in struct like this:

|- dao
  |- generic.go
    |- func GWhereFirst
|- service
  |- teaching
    |- teaching_auth.go

I'm trying to call dao.GWhereFirst from teaching_auth.go.

And I'm sure that "ui.completion.usePlaceholders" is false in settings.

What did you expect to see?

Regular suggestions, and no placeholders placed when I press ENTER.

And after founding out this issue, I rollbacked gopls to v0.11.0, which runs perfectly:
good

What did you see instead?

bad

The interesting thing is that if I delete the code generated with "import dao" left, then everything works fine. Just like the gif shows.

Editor and settings

VSCode

Version: 1.79.2
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:58:33.551Z (1 wk ago)
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.5.0

settings:

{
  "vim.autoSwitchInputMethod.enable": true,
  "editor.fontFamily": "'Iosevka', 'Fantasque Sans Mono','MonoLisa Miranquil', 'LXGW WenKai Mono',  Menlo, Monaco, 'Courier New', 微软雅黑, monospace",
  "editor.fontLigatures": "'dlig', 'VXLA' 2",
  // "editor.fontLigatures": "'ss15', 'dlig', 'VXLA' 2",
  "files.autoSave": "afterDelay",
  "workbench.editorAssociations": {},
  "workbench.colorCustomizations": {
    "editorCursor.foreground": "#B79147",
    "terminalCursor.foreground": "#B79147"
  },
  "python.languageServer": "Pylance",
  "editor.smoothScrolling": true,
  "terminal.integrated.fontFamily": "\"CaskaydiaCove Nerd Font Mono\"",
  "terminal.integrated.cursorStyle": "underline",
  "terminal.integrated.inheritEnv": false,
  "vim.cursorStylePerMode.insert": "underline",
  "security.workspace.trust.untrustedFiles": "open",
  "vim.startofline": false,
  "go.toolsManagement.autoUpdate": true,
  "editor.semanticHighlighting.enabled": true,
  "editor.cursorSmoothCaretAnimation": "on",
  "rust-analyzer.debug.engine": "vadimcn.vscode-lldb",
  "todo-tree.ripgrep.ripgrep": "/Users/miranquil/.cargo/bin/rg",
  "editor.accessibilitySupport": "off",
  "editor.inlineSuggest.enabled": true,
  "rust-analyzer.hover.actions.references.enable": true,
  "go.inlayHints.parameterNames": true,
  "editor.formatOnPaste": true,
  "workbench.list.smoothScrolling": true,
  "terminal.integrated.smoothScrolling": true,
  "go.inlayHints.constantValues": true,
  "go.inlayHints.rangeVariableTypes": true,
  "git.autofetch": true,
  "git.confirmSync": false,
  "editor.foldingImportsByDefault": true,
  "editor.cursorSurroundingLines": 8,
  "vim.foldfix": true,
  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": [
        "<C-d>"
      ],
      "after": [
        "1",
        "5",
        "g",
        "j",
        "z",
        "z",
      ]
    },
    {
      "before": [
        "<C-u>"
      ],
      "after": [
        "1",
        "5",
        "g",
        "k",
        "z",
        "z"
      ]
    },
    {
      "before": [
        "u"
      ],
      "after": [],
      "commands": [
        {
          "command": "undo",
          "args": []
        }
      ]
    },
    {
      "before": [
        "<C-r>"
      ],
      "after": [],
      "commands": [
        {
          "command": "redo",
          "args": []
        }
      ]
    }
  ],
  "files.insertFinalNewline": true,
  "files.trimFinalNewlines": true,
  "search.showLineNumbers": true,
  "gitlens.hovers.avatars": false,
  "gitlens.views.commits.avatars": false,
  "gitlens.views.repositories.avatars": false,
  "gitlens.views.fileHistory.avatars": false,
  "gitlens.views.lineHistory.avatars": false,
  "gitlens.views.branches.avatars": false,
  "gitlens.views.remotes.avatars": false,
  "gitlens.views.tags.avatars": false,
  "gitlens.views.worktrees.avatars": false,
  "gitlens.views.contributors.avatars": false,
  "gitlens.views.searchAndCompare.avatars": false,
  "gitlens.blame.avatars": false,
  "go.inlayHints.functionTypeParameters": true,
  "terminal.integrated.cursorBlinking": true,
  "editor.inlayHints.fontFamily": "Menlo",
  "editor.inlayHints.fontSize": 10,
  "[python]": {
    "editor.formatOnType": true
  },
  "files.exclude": {
    "**/.trunk/*out": true,
    "**/.trunk/*out/": true,
    "**/.trunk/*actions/": true,
    "**/.trunk/*logs/": true,
    "**/.trunk/*plugins/": true
  },
  "trunk.trunkGrayOutNonBlockingIssues": false,
  "files.watcherExclude": {
    "**/.trunk/*out": true,
    "**/.trunk/*out/": true,
    "**/.trunk/*actions/": true,
    "**/.trunk/*logs/": true,
    "**/.trunk/*plugins/": true
  },
  "go.editorContextMenuCommands": {
    "fillStruct": true,
    "benchmarkAtCursor": true
  },
  "todo-tree.general.showActivityBarBadge": true,
  "debug.console.fontFamily": "'CaskaydiaCove Nerd Font Mono', 'Sarasa Term SC'",
  "debug.console.fontSize": 12,
  "editor.lineNumbers": "relative",
  "editor.fontWeight": 500,
  "workbench.editor.titleScrollbarSizing": "large",
  "workbench.editor.highlightModifiedTabs": true,
  "editor.acceptSuggestionOnCommitCharacter": false,
  "editor.unfoldOnClickAfterEndOfLine": true,
  "editor.fontVariations": false,
  "editor.guides.bracketPairs": true,
  "workbench.colorTheme": "98878c8e-9f91-4e25-930d-dd7d280d9e35",
  "extensions.experimental.affinity": {
    "asvetliakov.vscode-neovim": 1
  },
  "editor.cursorStyle": "underline",
  "[markdown]": {
    "editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
  },
  "markdownlint.config": {
    "MD010": {
      "spaces_per_tab": 4
    }
  },
  "pangu.auto_format_on_save": true,
  "editor.formatOnSave": true,
  "[go]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  },
  "gopls": {
    "formatting.local": "infra",
  },
  "go.formatTool": "goimports",
  "workbench.iconTheme": "eq-material-theme-icons",
  "vscode-neovim.neovimExecutablePaths.darwin": "/opt/homebrew/bin/nvim",
  "lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB",
  "codeium.enableConfig": {
    "*": true,
    "go": false
  },
  "editor.inlayHints.padding": true,
  "editor.inlayHints.enabled": "offUnlessPressed",
  "workbench.startupEditor": "none",
  "editor.minimap.enabled": false,
  "tabout.charactersToTabOutFrom": [
    {
      "open": "[",
      "close": "]"
    },
    {
      "open": "{",
      "close": "}"
    },
    {
      "open": "(",
      "close": ")"
    },
    {
      "open": "'",
      "close": "'"
    },
    {
      "open": "\"",
      "close": "\""
    },
    {
      "open": ":",
      "close": ":"
    },
    {
      "open": "=",
      "close": "="
    },
    {
      "open": ">",
      "close": ">"
    },
    {
      "open": "<",
      "close": "<"
    },
    {
      "open": ".",
      "close": "."
    },
    {
      "open": "`",
      "close": "`"
    },
    {
      "open": ";",
      "close": ";"
    }
  ],
  "protoc": {
    "options": [
      "--proto_path=${workspaceFolder}/protopb"
    ]
  },
  "editor.fontSize": 14,
  "evenBetterToml.semanticTokens": true,
  "explorer.autoReveal": "focusNoScroll",
  "vim.autoSwitchInputMethod.defaultIM": "com.apple.keylayout.ABC",
  "vim.autoSwitchInputMethod.obtainIMCmd": "/usr/local/bin/im-select",
  "vim.autoSwitchInputMethod.switchIMCmd": "/usr/local/bin/im-select {im}",
  "go.languageServerFlags": [],
  "go.trace.server": "verbose",
}

Logs

I've added -logFile=/Users/miranquil/go.log to go.languageServerFlag. But after same operations nothing was written into this file.

@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 Jun 23, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jun 23, 2023
@miranquil miranquil changed the title x/tools/gopls: x/tools/gopls: Bad behavior after updating gopls, duplicated suggestions and unexpected placeholders. Jun 23, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.12.5 Jun 23, 2023
@findleyr
Copy link
Contributor

Thank you for the report.

This looks like a regression in unimported completion, however I can't quite reproduce the behavior you're seeing. I don't see the duplicated completion items, for example.

I see a couple bugs, which is that we don't populate a placeholder for type parameters, and aren't honoring the usePlaceholders setting.

Are you working in GOPATH mode (as it appears from the import path of the dao package)? Does the issue reproduce when you work within a module?

@miranquil
Copy link
Author

miranquil commented Jun 25, 2023

Sorry English is not my native language so I'm not sure I've quite understanded what "GOPATH mode" means.
The main project is already go mod init and also the dao package. And on the other hand my project is working with go.work.

Project's go.work:

go 1.18

use (
	.
	component
	dao
)

There's nothing about dao in Project's go.mod.

Also I've found that only the dao suffers from this issue. The packages like internal packages works well(excluding the placeholders' behavior).

I'm not sure if I have provided enough information. Please let me know if I can provice anything else.

@gopherbot
Copy link

Change https://go.dev/cl/506935 mentions this issue: gopls/internal/lsp/source/completion: placeholders for type params

@gopherbot
Copy link

Change https://go.dev/cl/506936 mentions this issue: gopls/internal/lsp/source/completion: honor usePlaceholders

@adonovan
Copy link
Member

adonovan commented Jun 28, 2023

I've sent CLs to fix the two problems @findleyr identified in #60959 (comment). I've reproduced the third problem (duplicates) and confirmed that the cause is the presence of test variants in the known map used by unimported completions. I'll send a fix momentarily.

@gopherbot
Copy link

Change https://go.dev/cl/506937 mentions this issue: gopls/internal/lsp/source/completion: avoid duplicates from variants

@miranquil
Copy link
Author

OMG it's Donovan!!!!
I'm so excited for this.

gopherbot pushed a commit to golang/tools that referenced this issue Jul 6, 2023
The unimported completions logic added in CL 496596 forgot
to add placeholders for type parameters. This change does so,
with a test.

Updates golang/go#60959

Change-Id: I4af8878787e4a229c47fb9ea85ca6b1d577e4d7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/506935
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopherbot pushed a commit to golang/tools that referenced this issue Jul 6, 2023
This change causes the unimported completion logic to honor
the ui.completion.usePlaceholders setting. The tests enable
it explicitly.  (The disabled behavior was tested interactively.)

Updates golang/go#60959

Change-Id: I38a34250a26147d98daaab9ab2eccf11ad877102
Reviewed-on: https://go-review.googlesource.com/c/tools/+/506936
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
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

4 participants