From 550322b34f0c1a077f457cc62ee5ccd634948797 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 15 Feb 2019 13:32:38 -0600 Subject: [PATCH] internal/lsp: return an updated view after setting a file's contents Change-Id: I71cfa1463c3f3ec3b80faf9dd57c81d6fa75c466 Reviewed-on: https://go-review.googlesource.com/c/162892 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- internal/lsp/cache/view.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 38f4a5b8..902a0d39 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -58,7 +58,21 @@ func (v *View) SetContent(ctx context.Context, uri source.URI, content []byte) ( v.mu.Lock() defer v.mu.Unlock() - f := v.getFile(uri) + newView := NewView(&v.Config) + + for fURI, f := range v.files { + newView.files[fURI] = &File{ + URI: fURI, + view: newView, + active: f.active, + content: f.content, + ast: f.ast, + token: f.token, + pkg: f.pkg, + } + } + + f := newView.getFile(uri) f.content = content // Resetting the contents invalidates the ast, token, and pkg fields. @@ -83,8 +97,7 @@ func (v *View) SetContent(ctx context.Context, uri source.URI, content []byte) ( } } - // TODO(rstambler): We should really return a new, updated view. - return v, nil + return newView, nil } // GetFile returns a File for the given URI. It will always succeed because it