From ca627f833ccd414a5e4e8407481d2cfff5e7dcb2 Mon Sep 17 00:00:00 2001 From: pjw Date: Sat, 27 Mar 2021 15:25:52 -0400 Subject: [PATCH] internal/lsp/semantic: fix some type definitions xyz and err in type A func(xyz int) (err error), or type B struct{xyz int} were incorrectly marked as types, when they are not. These are now marked as variables (although the choice is somewhat arbitrary for A). Fixes golang/go#45233 Change-Id: I2df4eab7606c356f30bf3337c12d9190e74bc392 Reviewed-on: https://go-review.googlesource.com/c/tools/+/305209 Reviewed-by: Rebecca Stambler Trust: Peter Weinberger --- internal/lsp/semantic.go | 9 +++++++++ internal/lsp/testdata/semantic/a.go.golden | 2 +- internal/lsp/tests/README.md | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/lsp/semantic.go b/internal/lsp/semantic.go index 033ddd4464..fbca581e49 100644 --- a/internal/lsp/semantic.go +++ b/internal/lsp/semantic.go @@ -451,6 +451,15 @@ func (e *encoded) definitionFor(x *ast.Ident) (tokenType, []string) { case *ast.InterfaceType: return tokMember, mods case *ast.TypeSpec: + // GenDecl/Typespec/FuncType/FieldList/Field/Ident + // (type A func(b uint64)) (err error) + // b and err should not be tokType, but tokVaraible + // and in GenDecl/TpeSpec/StructType/FieldList/Field/Ident + // (type A struct{b uint64}) + fldm := e.stack[len(e.stack)-2] + if _, ok := fldm.(*ast.Field); ok { + return tokVariable, mods + } return tokType, mods } } diff --git a/internal/lsp/testdata/semantic/a.go.golden b/internal/lsp/testdata/semantic/a.go.golden index c4286295bf..b09c20d9e1 100644 --- a/internal/lsp/testdata/semantic/a.go.golden +++ b/internal/lsp/testdata/semantic/a.go.golden @@ -27,7 +27,7 @@ ) /*⇒4,keyword,[]*/type /*⇒1,type,[definition]*/A /*⇒6,keyword,[]*/struct { - /*⇒1,type,[definition]*/X /*⇒3,type,[defaultLibrary]*/int /*⇒6,comment,[]*/`foof` + /*⇒1,variable,[definition]*/X /*⇒3,type,[defaultLibrary]*/int /*⇒6,comment,[]*/`foof` } /*⇒4,keyword,[]*/type /*⇒1,type,[definition]*/B /*⇒9,keyword,[]*/interface { /*⇒1,type,[]*/A diff --git a/internal/lsp/tests/README.md b/internal/lsp/tests/README.md index d8ba10f906..2c18675f7e 100644 --- a/internal/lsp/tests/README.md +++ b/internal/lsp/tests/README.md @@ -52,7 +52,7 @@ path and heading into a -run argument: ```bash cd /path/to/tools -go test ./internal/lsp -v -run TestLSP/Modules/SuggestedFix/bar_11_21 +go test ./internal/lsp/... -v -run TestLSP/Modules/SuggestedFix/bar_11_21 ``` ## Resetting marker tests