1
0
mirror of https://github.com/golang/go synced 2024-10-01 07:28:35 -06:00
go/internal/lsp
Albert Teoh 773fe550c1 gopls: return file error if file open fails
The bug manifests itself when a non-existent file is passed in as an
argument to gopls, causing a nil pointer dereference panic. This is due
to an attempt to reference the "mapper" attribute, which is not set if
the file is not found.

The resolution is to check for an informative error that is set on the
file instance after "getFile" is called and return it immediately to the
caller to allow the error to propagate up to the main() function and
print the error to stdout.

Testing:
--------

Non-existent file:
$ gopls -rpc.trace -v check gopls/doesnotexist.go
check: file:///Users/albertteoh/repo/tools/gopls/doesnotexist.go: open /Users/albertteoh/repo/tools/gopls/doesnotexist.go: no such file or directory

Existing go file:
$ gopls -rpc.trace -v check internal/lsp/definition.go
2019/08/03 13:33:00 Info:go/packages.Load
	packages = 2
2019/08/03 13:33:00 Info:go/packages.Load
	package = golang.org/x/tools/internal/lsp
...

Fixes golang/go#33445

Change-Id: Ib56d8a4b7f23f4882b75cf684c5d18a49d27b824
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188857
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-05 16:01:13 +00:00
..
browser internal/lsp: add version and bug commands 2019-05-11 04:16:02 +00:00
cache internal/lsp: handle potential nil pointers in GetToken 2019-08-02 20:08:13 +00:00
cmd gopls: return file error if file open fails 2019-08-05 16:01:13 +00:00
debug internal/lsp: new tracing system 2019-07-18 23:00:54 +00:00
diff internal/lsp: enable incrementalSync by default 2019-06-26 20:40:24 +00:00
fuzzy internal/lsp/fuzzy: add fuzzy matching library 2019-07-03 21:24:19 +00:00
protocol internal/lsp: fix watched file protocol constants 2019-07-31 19:43:47 +00:00
snippet internal/lsp: introduce snippet builder object 2019-04-25 18:37:29 +00:00
source internal/imports, internal/lsp: quick fix import errors 2019-08-01 20:53:47 +00:00
telemetry internal/lsp: use correct desc for annotation 2019-07-30 21:53:28 +00:00
testdata internal/lsp: format files in packages with errors 2019-07-26 23:07:22 +00:00
tests internal/lsp: format files in packages with errors 2019-07-26 23:07:22 +00:00
code_action.go internal/imports, internal/lsp: quick fix import errors 2019-08-01 20:53:47 +00:00
completion.go internal/lsp: convert logging calls 2019-07-18 19:03:12 +00:00
definition.go internal/lsp: attach documentation to signature help 2019-06-06 17:46:28 +00:00
diagnostics.go internal/lsp: convert logging calls 2019-07-18 19:03:12 +00:00
format.go internal/lsp: cache the *ast.File and *token.File on the package 2019-07-16 19:44:59 +00:00
general.go internal/lsp: set initialized state 2019-07-31 19:33:23 +00:00
highlight.go internal/lsp: convert logging calls 2019-07-18 19:03:12 +00:00
hover.go internal/lsp: swallow hover error over identifier not found 2019-07-24 18:42:53 +00:00
link.go internal/lsp: convert logging calls 2019-07-18 19:03:12 +00:00
lsp_test.go internal/lsp: purge the remains of the xlog system now it is not used 2019-07-18 19:11:56 +00:00
references.go internal/lsp: convert logging calls 2019-07-18 19:03:12 +00:00
rename.go internal/lsp: separate refactorings out of memoization CL 2019-06-25 16:04:30 +00:00
reset_golden.sh internal/lsp: fix definition tests to use golden files 2019-05-10 21:06:55 +00:00
server.go internal/lsp: set initialized state 2019-07-31 19:33:23 +00:00
signature_help.go internal/lsp: convert logging calls 2019-07-18 19:03:12 +00:00
symbols.go internal/lsp: reduce trace package to minimal StartSpan for now 2019-07-11 17:25:55 +00:00
text_synchronization.go internal/lsp: convert logging calls 2019-07-18 19:03:12 +00:00
util.go internal/lsp: cache the *ast.File and *token.File on the package 2019-07-16 19:44:59 +00:00
workspace.go internal/lsp: set initialized state 2019-07-31 19:33:23 +00:00