diff --git a/internal/lsp/source/highlight.go b/internal/lsp/source/highlight.go index d8a72bdac9..b17a1696af 100644 --- a/internal/lsp/source/highlight.go +++ b/internal/lsp/source/highlight.go @@ -62,6 +62,9 @@ Outer: // Reverse walk the path till we get to the func block. for _, n := range path { switch node := n.(type) { + case *ast.KeyValueExpr: + // If cursor is in a key: value expr, we don't want control flow highlighting + return nil, nil case *ast.Field: inReturnList = true case *ast.FuncLit: @@ -232,7 +235,7 @@ func highlightIdentifiers(ctx context.Context, snapshot Snapshot, m *protocol.Co if !ok { return true } - if n.Name != id.Name || n.Obj != id.Obj { + if n.Name != id.Name { return false } if nObj := pkg.GetTypesInfo().ObjectOf(n); nObj != idObj { diff --git a/internal/lsp/testdata/highlights/highlights.go b/internal/lsp/testdata/highlights/highlights.go index ff435307d2..39acf23bdb 100644 --- a/internal/lsp/testdata/highlights/highlights.go +++ b/internal/lsp/testdata/highlights/highlights.go @@ -7,9 +7,15 @@ import ( "golang.org/x/tools/internal/lsp/protocol" ) -type F struct{ bar int } +type F struct{ bar int } //@mark(barDeclaration, "bar"),highlight(barDeclaration, barDeclaration, bar1, bar2, bar3) -var foo = F{bar: 52} //@mark(fooDeclaration, "foo"),highlight(fooDeclaration, fooDeclaration, fooUse) +func _() F { + return F{ + bar: 123, //@mark(bar1, "bar"),highlight(bar1, barDeclaration, bar1, bar2, bar3) + } +} + +var foo = F{bar: 52} //@mark(fooDeclaration, "foo"),mark(bar2, "bar"),highlight(fooDeclaration, fooDeclaration, fooUse),highlight(bar2, barDeclaration, bar1, bar2, bar3) func Print() { //@mark(printFunc, "Print"),highlight(printFunc, printFunc, printTest) fmt.Println(foo) //@mark(fooUse, "foo"),highlight(fooUse, fooDeclaration, fooUse) @@ -17,7 +23,7 @@ func Print() { //@mark(printFunc, "Print"),highlight(printFunc, printFunc, print } func (x *F) Inc() { //@mark(xDeclaration, "x"),highlight(xDeclaration, xDeclaration, xUse) - x.bar++ //@mark(xUse, "x"),highlight(xUse, xDeclaration, xUse) + x.bar++ //@mark(xUse, "x"),mark(bar3, "bar"),highlight(xUse, xDeclaration, xUse),highlight(bar3, barDeclaration, bar1, bar2, bar3) } func testFunctions() { diff --git a/internal/lsp/testdata/summary.txt.golden b/internal/lsp/testdata/summary.txt.golden index 19f615c12a..1ab98b8347 100644 --- a/internal/lsp/testdata/summary.txt.golden +++ b/internal/lsp/testdata/summary.txt.golden @@ -13,7 +13,7 @@ ImportCount = 7 SuggestedFixCount = 1 DefinitionsCount = 38 TypeDefinitionsCount = 2 -HighlightsCount = 37 +HighlightsCount = 41 ReferencesCount = 7 RenamesCount = 22 PrepareRenamesCount = 8