golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.89k stars 752 forks source link

Code completion not working properly #2559

Open simococce02 opened 1 year ago

simococce02 commented 1 year ago

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.19.3 darwin/arm64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - command not found in zsh terminal * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.73.1 (Universal) * Check your installed extensions to get the version of the VS Code Go extension - 0.36.0 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. - Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /Users/cocce/go GOROOT: /usr/local/go PATH: /Users/cocce/miniconda3/bin:/Users/cocce/miniconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion Tech Preview.app/Contents/Public:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS go: /usr/local/go/bin/go: go version go1.19.3 darwin/arm64 gotests: not installed gomodifytags: not installed impl: not installed goplay: not installed dlv: /Users/cocce/go/bin/dlv (version: v1.9.1 built with go: go1.19.1) staticcheck: /Users/cocce/go/bin/staticcheck (version: v0.3.3 built with go: go1.19.1) gopls: /Users/cocce/go/bin/gopls (version: v0.10.1 built with go: go1.19.1) go env Workspace Folder (choba_library): /Users/cocce/Library/CloudStorage/OneDrive-UniversitàdegliStudidiMilano/Notability/Unimi/Anno 1/Primo semestre/Programmazione I/choba_library GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/cocce/Library/Caches/go-build" GOENV="/Users/cocce/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/cocce/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/cocce/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.19.3" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" 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/mw/h65c6rx15zqf3xq8m476bkym0000gn/T/go-build2013612946=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

"[go]": { "editor.insertSpaces": false, "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": true }, "editor.suggest.snippetsPreventQuickSuggestions": false }, "go.addTags": { "tags": "json", "options": "json=omitempty", "promptForTags": false, "transform": "snakecase", "template": "" }, // Alternate tools or alternate paths for the same tools used by the Go extension. Provide either absolute path or the name of the binary in GOPATH/bin, GOROOT/bin or PATH. Useful when you want to use wrapper script for the Go tools. "go.alternateTools": {},

// Include unimported packages in auto-complete suggestions. Not applicable when using the language server.
"go.autocompleteUnimportedPackages": false,

// Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"]) This is propagated to the language server if `gopls.build.buildFlags` is not specified.
"go.buildFlags": [],

// Compiles code on file save using 'go build' or 'go test -c'. Options are 'workspace', 'package', or 'off'.  Not applicable when using the language server's diagnostics. See 'go.languageServerExperimentalFeatures.diagnostics' setting.
"go.buildOnSave": "package",

// The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set. This is propagated to the language server if `gopls.build.buildFlags` is not specified.
"go.buildTags": "",

// This option lets you choose the way to display code coverage. Choose either to highlight the complete line or to show a decorator in the gutter. You can customize the colors and borders for the former and the style for the latter.
"go.coverageDecorator": {
    "type": "highlight",
    "coveredHighlightColor": "rgba(64,128,128,0.5)",
    "uncoveredHighlightColor": "rgba(128,64,64,0.25)",
    "coveredBorderColor": "rgba(64,128,128,0.5)",
    "uncoveredBorderColor": "rgba(128,64,64,0.25)",
    "coveredGutterStyle": "blockblue",
    "uncoveredGutterStyle": "slashyellow"
},

// Use these options to control whether only covered or only uncovered code or both should be highlighted after running test coverage
"go.coverageOptions": "showBothCoveredAndUncoveredCode",

// When generating code coverage, the value for -covermode. 'default' is the default value chosen by the 'go test' command.
"go.coverMode": "default",

// If true, runs 'go test -coverprofile' on save and shows test coverage.
"go.coverOnSave": false,

// If true, shows test coverage when Go: Test Function at cursor command is run.
"go.coverOnSingleTest": false,

// If true, shows test coverage when Go: Test Single File command is run.
"go.coverOnSingleTestFile": false,

// If true, shows test coverage when Go: Test Package command is run.
"go.coverOnTestPackage": true,

// When generating code coverage, should counts be shown as --374--
"go.coverShowCounts": false,

// Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.
"go.delveConfig": {},

// If true, tests will not run concurrently. When a new test run is started, the previous will be cancelled.
"go.disableConcurrentTests": false,

