diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 4f3bffb215..3da975ddef 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -419,6 +419,7 @@ func (s *Session) updateOverlays(ctx context.Context, changes []source.FileModif return overlays, nil } +// GetFile implements the source.FileSystem interface. func (s *Session) GetFile(uri span.URI) source.FileHandle { if overlay := s.readOverlay(uri); overlay != nil { return overlay @@ -436,3 +437,16 @@ func (s *Session) readOverlay(uri span.URI) *overlay { } return nil } + +func (s *Session) UnsavedFiles() []span.URI { + s.overlayMu.Lock() + defer s.overlayMu.Unlock() + + var unsaved []span.URI + for uri, overlay := range s.overlays { + if !overlay.saved { + unsaved = append(unsaved, uri) + } + } + return unsaved +} diff --git a/internal/lsp/source/view.go b/internal/lsp/source/view.go index 29b3671e59..e82b11d3f2 100644 --- a/internal/lsp/source/view.go +++ b/internal/lsp/source/view.go @@ -185,6 +185,9 @@ type Session interface { // It returns the resulting snapshots, a guaranteed one per view. DidModifyFiles(ctx context.Context, changes []FileModification) ([]Snapshot, error) + // UnsavedFiles returns a slice of open but unsaved files in the session. + UnsavedFiles() []span.URI + // Options returns a copy of the SessionOptions for this session. Options() Options