Skip to content

Commit e7d61d9

Browse files
committed
gopls/internal/lsp/cache: simplify named error values
Simplify error values that were defined in the source package, but never used in the source package. These should have reduced to ~nothing: the only remaining use-case for named errors was to implement support for legacy Go command behavior. Additional TODOs are left to clean this up. Change-Id: I4047974c5accc9fcbc4be921ba50d567bc364c2e Reviewed-on: https://go-review.googlesource.com/c/tools/+/543917 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent 3a915e4 commit e7d61d9

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

gopls/internal/lsp/cache/mod_tidy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cache
66

77
import (
88
"context"
9+
"errors"
910
"fmt"
1011
"go/ast"
1112
"go/token"
@@ -25,6 +26,9 @@ import (
2526
"golang.org/x/tools/internal/memoize"
2627
)
2728

29+
// This error is sought by mod diagnostics.
30+
var ErrNoModOnDisk = errors.New("go.mod file is not on disk")
31+
2832
// ModTidy returns the go.mod file that would be obtained by running
2933
// "go mod tidy". Concurrent requests are combined into a single command.
3034
func (s *Snapshot) ModTidy(ctx context.Context, pm *ParsedModule) (*TidiedModule, error) {

gopls/internal/lsp/cache/pkg.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ var (
6666
AllowNetwork = source.AllowNetwork
6767
LoadWorkspace = source.LoadWorkspace
6868
WriteTemporaryModFile = source.WriteTemporaryModFile
69-
70-
// Errors
71-
ErrNoModOnDisk = source.ErrNoModOnDisk
72-
ErrViewExists = source.ErrViewExists
7369
)
7470

7571
// Functions

gopls/internal/lsp/cache/session.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cache
66

77
import (
88
"context"
9+
"errors"
910
"fmt"
1011
"os"
1112
"path/filepath"
@@ -73,6 +74,9 @@ func (s *Session) Cache() *Cache {
7374
return s.cache
7475
}
7576

77+
// TODO(rfindley): is the logic surrounding this error actually necessary?
78+
var ErrViewExists = errors.New("view already exists for session")
79+
7680
// NewView creates a new View, returning it and its first snapshot. If a
7781
// non-empty tempWorkspace directory is provided, the View will record a copy
7882
// of its gopls workspace module in that directory, so that client tooling

gopls/internal/lsp/general.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"golang.org/x/tools/gopls/internal/lsp/cache"
2424
"golang.org/x/tools/gopls/internal/lsp/debug"
2525
"golang.org/x/tools/gopls/internal/lsp/protocol"
26-
"golang.org/x/tools/gopls/internal/lsp/source"
2726
"golang.org/x/tools/gopls/internal/settings"
2827
"golang.org/x/tools/gopls/internal/telemetry"
2928
"golang.org/x/tools/internal/event"
@@ -315,7 +314,7 @@ func (s *server) addFolders(ctx context.Context, folders []protocol.WorkspaceFol
315314
work := s.progress.Start(ctx, "Setting up workspace", "Loading packages...", nil, nil)
316315
snapshot, release, err := s.addView(ctx, folder.Name, uri)
317316
if err != nil {
318-
if err == source.ErrViewExists {
317+
if err == cache.ErrViewExists {
319318
continue
320319
}
321320
viewErrors[uri] = err

gopls/internal/lsp/mod/diagnostics.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ func ModTidyDiagnostics(ctx context.Context, snapshot *cache.Snapshot, fh file.H
115115
}
116116

117117
tidied, err := snapshot.ModTidy(ctx, pm)
118-
if err != nil && !source.IsNonFatalGoModError(err) {
118+
if err != nil && err != cache.ErrNoModOnDisk {
119+
// TODO(rfindley): the check for ErrNoModOnDisk was historically determined
120+
// to be benign, but may date back to the time when the Go command did not
121+
// have overlay support.
122+
//
123+
// See if we can pass the overlay to the Go command, and eliminate this guard..
119124
event.Error(ctx, fmt.Sprintf("tidy: diagnosing %s", pm.URI), err)
120125
}
121126
if err == nil {

gopls/internal/lsp/source/snapshot.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"context"
1010
"encoding/json"
11-
"errors"
1211
"fmt"
1312
"go/ast"
1413
"go/parser"
@@ -571,16 +570,6 @@ func RemoveIntermediateTestVariants(pmetas *[]*Metadata) {
571570
*pmetas = res
572571
}
573572

574-
var (
575-
ErrViewExists = errors.New("view already exists for session")
576-
ErrTmpModfileUnsupported = errors.New("-modfile is unsupported for this Go version")
577-
ErrNoModOnDisk = errors.New("go.mod file is not on disk")
578-
)
579-
580-
func IsNonFatalGoModError(err error) bool {
581-
return err == ErrTmpModfileUnsupported || err == ErrNoModOnDisk
582-
}
583-
584573
// Common parse modes; these should be reused wherever possible to increase
585574
// cache hits.
586575
const (

0 commit comments

Comments
 (0)