// Pick 'godoc' or 'gogetdoc' to get documentation. Not applicable when using the language server.
"go.docsTool": "godoc",

// Experimental Feature: Enable/Disable entries from the context menu in the editor.
"go.editorContextMenuCommands": {
    "toggleTestFile": true,
    "addTags": true,
    "removeTags": false,
    "fillStruct": false,
    "testAtCursor": true,
    "testFile": false,
    "testPackage": false,
    "generateTestForFunction": true,
    "generateTestForFile": false,
    "generateTestForPackage": false,
    "addImport": true,
    "testCoverage": true,
    "playground": true,
    "debugTestAtCursor": true,
    "benchmarkAtCursor": false
},

// Feature level setting to enable/disable code lens for references and run/debug tests
"go.enableCodeLens": {
    "runtest": true
},

// Flags to pass to format tool (e.g. ["-s"]). Not applicable when using the language server.
"go.formatFlags": [],

// When the language server is enabled and one of default/gofmt/goimports/gofumpt is chosen, the language server will handle formatting. Otherwise, the extension will use the specified tool for formatting.
//  - default: If the language server is enabled, format via the language server, which already supports gofmt, goimports, goreturns, and gofumpt. Otherwise, goimports.
//  - gofmt: Formats the file according to the standard Go style. (not applicable when the language server is enabled)
//  - goimports: Organizes imports and formats the file with gofmt. (not applicable when the language server is enabled)
//  - goformat: Configurable gofmt, see https://github.com/mbenkmann/goformat.
//  - gofumpt: Stricter version of gofmt, see https://github.com/mvdan/gofumpt. (not applicable when the language server is enabled)
//  - undefined: Applies gofumpt formatting and organizes imports.
"go.formatTool": "default",

// Additional command line flags to pass to `gotests` for generating tests.
"go.generateTestsFlags": [],

// Enable gocode's autobuild feature. Not applicable when using the language server.
"go.gocodeAutoBuild": false,

// Additional flags to pass to gocode. Not applicable when using the language server.
"go.gocodeFlags": [
    "-builtin",
    "-ignore-case",
    "-unimported-packages"
],

// Used to determine the Go package lookup rules for completions by gocode. Only applies when using nsf/gocode. Latest versions of the Go extension uses mdempsky/gocode by default. Not applicable when using the language server.
"go.gocodePackageLookupMode": "go",

// Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true.
"go.gopath": null,

// Specifies the GOROOT to use when no environment variable is set.
"go.goroot": null,

// Folder names (not paths) to ignore while using Go to Symbol in Workspace feature. Not applicable when using the language server.
"go.gotoSymbol.ignoreFolders": [],

// If false, the standard library located at $GOROOT will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server.
"go.gotoSymbol.includeGoroot": false,

// If false, the import statements will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server.
"go.gotoSymbol.includeImports": false,

// Infer GOPATH from the workspace root. This is ignored when using Go Modules.
"go.inferGopath": false,

// Enable/disable inlay hints for variable types in assign statements:
// ```go
//  i/* int*/, j/* int*/ := 0, len(r)-1
// ```
"go.inlayHints.assignVariableTypes": false,

// Enable/disable inlay hints for composite literal field names:
// ```go
//  {/*in: */"Hello, world", /*want: */"dlrow ,olleH"}
// ```
"go.inlayHints.compositeLiteralFields": false,

// Enable/disable inlay hints for composite literal types:
// ```go
//  for _, c := range []struct {
//      in, want string
//  }{
//      /*struct{ in string; want string }*/{"Hello, world", "dlrow ,olleH"},
//  }
// ```
"go.inlayHints.compositeLiteralTypes": false,

// Enable/disable inlay hints for constant values:
// ```go
//  const (
//      KindNone   Kind = iota/* = 0*/
//      KindPrint/*  = 1*/
//      KindPrintf/* = 2*/
//      KindErrorf/* = 3*/
//  )
// ```
"go.inlayHints.constantValues": false,

// Enable/disable inlay hints for implicit type parameters on generic functions:
// ```go
//  myFoo/*[int, string]*/(1, "hello")
// ```
"go.inlayHints.functionTypeParameters": false,

