From 2b6af5f9ace725aefaab9e4e3abbcdd9f07ef5bc Mon Sep 17 00:00:00 2001 From: Rohan Challa Date: Mon, 2 Dec 2019 15:10:25 -0500 Subject: [PATCH] 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 Run-TryBot: Rohan Challa TryBot-Result: Gobot Gobot --- internal/lsp/source/highlight.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/lsp/source/highlight.go b/internal/lsp/source/highlight.go index f5c28c224a..849bc8063b 100644 --- a/internal/lsp/source/highlight.go +++ b/internal/lsp/source/highlight.go @@ -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