1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:14:40 -07:00

internal/lsp: add an implementation for textDocument/didSave

This change marks the overlay for a saved file as "on disk".
This will reduce the number of overlays we provide to go/packages, which
can be expensive.

Updates golang/go#31796, golang/go#32457

Change-Id: I8e69503ab80bba29caf4e42491d87e643bf17f1a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181123
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
This commit is contained in:
Rebecca Stambler 2019-06-07 11:34:41 -04:00
parent eacb66d2a7
commit e6ce0ddf03
2 changed files with 15 additions and 3 deletions

View File

@ -42,6 +42,10 @@ type overlay struct {
uri span.URI
data []byte
hash string
// onDisk is true if a file has been saved on disk,
// and therefore does not need to be part of the overlay sent to go/packages.
onDisk bool
}
func (s *session) Shutdown(ctx context.Context) {
@ -181,6 +185,12 @@ func (s *session) DidOpen(uri span.URI) {
}
func (s *session) DidSave(uri span.URI) {
s.overlayMu.Lock()
defer s.overlayMu.Unlock()
if overlay, ok := s.overlays[uri]; ok {
overlay.onDisk = true
}
}
func (s *session) DidClose(uri span.URI) {
@ -236,6 +246,9 @@ func (s *session) buildOverlay() map[string][]byte {
overlays := make(map[string][]byte)
for uri, overlay := range s.overlays {
if overlay.onDisk {
continue
}
if filename, err := uri.Filename(); err == nil {
overlays[filename] = overlay.data
}

View File

@ -100,9 +100,8 @@ func (s *Server) applyChanges(ctx context.Context, params *protocol.DidChangeTex
}
func (s *Server) didSave(ctx context.Context, params *protocol.DidSaveTextDocumentParams) error {
uri := span.NewURI(params.TextDocument.URI)
s.session.DidSave(uri)
return nil // ignore
s.session.DidSave(span.NewURI(params.TextDocument.URI))
return nil
}
func (s *Server) didClose(ctx context.Context, params *protocol.DidCloseTextDocumentParams) error {