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: documentHighlight from subpackage selects usage for parent package #60435

Closed
borsosl opened this issue May 23, 2023 · 2 comments
Closed
Assignees
Labels
Documentation 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

@borsosl
Copy link

borsosl commented May 23, 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 windows/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.11.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.78.2
    • b3e4e68a0bc097f0ae7907b217c1119af9e03435
    • x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.38.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • gotests: C:\Users\Laci\go\bin\gotests.exe (version: v1.6.0 built with go: go1.20)
      gomodifytags: C:\Users\Laci\go\bin\gomodifytags.exe (version: v1.16.0 built with go: go1.20)
      impl: C:\Users\Laci\go\bin\impl.exe (version: v1.1.0 built with go: go1.20)
      goplay: C:\Users\Laci\go\bin\goplay.exe (version: v1.0.0 built with go: go1.20)
      dlv: C:\Users\Laci\go\bin\dlv.exe (version: v1.20.2 built with go: go1.20)
      staticcheck: C:\Users\Laci\go\bin\staticcheck.exe (version: v0.4.3 built with go: go1.20)
      gopls: C:\Users\Laci\go\bin\gopls.exe (version: v0.11.0 built with go: go1.20)

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.testFlags": ["-v"],
"gopls": {
    "buildFlags": ["-tags=integration"]
},

Describe the bug

Use a source file that imports both a parent and a subpackage:

import (
...
"net/http"
"net/http/httptest"
...
)

Normally clicking on an imported package and using F7 cycles through its usages. In the case of the subpackage, it also finds the parent package usages.
Expected: Starting from the subpackage import, F7 should cycle through only usages of the subpackage.

Steps to reproduce the behavior:

  1. Open a source file that imports both "net/http" and "net/http/httptest" and uses http first
  2. Click on 'httptest' within the imports
  3. Press F7
  4. Observe that the first http usage is selected

Screenshots or recordings

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

@suzmue
Copy link
Contributor

suzmue commented May 25, 2023

Thanks for the report! I am able to reproduce that the parent package references are selected.

This appears to be an issue with the textDocument/documentHighlight feature in gopls.

Repro case:

main.go:

package main

import (
	"net/http"
	"net/http/httptest"
)

func main() {
	http.CanonicalHeaderKey("")
	httptest.NewRecorder()
}

Screenshot 2023-05-25 at 12 52 52 PM

Log:

[Trace - 12:51:35.785 PM] Sending request 'textDocument/documentHighlight - (15)'.
Params: {"textDocument":{"uri":"file:///Users/suzmue/issue2781/main.go"},"position":{"line":4,"character":15}}


[Trace - 12:51:35.786 PM] Received response 'textDocument/documentHighlight - (15)' in 0ms.
Result: [{"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":20}},"kind":1},{"range":{"start":{"line":8,"character":1},"end":{"line":8,"character":5}},"kind":1},{"range":{"start":{"line":9,"character":1},"end":{"line":9,"character":9}},"kind":1}]

@suzmue suzmue changed the title Go to Next Symbol Highlight from subpackage selects usage for parent package x/tools/gopls: documentHighlight from subpackage selects usage for parent package May 25, 2023
@suzmue suzmue transferred this issue from golang/vscode-go May 25, 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 May 25, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 25, 2023
@suzmue suzmue modified the milestones: Unreleased, gopls/later May 25, 2023
@adonovan adonovan self-assigned this May 25, 2023
@gopherbot
Copy link

Change https://go.dev/cl/498268 mentions this issue: internal/lsp/source: use exact match in import highlighting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 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