// Enable/disable inlay hints for parameter names:
// ```go
//  parseInt(/* str: */ "123", /* radix: */ 8)
// ```
"go.inlayHints.parameterNames": false,

// Enable/disable inlay hints for variable types in range statements:
// ```go
//  for k/* int*/, v/* string*/ := range []string{} {
//      fmt.Println(k, v)
//  }
// ```
"go.inlayHints.rangeVariableTypes": false,

// If true, then `-i` flag will be passed to `go build` everytime the code is compiled. Since Go 1.10, setting this may be unnecessary unless you are in GOPATH mode and do not use the language server.
"go.installDependenciesWhenBuilding": false,

// Temporary flag to enable/disable diagnostics from the language server. This setting will be deprecated soon. Please see and response to [Issue 50](https://github.com/golang/vscode-go/issues/50).
"go.languageServerExperimentalFeatures": {
    "diagnostics": true
},

// Flags like -rpc.trace and -logfile to be used while running the language server.
"go.languageServerFlags": [],

// Flags to pass to Lint tool (e.g. ["-min_confidence=.8"])
"go.lintFlags": [],

// Lints code on file save using the configured Lint tool. Options are 'file', 'package', 'workspace' or 'off'.
//  - file: lint the current file on file saving
//  - package: lint the current package on file saving
//  - workspace: lint all the packages in the current workspace root folder on file saving
//  - off: do not run lint automatically
"go.lintOnSave": "package",

// Specifies Lint tool name.
"go.lintTool": "staticcheck",

// Use gotype on the file currently being edited and report any semantic or syntactic errors found after configured delay. Not applicable when using the language server.
"go.liveErrors": {
    "enabled": false,
    "delay": 500
},

// The logging level the extension logs at, defaults to 'error'
"go.logging.level": "error",

// The flags configured here will be passed through to command `goplay`
"go.playground": {
    "openbrowser": true,
    "share": true,
    "run": true
},

// Tags and options configured here will be used by the Remove Tags command to remove tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, all tags and options will be removed.
"go.removeTags": {
    "tags": "",
    "options": "",
    "promptForTags": false
},

// Prompt for surveys, including the gopls survey and the Go developer survey.
"go.survey.prompt": true,

// Apply the Go & PATH environment variables used by the extension to all integrated terminals.
"go.terminal.activateEnvironment": true,

// Absolute path to a file containing environment variables definitions. File contents should be of the form key=value.
"go.testEnvFile": null,

// Environment variables that will be passed to the process that runs the Go tests
"go.testEnvVars": {},

// Run benchmarks when running all tests in a file or folder.
"go.testExplorer.alwaysRunBenchmarks": false,

// Concatenate all test log messages for a given location into a single message.
"go.testExplorer.concatenateMessages": true,

// Enable the Go test explorer
"go.testExplorer.enable": true,

// Present packages in the test explorer flat or nested.
"go.testExplorer.packageDisplayMode": "flat",

// Set the source location of dynamically discovered subtests to the location of the containing function. As a result, dynamically discovered subtests will be added to the gutter test widget of the containing function.
"go.testExplorer.showDynamicSubtestsInEditor": false,

// Open the test output terminal when a test run is started.
"go.testExplorer.showOutput": true,

// Flags to pass to `go test`. If null, then buildFlags will be used. This is not propagated to the language server.
"go.testFlags": null,

// Run 'go test' on save for current package. It is not advised to set this to `true` when you have Auto Save enabled.
"go.testOnSave": false,

// The Go build tags to use for when running tests. If null, then buildTags will be used.
"go.testTags": null,

// Specifies the timeout for go test in ParseDuration format.
"go.testTimeout": "30s",

// Environment variables that will be passed to the tools that run the Go tools (e.g. CGO_CFLAGS) and debuggee process launched by Delve. Format as string key:value pairs. When debugging, merged with `envFile` and `env` values with precedence `env` > `envFile` > `go.toolsEnvVars`.
"go.toolsEnvVars": {},

// Location to install the Go tools that the extension depends on if you don't want them in your GOPATH.
"go.toolsGopath": null,

