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

Command 'gopls.package_symbols' failed: Error: no package metadata for file {filename} #3681

Closed
BrunoKrugel opened this issue Feb 12, 2025 · 8 comments
Assignees
Milestone

Comments

@BrunoKrugel
Copy link

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.
    -go1.23.6 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.18.0-pre.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.93.1
  • Check your installed extensions to get the version of the VS Code Go extension
   golang.org/x/tools/[email protected] h1:+airkGmhm12YT67Lcv/SpkQfIe+9LiumzV1SL1+jNZU=
    github.com/BurntSushi/[email protected] h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
    github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/[email protected] h1:1xaZTydL5Gsg78QharTwKfA9FY9CZ1VQj6D/AZEvHR0=
    golang.org/x/[email protected] h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
    golang.org/x/[email protected] h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
    golang.org/x/[email protected] h1:L2k9GUV2TpQKVRGMjN94qfUMgUwOFimSQ6gipyJIjKw=
    golang.org/x/[email protected] h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
    golang.org/x/[email protected] h1:Hd/d+QygQ355a6wowhs7TdfG8iaFPkctgkKN/hhFRWU=
    golang.org/x/[email protected] h1:NPGnvPOTgnjBc9HTaUx+nj+EaUYxl5SJOWqaDYGaFYw=
    honnef.co/go/[email protected] h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=
    mvdan.cc/[email protected] h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
    mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

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.

  "gopls": {
    "ui.diagnostic.staticcheck": true,
    "ui.semanticTokens": true,
    "verboseOutput": true,
    "codelenses": {
      "gc_details": true
    }
  },

Describe the bug

After Release v0.45.1, every time I save a non .go file in my project (for example, a .json or Makefile) I receive the error Command 'gopls.package_symbols' failed: Error: no package metadata for file {filename}

Steps to reproduce the behavior:

  1. Save any non .go file (for example a .json) inside a Go project.

Screenshots or recordings

Command 'gopls.package_symbols' failed: Error: no package metadata for file file:///{filepath}/{filename}.json.
@gopherbot gopherbot added this to the Untriaged milestone Feb 12, 2025
@jbdk
Copy link

jbdk commented Feb 13, 2025

I had the same problem.
Solved it by switching "Go for Visual Studio Code" extension from pre-release version to release (v0.44.0).
I don't know if you want to stay on the pre-release version, but I had to get rid of those error messages somehow.

@BrunoKrugel
Copy link
Author

I had the same problem. Solved it by switching "Go for Visual Studio Code" extension from pre-release version to release (v0.44.0). I don't know if you want to stay on the pre-release version, but I had to get rid of those error messages somehow.

Yeah I had to leave the pre-release due this error.

@h9jiang h9jiang modified the milestones: Untriaged, v0.46.0 Feb 13, 2025
@h9jiang h9jiang self-assigned this Feb 13, 2025
@h9jiang
Copy link
Member

h9jiang commented Feb 13, 2025

Thanks for reporting this. The go extension should not trigger any package_symbol command against non-go file.

This is a mistake. Let me fix it and release v0.45.2 to make the pre-release version healthy.

@jakebailey
Copy link

It also needs to filter out non-file schemes, since those are also rejected (I have gotten the error for the git scheme, untitled, etc).

@h9jiang
Copy link
Member

h9jiang commented Feb 13, 2025

Hi jakebailey,

Thanks for the reminder. You are correct, I will also add a condition for checking doc.uri.scheme !== 'file', gopls package symbol does not work for scheme other than 'file'.

I was able to re-produce this with untitled scheme (when it's empty, its considered as plain text, but later considered as languageID go resulting in failure.)

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/649257 mentions this issue: gopls/internal/golang: avoid PackageSymbols errors with missing packages

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/649258 mentions this issue: extension/src: reload package symbol for only go file and file scheme

gopherbot pushed a commit to golang/tools that referenced this issue Feb 13, 2025
As reported in golang/vscode-go#3681, spurious errors from
gopls.package_symbols can cause very distracting popups in VS Code.

For now, err on the side of silence. In the future, we may want to
revisit this behavior.

For golang/vscode-go#3681

Change-Id: I67f8b8e1e299ef88dabbb284a151aada131652f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/649257
Reviewed-by: Hongxiang Jiang <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
gopherbot pushed a commit that referenced this issue Feb 14, 2025
Skip vscode message for package symbol command due to high frequency.

For #3681

Change-Id: If4e0749d7123d17292a9f7266e73c65c8bde332c
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/649258
Reviewed-by: Robert Findley <[email protected]>
Auto-Submit: Hongxiang Jiang <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
kokoro-CI: kokoro <[email protected]>
@h9jiang
Copy link
Member

h9jiang commented Feb 20, 2025

The fix is released in vscode-go insider version v0.45.2. Also a change in gopls.package_symbols released in gopls v0.18.0-pre.5.

@h9jiang h9jiang closed this as completed Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants