From 7e522c867c8e0dd6462b9fe975c66694759fddec Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 30 Nov 2020 15:48:40 -0500 Subject: [PATCH] internal/lsp: update modifications to directories at the LSP level Expanding the set of modifications in the cache package leads to a mismatch when the didModifyFiles code in text_synchronization.go processes the list of modifications. Change-Id: Id0b7fea445103b34838fb9b03aee95a01e454306 Reviewed-on: https://go-review.googlesource.com/c/tools/+/274192 Trust: Rebecca Stambler Run-TryBot: Rebecca Stambler gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Heschi Kreinick --- internal/lsp/cache/session.go | 8 +------- internal/lsp/source/view.go | 5 +++++ internal/lsp/text_synchronization.go | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index bcf7232ee9..a4394a2e93 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -422,10 +422,6 @@ func (s *Session) DidModifyFiles(ctx context.Context, changes []source.FileModif views := make(map[*View]map[span.URI]*fileChange) bestViews := map[span.URI]source.View{} - // If the set of changes included directories, expand those directories - // to their files. - changes = s.expandChangesToDirectories(ctx, changes) - overlays, err := s.updateOverlays(ctx, changes) if err != nil { return nil, nil, nil, err @@ -498,9 +494,7 @@ func (s *Session) DidModifyFiles(ctx context.Context, changes []source.FileModif return bestViews, snapshots, releases, nil } -// expandChangesToDirectories returns the set of changes with the directory -// changes removed and expanded to include all of the files in the directory. -func (s *Session) expandChangesToDirectories(ctx context.Context, changes []source.FileModification) []source.FileModification { +func (s *Session) ExpandModificationsToDirectories(ctx context.Context, changes []source.FileModification) []source.FileModification { var snapshots []*snapshot for _, v := range s.views { snapshot, release := v.getSnapshot(ctx) diff --git a/internal/lsp/source/view.go b/internal/lsp/source/view.go index cc9511daf4..ddf8f6b477 100644 --- a/internal/lsp/source/view.go +++ b/internal/lsp/source/view.go @@ -289,6 +289,11 @@ type Session interface { // resulting snapshots, a guaranteed one per view. DidModifyFiles(ctx context.Context, changes []FileModification) (map[span.URI]View, map[View]Snapshot, []func(), error) + // ExpandModificationsToDirectories returns the set of changes with the + // directory changes removed and expanded to include all of the files in + // the directory. + ExpandModificationsToDirectories(ctx context.Context, changes []FileModification) []FileModification + // Overlays returns a slice of file overlays for the session. Overlays() []Overlay diff --git a/internal/lsp/text_synchronization.go b/internal/lsp/text_synchronization.go index d08d25f7ab..745b5bcb8d 100644 --- a/internal/lsp/text_synchronization.go +++ b/internal/lsp/text_synchronization.go @@ -186,6 +186,11 @@ func (s *Server) didModifyFiles(ctx context.Context, modifications []source.File }() }() } + + // If the set of changes included directories, expand those directories + // to their files. + modifications = s.session.ExpandModificationsToDirectories(ctx, modifications) + views, snapshots, releases, err := s.session.DidModifyFiles(ctx, modifications) if err != nil { return err