mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
internal/lsp/regtest: consolidate Env wrappers
Helper functions on the regtest.Env wrapping workspace or editor functionality are moved to a new wrappers.go file. Also, rename 'WriteBuffer' to 'SaveBuffer', for less confusion with 'WriteFile'. Change-Id: Ide9a5cf919dcee6e4a4fbfdb167eddf751a26eeb Reviewed-on: https://go-review.googlesource.com/c/tools/+/221538 Reviewed-by: Rohan Challa <rohan@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
b1e4e04173
commit
9aa23abf06
@ -232,9 +232,9 @@ func (e *Editor) CloseBuffer(ctx context.Context, path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteBuffer writes the content of the buffer specified by the given path to
|
||||
// SaveBuffer writes the content of the buffer specified by the given path to
|
||||
// the filesystem.
|
||||
func (e *Editor) WriteBuffer(ctx context.Context, path string) error {
|
||||
func (e *Editor) SaveBuffer(ctx context.Context, path string) error {
|
||||
e.mu.Lock()
|
||||
buf, ok := e.buffers[path]
|
||||
if !ok {
|
||||
|
@ -273,58 +273,6 @@ func NewEnv(ctx context.Context, t *testing.T, ws *fake.Workspace, ts servertest
|
||||
return env
|
||||
}
|
||||
|
||||
// RemoveFileFromWorkspace deletes a file on disk but does nothing in the
|
||||
// editor. It calls t.Fatal on any error.
|
||||
func (e *Env) RemoveFileFromWorkspace(name string) {
|
||||
e.t.Helper()
|
||||
if err := e.W.RemoveFile(e.ctx, name); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenFile opens a file in the editor, calling t.Fatal on any error.
|
||||
func (e *Env) OpenFile(name string) {
|
||||
e.t.Helper()
|
||||
if err := e.E.OpenFile(e.ctx, name); 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()
|
||||
if err := e.E.CreateBuffer(e.ctx, name, content); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// CloseBuffer closes an editor buffer, calling t.Fatal on any error.
|
||||
func (e *Env) CloseBuffer(name string) {
|
||||
e.t.Helper()
|
||||
if err := e.E.CloseBuffer(e.ctx, name); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// EditBuffer applies edits to an editor buffer, calling t.Fatal on any error.
|
||||
func (e *Env) EditBuffer(name string, edits ...fake.Edit) {
|
||||
e.t.Helper()
|
||||
if err := e.E.EditBuffer(e.ctx, name, edits); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// GoToDefinition goes to definition in the editor, calling t.Fatal on any
|
||||
// error.
|
||||
func (e *Env) GoToDefinition(name string, pos fake.Pos) (string, fake.Pos) {
|
||||
e.t.Helper()
|
||||
n, p, err := e.E.GoToDefinition(e.ctx, name, pos)
|
||||
if err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
return n, p
|
||||
}
|
||||
|
||||
func (e *Env) onDiagnostics(_ context.Context, d *protocol.PublishDiagnosticsParams) error {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
@ -341,17 +289,6 @@ func (e *Env) onDiagnostics(_ context.Context, d *protocol.PublishDiagnosticsPar
|
||||
return nil
|
||||
}
|
||||
|
||||
// CloseEditor shuts down the editor, calling t.Fatal on any error.
|
||||
func (e *Env) CloseEditor() {
|
||||
e.t.Helper()
|
||||
if err := e.E.Shutdown(e.ctx); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
if err := e.E.Exit(e.ctx); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func meetsCondition(m map[string]*protocol.PublishDiagnosticsParams, expectations []DiagnosticExpectation) bool {
|
||||
for _, e := range expectations {
|
||||
if !e.IsMet(m) {
|
||||
|
79
internal/lsp/regtest/wrappers.go
Normal file
79
internal/lsp/regtest/wrappers.go
Normal file
@ -0,0 +1,79 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package regtest
|
||||
|
||||
import "golang.org/x/tools/internal/lsp/fake"
|
||||
|
||||
// RemoveFileFromWorkspace deletes a file on disk but does nothing in the
|
||||
// editor. It calls t.Fatal on any error.
|
||||
func (e *Env) RemoveFileFromWorkspace(name string) {
|
||||
e.t.Helper()
|
||||
if err := e.W.RemoveFile(e.ctx, name); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenFile opens a file in the editor, calling t.Fatal on any error.
|
||||
func (e *Env) OpenFile(name string) {
|
||||
e.t.Helper()
|
||||
if err := e.E.OpenFile(e.ctx, name); 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()
|
||||
if err := e.E.CreateBuffer(e.ctx, name, content); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// CloseBuffer closes an editor buffer without saving, calling t.Fatal on any
|
||||
// error.
|
||||
func (e *Env) CloseBuffer(name string) {
|
||||
e.t.Helper()
|
||||
if err := e.E.CloseBuffer(e.ctx, name); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// EditBuffer applies edits to an editor buffer, calling t.Fatal on any error.
|
||||
func (e *Env) EditBuffer(name string, edits ...fake.Edit) {
|
||||
e.t.Helper()
|
||||
if err := e.E.EditBuffer(e.ctx, name, edits); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// SaveBuffer saves an editor buffer, calling t.Fatal on any error.
|
||||
func (e *Env) SaveBuffer(name string) {
|
||||
e.t.Helper()
|
||||
if err := e.E.SaveBuffer(e.ctx, name); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// GoToDefinition goes to definition in the editor, calling t.Fatal on any
|
||||
// error.
|
||||
func (e *Env) GoToDefinition(name string, pos fake.Pos) (string, fake.Pos) {
|
||||
e.t.Helper()
|
||||
n, p, err := e.E.GoToDefinition(e.ctx, name, pos)
|
||||
if err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
return n, p
|
||||
}
|
||||
|
||||
// CloseEditor shuts down the editor, calling t.Fatal on any error.
|
||||
func (e *Env) CloseEditor() {
|
||||
e.t.Helper()
|
||||
if err := e.E.Shutdown(e.ctx); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
if err := e.E.Exit(e.ctx); err != nil {
|
||||
e.t.Fatal(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user