diff --git a/gopls/internal/regtest/diagnostics_test.go b/gopls/internal/regtest/diagnostics_test.go index 8404ea1a3b..18f19c0685 100644 --- a/gopls/internal/regtest/diagnostics_test.go +++ b/gopls/internal/regtest/diagnostics_test.go @@ -1004,7 +1004,7 @@ go 1.12 env.WriteWorkspaceFile(name, "") env.Await(CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1)) - env.OpenFileWithContent(name, "\n") + env.CreateBuffer(name, "\n") env.Await(CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1)) env.EditBuffer(name, fake.NewEdit(1, 0, 1, 0, content)) @@ -1142,7 +1142,7 @@ package main func main() {} ` runner.Run(t, basic, func(t *testing.T, env *Env) { - env.Editor.OpenFileWithContent(env.Ctx, "foo.go", `package main`) + env.Editor.CreateBuffer(env.Ctx, "foo.go", `package main`) env.Await( CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1), ) diff --git a/gopls/internal/regtest/formatting_test.go b/gopls/internal/regtest/formatting_test.go index f0d3afa098..3a9ffdb4b7 100644 --- a/gopls/internal/regtest/formatting_test.go +++ b/gopls/internal/regtest/formatting_test.go @@ -173,7 +173,7 @@ func Hi() { } ` crlf := strings.ReplaceAll(want, "\n", "\r\n") - env.OpenFileWithContent("main.go", crlf) + env.CreateBuffer("main.go", crlf) env.SaveBuffer("main.go") got := env.Editor.BufferText("main.go") if want != got { diff --git a/gopls/internal/regtest/wrappers.go b/gopls/internal/regtest/wrappers.go index 12bb26bfa0..53f79527d8 100644 --- a/gopls/internal/regtest/wrappers.go +++ b/gopls/internal/regtest/wrappers.go @@ -67,13 +67,6 @@ func (e *Env) OpenFile(name string) { } } -func (e *Env) OpenFileWithContent(name, content string) { - e.T.Helper() - if err := e.Editor.OpenFileWithContent(e.Ctx, name, content); err != nil { - e.T.Fatal(err) - } -} - // CreateBuffer creates a buffer in the editor, calling t.Fatal on any error. func (e *Env) CreateBuffer(name string, content string) { e.T.Helper() diff --git a/internal/lsp/fake/editor.go b/internal/lsp/fake/editor.go index 34f68266dc..5567f467be 100644 --- a/internal/lsp/fake/editor.go +++ b/internal/lsp/fake/editor.go @@ -277,26 +277,7 @@ func (e *Editor) OpenFile(ctx context.Context, path string) error { if err != nil { return err } - return e.OpenFileWithContent(ctx, path, content) -} - -// OpenFileWithContent creates a buffer for the given workdir-relative file -// with the given contents. -func (e *Editor) OpenFileWithContent(ctx context.Context, path, content string) error { - buf := newBuffer(path, content) - e.mu.Lock() - e.buffers[path] = buf - item := textDocumentItem(e.sandbox.Workdir, buf) - e.mu.Unlock() - - if e.Server != nil { - if err := e.Server.DidOpen(ctx, &protocol.DidOpenTextDocumentParams{ - TextDocument: item, - }); err != nil { - return errors.Errorf("DidOpen: %w", err) - } - } - return nil + return e.CreateBuffer(ctx, path, content) } func newBuffer(path, content string) buffer {