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 <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-02-15 13:32:38 -06:00
Родитель e8c45e0433
Коммит 550322b34f
1 изменённых файлов: 16 добавлений и 3 удалений

19
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