mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00: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:
parent
73d708539c
commit
249e2b9b6d
@ -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 {
|
func (c *cmdClient) getFile(ctx context.Context, uri span.URI) *cmdFile {
|
||||||
file, found := c.files[uri]
|
file, found := c.files[uri]
|
||||||
if !found {
|
if !found || file.err != nil {
|
||||||
file = &cmdFile{
|
file = &cmdFile{
|
||||||
uri: uri,
|
uri: uri,
|
||||||
hasDiagnostics: make(chan struct{}),
|
hasDiagnostics: make(chan struct{}),
|
||||||
@ -335,7 +335,7 @@ func (c *cmdClient) getFile(ctx context.Context, uri span.URI) *cmdFile {
|
|||||||
fname := uri.Filename()
|
fname := uri.Filename()
|
||||||
content, err := ioutil.ReadFile(fname)
|
content, err := ioutil.ReadFile(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
file.err = fmt.Errorf("%v: %v", uri, err)
|
file.err = fmt.Errorf("getFile %v: %v", uri, err)
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
f := c.fset.AddFile(fname, -1, len(content))
|
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()
|
defer c.Client.filesMu.Unlock()
|
||||||
|
|
||||||
file := c.Client.getFile(ctx, uri)
|
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 {
|
if file.err != nil || file.added {
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user