// Automatically update the tools used by the extension, without prompting the user.
"go.toolsManagement.autoUpdate": false,

// Specify whether to prompt about new versions of Go and the Go tools (currently, only `gopls`) the extension depends on
//  - proxy: keeps notified of new releases by checking the Go module proxy (GOPROXY)
//  - local: checks only the minimum tools versions required by the extension
//  - off: completely disables version check (not recommended)
"go.toolsManagement.checkForUpdates": "proxy",

// The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation.
"go.toolsManagement.go": "",

// Trace the communication between VS Code and the Go language server.
"go.trace.server": "off",

// Complete functions with their parameter signature, including the variable type. Not propagated to the language server.
"go.useCodeSnippetsOnFunctionSuggest": false,

// Complete functions with their parameter signature, excluding the variable types. Use `gopls.usePlaceholders` when using the language server.
"go.useCodeSnippetsOnFunctionSuggestWithoutType": false,

// Use `go.toolsManagement.checkForUpdates` instead.
// When enabled, the extension automatically checks the Go proxy if there are updates available for Go and the Go tools (at present, only gopls) it depends on and prompts the user accordingly
"go.useGoProxyToCheckForToolUpdates": true,

// Use the Go language server "gopls" from Google for powering language features like code navigation, completion, refactoring, formatting & diagnostics.
"go.useLanguageServer": true,

// Flags to pass to `go tool vet` (e.g. ["-all", "-shadow"])
"go.vetFlags": [],

// Vets code on file save using 'go tool vet'. Not applicable when using the language server's diagnostics. See 'go.languageServerExperimentalFeatures.diagnostics' setting.
//  - package: vet the current package on file saving
//  - workspace: vet all the packages in the current workspace root folder on file saving
//  - off: do not run vet automatically
"go.vetOnSave": "package",

// Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.
"gopls": {},

Describe the bug

A clear and concise description of what the bug.

When I open some go file and I want to write a function or some assignment the code completion not loads all the list but only the default function. For example when I want to use fmt and I should see the list of function, I can't see it and I just see "const, func, import, type, var" as the list. VSCode output in Extension Host Log show me an error log with this description 2022-12-07 11:21:45.149 [error] [golang.go] provider FAILED 2022-12-07 11:21:45.156 [error] Error: no identifier found at handleResponse (/Users/cocce/.vscode/extensions/golang.go-0.36.0/dist/goMain.js:4470:40) at processMessageQueue (/Users/cocce/.vscode/extensions/golang.go-0.36.0/dist/goMain.js:4293:13) at Immediate.<anonymous> (/Users/cocce/.vscode/extensions/golang.go-0.36.0/dist/goMain.js:4279:11) at process.processImmediate (node:internal/timers:466:21)

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. See error

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Screenshot 2022-12-07 at 11 53 49 Screenshot 2022-12-07 at 11 53 59
findleyr commented 1 year ago

Hi, it's unclear to us what's going on, but appears that the language server is not running. From your version output, I see that the gopls binary does not exist.

Can you run "Go: Install/Update Tools" from the command palette?

simococce02 commented 1 year ago

I tried to reinstall gopls but i just go this message in continuous loading

Screenshot 2022-12-15 at 16 21 36
simococce02 commented 1 year ago

I tried to uninstall everything concerning golang from my mac but the above error still remain

findleyr commented 1 year ago

@simococce02 do you have a go.mod or go.work in a parent directory of the folder you open? As described in that error, gopls needs to know which module(s) you are working on.

simococce02 commented 1 year ago

Yes I created both go.mod file and go.work file

simococce02 commented 1 year ago

Also now I need to test my code but terminal said that can't found function, but I have that function. If i try just to build and run a single code, it works; if I try to use testing not works

hyangah commented 1 year ago

We need more details to continue triaging.

For language intellisense feature errors - please share the language server log following the instruction here https://github.com/golang/vscode-go/wiki/troubleshooting#collect-gopls-information

For test failure - please describe how you ran the test function and show the error message that shows up in the "Go Tests" output channel. Example repro case or screenshot/video to demonstrate the issue is also helpful.

Thanks!