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 

Activity

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Jul 27, 2023
added this to the Unreleased milestone on Jul 27, 2023
hyangah

hyangah commented on Jul 27, 2023

@hyangah
Contributor

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

findleyr

findleyr commented on Jul 28, 2023

@findleyr
Member

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

self-assigned this
on Jul 28, 2023
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[/+] on Jul 28, 2023
gopherbot

gopherbot commented on Jul 28, 2023

@gopherbot
Contributor

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

5 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @hyangah@gopherbot@findleyr@willdhorn

      Issue actions

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