internal/lsp: improve error message about unsaved files

We should mention which files gopls thinks are unsaved.

Change-Id: I291976ad9bbf52e27c84fae650c613eb7ece8e83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340469
Trust: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Rebecca Stambler 2021-08-06 14:10:12 -04:00
parent 7bc3c281e1
commit 92b2fbe726
1 changed files with 5 additions and 1 deletions

View File

@ -73,11 +73,15 @@ type commandFunc func(context.Context, commandDeps) error
func (c *commandHandler) run(ctx context.Context, cfg commandConfig, run commandFunc) (err error) {
if cfg.requireSave {
var unsaved []string
for _, overlay := range c.s.session.Overlays() {
if !overlay.Saved() {
return errors.New("All files must be saved first")
unsaved = append(unsaved, overlay.URI().Filename())
}
}
if len(unsaved) > 0 {
return errors.Errorf("All files must be saved first (unsaved: %v).", unsaved)
}
}
var deps commandDeps
if cfg.forURI != "" {