gopls/internal/lsp/fake: eliminate the unnecessary ChangeFilesOnDisk API
This API is redundant with individual sandbox file operations, and is
one of the few places where we expose the (possibly unnecessary)
FileEvent type.
Change-Id: I7b06d0c3eb99b75e3f63611559b7aeb60b9b120b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/455855
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/lsp/fake/workdir.go b/gopls/internal/lsp/fake/workdir.go
index 4c8aa12..faba517 100644
--- a/gopls/internal/lsp/fake/workdir.go
+++ b/gopls/internal/lsp/fake/workdir.go
@@ -221,26 +221,6 @@
return start, err
}
-// ChangeFilesOnDisk executes the given on-disk file changes in a batch,
-// simulating the action of changing branches outside of an editor.
-func (w *Workdir) ChangeFilesOnDisk(ctx context.Context, events []FileEvent) error {
- for _, e := range events {
- switch e.ProtocolEvent.Type {
- case protocol.Deleted:
- fp := w.AbsPath(e.Path)
- if err := os.Remove(fp); err != nil {
- return fmt.Errorf("removing %q: %w", e.Path, err)
- }
- case protocol.Changed, protocol.Created:
- if _, err := w.writeFile(ctx, e.Path, e.Content); err != nil {
- return err
- }
- }
- }
- w.sendEvents(ctx, events)
- return nil
-}
-
// RemoveFile removes a workdir-relative file path.
func (w *Workdir) RemoveFile(ctx context.Context, path string) error {
fp := w.AbsPath(path)
diff --git a/gopls/internal/lsp/regtest/wrappers.go b/gopls/internal/lsp/regtest/wrappers.go
index e2d62e6..7193966 100644
--- a/gopls/internal/lsp/regtest/wrappers.go
+++ b/gopls/internal/lsp/regtest/wrappers.go
@@ -13,13 +13,6 @@
"golang.org/x/tools/gopls/internal/lsp/protocol"
)
-func (e *Env) ChangeFilesOnDisk(events []fake.FileEvent) {
- e.T.Helper()
- if err := e.Sandbox.Workdir.ChangeFilesOnDisk(e.Ctx, events); err != nil {
- e.T.Fatal(err)
- }
-}
-
// RemoveWorkspaceFile deletes a file on disk but does nothing in the
// editor. It calls t.Fatal on any error.
func (e *Env) RemoveWorkspaceFile(name string) {
diff --git a/gopls/internal/regtest/diagnostics/diagnostics_test.go b/gopls/internal/regtest/diagnostics/diagnostics_test.go
index 45bf602..fb858f6 100644
--- a/gopls/internal/regtest/diagnostics/diagnostics_test.go
+++ b/gopls/internal/regtest/diagnostics/diagnostics_test.go
@@ -11,12 +11,11 @@
"testing"
"golang.org/x/tools/gopls/internal/hooks"
- . "golang.org/x/tools/gopls/internal/lsp/regtest"
- "golang.org/x/tools/internal/bug"
-
"golang.org/x/tools/gopls/internal/lsp"
"golang.org/x/tools/gopls/internal/lsp/fake"
"golang.org/x/tools/gopls/internal/lsp/protocol"
+ . "golang.org/x/tools/gopls/internal/lsp/regtest"
+ "golang.org/x/tools/internal/bug"
"golang.org/x/tools/internal/testenv"
)
diff --git a/gopls/internal/regtest/watch/watch_test.go b/gopls/internal/regtest/watch/watch_test.go
index 1be766b..32fe418 100644
--- a/gopls/internal/regtest/watch/watch_test.go
+++ b/gopls/internal/regtest/watch/watch_test.go
@@ -487,39 +487,11 @@
func _() {}
`
Run(t, pkg, func(t *testing.T, env *Env) {
- env.ChangeFilesOnDisk([]fake.FileEvent{
- {
- Path: "a/a3.go",
- Content: `package a
-
-var Hello int
-`,
- ProtocolEvent: protocol.FileEvent{
- URI: env.Sandbox.Workdir.URI("a/a3.go"),
- Type: protocol.Created,
- },
- },
- {
- Path: "a/a1.go",
- ProtocolEvent: protocol.FileEvent{
- URI: env.Sandbox.Workdir.URI("a/a1.go"),
- Type: protocol.Deleted,
- },
- },
- {
- Path: "a/a2.go",
- Content: `package a; func _() {};`,
- ProtocolEvent: protocol.FileEvent{
- URI: env.Sandbox.Workdir.URI("a/a2.go"),
- Type: protocol.Changed,
- },
- },
- })
- env.Await(
- OnceMet(
- env.DoneWithChangeWatchedFiles(),
- NoDiagnostics("main.go"),
- ),
+ env.WriteWorkspaceFile("a/a3.go", "package a\n\nvar Hello int\n")
+ env.RemoveWorkspaceFile("a/a1.go")
+ env.WriteWorkspaceFile("a/a2.go", "package a; func _() {};")
+ env.AfterChange(
+ NoDiagnostics("main.go"),
)
})
}