1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07:00

internal/lsp: remove filename print from rename output

This prevents piping back to the file, a common pattern.
Multi file forms should use the unified diff.

Change-Id: I1ea140c59de24feb74a64b0cb41890536f23cd3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197157
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Ian Cottrell 2019-09-24 17:04:33 -04:00
parent 125cfdbd7b
commit ae58c0ff6b
6 changed files with 11 additions and 20 deletions

View File

@ -117,7 +117,9 @@ func (r *rename) Run(ctx context.Context, args ...string) error {
diffs := diff.ToUnified(filename+".orig", filename, string(cmdFile.mapper.Content), myersEdits)
fmt.Print(diffs)
default:
fmt.Printf("%s:\n", filepath.Base(filename))
if len(keys) > 1 {
fmt.Printf("%s:\n", filepath.Base(filename))
}
fmt.Print(string(newContent))
if changeCount > 1 { // if this wasn't last change, print newline
fmt.Println()

View File

@ -564,7 +564,10 @@ func (r *runner) Rename(t *testing.T, data tests.Renames) {
}
filename := filepath.Base(m.URI.Filename())
contents := applyEdits(string(m.Content), sedits)
res = append(res, fmt.Sprintf("%s:\n%s", filename, contents))
if len(*workspaceEdits.Changes) > 1 {
contents = fmt.Sprintf("%s:\n%s", filename, contents)
}
res = append(res, contents)
}
// Sort on filename

View File

@ -687,7 +687,10 @@ func (r *runner) Rename(t *testing.T, data tests.Renames) {
t.Fatal(err)
}
contents := applyEdits(string(data), diffEdits)
res = append(res, fmt.Sprintf("%s:\n%s", filename, contents))
if len(changes) > 1 {
contents = fmt.Sprintf("%s:\n%s", filename, contents)
}
res = append(res, contents)
}
// Sort on filename

View File

@ -19,7 +19,6 @@
func sw() {
-- GetSum-rename --
random.go:
package a
import (
@ -85,7 +84,6 @@ func sw() {
}
-- f2name-rename --
random.go:
package a
import (
@ -151,7 +149,6 @@ func sw() {
}
-- f2y-rename --
random.go:
package a
import (
@ -217,7 +214,6 @@ func sw() {
}
-- fmt2-rename --
random.go:
package a
import (
@ -284,7 +280,6 @@ func sw() {
default:
-- fmty-rename --
random.go:
package a
import (
@ -351,7 +346,6 @@ func sw() {
default:
-- format-rename --
random.go:
package a
import (
@ -418,7 +412,6 @@ func sw() {
}
-- log-rename --
random.go:
package a
import (
@ -481,7 +474,6 @@ func sw() {
func _() {
-- myX-rename --
random.go:
package a
import (
@ -541,7 +533,6 @@ func sw() {
func sw() {
-- pos-rename --
random.go:
package a
import (
@ -607,7 +598,6 @@ func sw() {
}
-- y0-rename --
random.go:
package a
import (
@ -673,7 +663,6 @@ func sw() {
}
-- y1-rename --
random.go:
package a
import (
@ -739,7 +728,6 @@ func sw() {
}
-- y2-rename --
random.go:
package a
import (
@ -805,7 +793,6 @@ func sw() {
}
-- y3-rename --
random.go:
package a
import (
@ -865,7 +852,6 @@ func sw() {
type Pos struct {
-- z-rename --
random.go:
package a
import (

View File

@ -10,7 +10,6 @@
}
-- bar-rename --
testy.go:
package testy
type tt int //@rename("tt", "testyType")
@ -32,7 +31,6 @@ func a() {
foo := 42 //@rename("foo", "bar")
-- testyType-rename --
testy.go:
package testy
type testyType int //@rename("tt", "testyType")

View File

@ -52,7 +52,6 @@ func TestSomething(t *testing.T) {
}
-- testyX-rename --
testy_test.go:
package testy
import "testing"