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: unable to find references for struct fields that use type param composite lits #61618

Closed
willdhorn opened this issue Jul 27, 2023 · 4 comments
Assignees
Labels
gopls/generics Issues related to gopls' support for generics 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

@willdhorn
Copy link

willdhorn commented Jul 27, 2023

gopls version: v0.12.4 (go1.20.3)
gopls flags:
update flags: proxy
extension version: 0.39.1
go version: 1.20.3
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Thu, 27 Jul 2023 03:27:43 GMT
restart history:
Tue, 25 Jul 2023 20:01:41 GMT: activation (enabled: true)
Tue, 25 Jul 2023 20:08:52 GMT: config change (enabled: true)
Tue, 25 Jul 2023 20:09:30 GMT: config change (enabled: true)
Tue, 25 Jul 2023 20:09:41 GMT: config change (enabled: true)
Tue, 25 Jul 2023 20:11:07 GMT: config change (enabled: true)

This is a followup or additional issue related to #61614 using the same minimal example I am unable to find references (cmd/ctrl+click in VSCode and other editors) for the generic fields.

What did you do?

If I cmd+click on a usage of the field, like 'element', then it correctly takes to the definition, but if I then cmd+click on the definition of the field, it does not show it's references. Instead it shows the message "No type definition found for 'elements'", (which is correct I guess) since I have that configured as the fallback action in vscode. For non generic fields, like 'name', it shows the other references as expected.

type builder[S ~[]F, F ~string] struct {
	name string  // <-- cmd+click here correctly shows references
	elements S // <-- [Definition] - cmd+click here does not show references and runs alternate gotoLocation command
	elemData map[F][]ElemData[F]
	// other fields...
}
type ElemData struct {
  Name F
  // other fields...
}
type BuilderImpl[S ~[]F, F ~string] struct{ builder[S, F] }
func NewBuilderImpl[S ~[]F, F ~string](name string)  *BuilderImpl[S, F] {
  return &BuilderImpl[S,F]{
	builder[S, F]{
	  name: name,
	  elements: S{}, // <-- [Usage] - cmd+click here takes me to [Definition]
	  elemData: map[F][]ElemData[F]{},
	}
  }
}

Editor and settings

  "editor.gotoLocation.alternativeReferenceCommand": "editor.action.goToTypeDefinition"
  "editor.gotoLocation.alternativeImplementationCommand": "editor.action.revealDefinition",
  "editor.gotoLocation.alternativeTypeDefinitionCommand": "editor.action.goToImplementation",
  "editor.gotoLocation.alternativeDefinitionCommand": "editor.action.goToReferences",
  "editor.gotoLocation.alternativeDeclarationCommand": "editor.action.referenceSearch.trigger",
  "editor.gotoLocation.multipleTypeDefinitions": "peek",
  "editor.gotoLocation.multipleReferences": "peek",
  "editor.gotoLocation.multipleDefinitions": "peek",
  "editor.gotoLocation.multipleDeclarations": "peek",
  "editor.gotoLocation.multipleImplementations": "peek",
// gopls settings, but nothing relevant to this issue
  "gopls": {
    "ui.semanticTokens": true,
    "ui.noSemanticString": false,
    "ui.completion.usePlaceholders": false,
    "ui.diagnostic.analyses": {
      "infertypeargs": false
    },
    "ui.documentation.linksInHover": false,
    "ui.navigation.importShortcut": "Definition"
  },

Logs

This is the only relevant log message I'm getting

[Error - 3:02:13 PM] Request textDocument/typeDefinition failed.
  Message: no type definition for elements
  Code: 0 
@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 Jul 27, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jul 27, 2023
@hyangah hyangah added the gopls/generics Issues related to gopls' support for generics label Jul 27, 2023
@hyangah hyangah modified the milestones: Unreleased, gopls/v0.14.0 Jul 27, 2023
@hyangah
Copy link
Contributor

hyangah commented Jul 27, 2023

I could still reproduce this with gopls@v0.13.0-pre.3 (go1.21rc3)

@findleyr
Copy link
Contributor

Thanks. This used to work in v0.11.0, I think. It looks like the new references logic dropped the 'equalOrigin' logic, unfortunately.

@findleyr findleyr self-assigned this Jul 28, 2023
@findleyr findleyr changed the title x/tools/gopls: unable to find references for stuct fields that use type param composite lits x/tools/gopls: unable to find references for struct fields that use type param composite lits Jul 28, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.0, gopls/v0.13.1 Jul 28, 2023
@gopherbot
Copy link

Change https://go.dev/cl/513780 mentions this issue: gopls/internal/lsp/source: reinstance equalOrigin for references check

@willdhorn
Copy link
Author

Thanks again for fixing this so quickly!

Unfortunately it seems I'm destined to keep you busy lol as just I made gopls crash again, this time when renaming a method of "BuilderImpl"

Issue: #61640

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/generics Issues related to gopls' support for generics 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