Skip to content

Commit

Permalink
internal/lsp: remove filename print from rename output
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
ianthehat committed Sep 25, 2019
1 parent 125cfdb commit ae58c0f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
4 changes: 3 additions & 1 deletion internal/lsp/cmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion internal/lsp/lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion internal/lsp/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions internal/lsp/testdata/rename/a/random.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
func sw() {

-- GetSum-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -85,7 +84,6 @@ func sw() {
}

-- f2name-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -151,7 +149,6 @@ func sw() {
}

-- f2y-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -217,7 +214,6 @@ func sw() {
}

-- fmt2-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -284,7 +280,6 @@ func sw() {
default:

-- fmty-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -351,7 +346,6 @@ func sw() {
default:

-- format-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -418,7 +412,6 @@ func sw() {
}

-- log-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -481,7 +474,6 @@ func sw() {
func _() {

-- myX-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -541,7 +533,6 @@ func sw() {
func sw() {

-- pos-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -607,7 +598,6 @@ func sw() {
}

-- y0-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -673,7 +663,6 @@ func sw() {
}

-- y1-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -739,7 +728,6 @@ func sw() {
}

-- y2-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -805,7 +793,6 @@ func sw() {
}

-- y3-rename --
random.go:
package a

import (
Expand Down Expand Up @@ -865,7 +852,6 @@ func sw() {
type Pos struct {

-- z-rename --
random.go:
package a

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/lsp/testdata/rename/testy/testy.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}

-- bar-rename --
testy.go:
package testy

type tt int //@rename("tt", "testyType")
Expand All @@ -32,7 +31,6 @@ func a() {
foo := 42 //@rename("foo", "bar")

-- testyType-rename --
testy.go:
package testy

type testyType int //@rename("tt", "testyType")
Expand Down
1 change: 0 additions & 1 deletion internal/lsp/testdata/rename/testy/testy_test.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func TestSomething(t *testing.T) {
}

-- testyX-rename --
testy_test.go:
package testy

import "testing"
Expand Down

0 comments on commit ae58c0f

Please sign in to comment.