internal/lsp: skip return highlighting if cursor is in arglist of func
If the cursor is within an argument that is within a callExpr which is
in a return statement, we only want it to highlight the ident that the cursor
is in. We do not want it to highlight the entire function.
Updates golang/go#34496
Change-Id: If4025660a99fd5df90098e0560a5e9e7260e33c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211338
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/source/highlight.go b/internal/lsp/source/highlight.go
index b17a169..26ad808 100644
--- a/internal/lsp/source/highlight.go
+++ b/internal/lsp/source/highlight.go
@@ -60,11 +60,20 @@
inReturnList := false
Outer:
// Reverse walk the path till we get to the func block.
- for _, n := range path {
+ for i, 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.CallExpr:
+ // If cusor is an arg in a callExpr, we don't want control flow highlighting.
+ if i > 0 {
+ for _, arg := range node.Args {
+ if arg == path[i-1] {
+ return nil, nil
+ }
+ }
+ }
case *ast.Field:
inReturnList = true
case *ast.FuncLit:
diff --git a/internal/lsp/testdata/highlights/highlights.go b/internal/lsp/testdata/highlights/highlights.go
index 39acf23..71a9f17 100644
--- a/internal/lsp/testdata/highlights/highlights.go
+++ b/internal/lsp/testdata/highlights/highlights.go
@@ -101,3 +101,8 @@
}
return 4.9, "test" //@mark(retVal51, "4.9"),mark(retVal52, "\"test\""),highlight(retVal51, retVal31, retVal41, retVal51),highlight(retVal52, retVal32, retVal42, retVal52)
}
+
+func testReturnFunc() int32 { //@mark(retCall, "int32")
+ mulch := 1 //@mark(mulchDec, "mulch"),highlight(mulchDec, mulchDec, mulchRet)
+ return int32(mulch) //@mark(mulchRet, "mulch"),mark(retFunc, "int32"),mark(retTotal, "int32(mulch)"),highlight(mulchRet, mulchDec, mulchRet),highlight(retFunc, retCall, retFunc, retTotal)
+}
diff --git a/internal/lsp/testdata/summary.txt.golden b/internal/lsp/testdata/summary.txt.golden
index fe545cc..7ca0e42 100644
--- a/internal/lsp/testdata/summary.txt.golden
+++ b/internal/lsp/testdata/summary.txt.golden
@@ -13,7 +13,7 @@
SuggestedFixCount = 1
DefinitionsCount = 39
TypeDefinitionsCount = 2
-HighlightsCount = 41
+HighlightsCount = 44
ReferencesCount = 7
RenamesCount = 22
PrepareRenamesCount = 8