internal/lsp: add nil check for control flow highlighting
Added a check to make sure that highlighting the control flow of
a function only continues if the cursor is actually in a function.
Change-Id: Idac90d9e55c09c3dcb9ae938585157658acc95e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209581
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 f5c28c2..849bc80 100644
--- a/internal/lsp/source/highlight.go
+++ b/internal/lsp/source/highlight.go
@@ -91,6 +91,10 @@
inReturnList = inReturnList || path[0] != returnStmt
}
}
+ // Cursor is not in a function.
+ if enclosingFunc == nil {
+ return nil, nil
+ }
// If the cursor is on a "return" or "func" keyword, we should highlight all of the exit
// points of the function, including the "return" and "func" keywords.
highlightAllReturnsAndFunc := path[0] == returnStmt || path[0] == enclosingFunc