Skip to content

x/tools/gopls: unable to find references for struct fields that use type param composite lits #61618

Closed
@willdhorn

Description

@willdhorn

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 

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/genericsIssues related to gopls' support for generics

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions