1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:44:42 -07:00

internal/lsp/cmd: handle errors when adding a file

Change-Id: Iaed5c92fe777e5b9b588614b5c1696851e3f6c93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-08-01 16:31:02 -04:00
parent 73d708539c
commit 249e2b9b6d

View File

@ -324,7 +324,7 @@ func (c *cmdClient) PublishDiagnostics(ctx context.Context, p *protocol.PublishD
func (c *cmdClient) getFile(ctx context.Context, uri span.URI) *cmdFile {
file, found := c.files[uri]
if !found {
if !found || file.err != nil {
file = &cmdFile{
uri: uri,
hasDiagnostics: make(chan struct{}),
@ -335,7 +335,7 @@ func (c *cmdClient) getFile(ctx context.Context, uri span.URI) *cmdFile {
fname := uri.Filename()
content, err := ioutil.ReadFile(fname)
if err != nil {
file.err = fmt.Errorf("%v: %v", uri, err)
file.err = fmt.Errorf("getFile %v: %v", uri, err)
return file
}
f := c.fset.AddFile(fname, -1, len(content))
@ -350,6 +350,13 @@ func (c *connection) AddFile(ctx context.Context, uri span.URI) *cmdFile {
defer c.Client.filesMu.Unlock()
file := c.Client.getFile(ctx, uri)
// This should never happen.
if file == nil {
return &cmdFile{
uri: uri,
err: fmt.Errorf("no file found for %s", uri),
}
}
if file.err != nil || file.added {
return file
}