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>
This commit is contained in:
Rohan Challa 2019-12-02 15:10:25 -05:00
parent 5a103c92be
commit 2b6af5f9ac
1 changed files with 4 additions and 0 deletions

View File

@ -91,6 +91,10 @@ Outer:
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