1
0
mirror of https://github.com/golang/go synced 2024-11-18 21:24:44 -07:00
go/internal/lsp/cmd/test/prepare_rename.go
Rohan Verma 1cc6d1ef6c tools/gopls: add cmd support for prepare_rename
This change adds command line support for prepare_rename.

Updates golang/go#32875

Change-Id: I7f155b9c8329c0faa26a320abab162730a7916ad
GitHub-Last-Rev: 118e846420d7c56fbf0e4f416c8fd6a52e9638a8
GitHub-Pull-Request: golang/tools#188
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207579
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-04 07:42:04 +00:00

46 lines
1.1 KiB
Go

// Copyright 2019 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 cmdtest
import (
"fmt"
"testing"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/span"
)
func (r *runner) PrepareRename(t *testing.T, src span.Span, want *source.PrepareItem) {
m, err := r.data.Mapper(src.URI())
if err != nil {
t.Errorf("prepare_rename failed: %v", err)
}
var (
target = fmt.Sprintf("%v", src)
args = []string{"prepare_rename", target}
stdOut, stdErr = r.NormalizeGoplsCmd(t, args...)
expect string
)
if want.Text == "" {
if stdErr != "" {
t.Errorf("prepare_rename failed for %s,\nexpected:\n`%v`\ngot:\n`%v`", target, expect, stdErr)
}
return
}
ws, err := m.Span(protocol.Location{Range: want.Range})
if err != nil {
t.Errorf("prepare_rename failed: %v", err)
}
expect = r.Normalize(fmt.Sprintln(ws))
if expect != stdOut {
t.Errorf("prepare_rename failed for %s expected:\n`%s`\ngot:\n`%s`\n", target, expect, stdOut)
}
}