mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07:00
internal/lsp/cache: add an UnsavedFiles method to Session
It is useful to know whether the session has any unsaved files, for example to warn/error when executing a command that interacts only with files on disk. Add a new UnsavedFiles method to the Session. Change-Id: Iea4bf472e3ed6897979306b670eb974a2ee0d3bb Reviewed-on: https://go-review.googlesource.com/c/tools/+/232747 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
ff647943c7
commit
08cbf656ce
14
internal/lsp/cache/session.go
vendored
14
internal/lsp/cache/session.go
vendored
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user