mirror of
https://github.com/golang/go
synced 2024-11-18 19:54:44 -07:00
internal/lsp/cmd: don't create .orig files for rename by default
Fixes golang/go#35551 Change-Id: I78086e0288da84a4c0b008d05e376f47b30d978a Reviewed-on: https://go-review.googlesource.com/c/tools/+/207347 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
11e13f1c3f
commit
6d480e29d4
@ -23,8 +23,9 @@ import (
|
|||||||
|
|
||||||
// rename implements the rename verb for gopls.
|
// rename implements the rename verb for gopls.
|
||||||
type rename struct {
|
type rename struct {
|
||||||
Diff bool `flag:"d" help:"display diffs instead of rewriting files"`
|
Diff bool `flag:"d" help:"display diffs instead of rewriting files"`
|
||||||
Write bool `flag:"w" help:"write result to (source) file instead of stdout"`
|
Write bool `flag:"w" help:"write result to (source) file instead of stdout"`
|
||||||
|
Preserve bool `flag:"preserve" help:"preserve original files"`
|
||||||
|
|
||||||
app *Application
|
app *Application
|
||||||
}
|
}
|
||||||
@ -102,9 +103,10 @@ func (r *rename) Run(ctx context.Context, args ...string) error {
|
|||||||
switch {
|
switch {
|
||||||
case r.Write:
|
case r.Write:
|
||||||
fmt.Fprintln(os.Stderr, filename)
|
fmt.Fprintln(os.Stderr, filename)
|
||||||
err := os.Rename(filename, filename+".orig")
|
if r.Preserve {
|
||||||
if err != nil {
|
if err := os.Rename(filename, filename+".orig"); err != nil {
|
||||||
return errors.Errorf("%v: %v", edits, err)
|
return errors.Errorf("%v: %v", edits, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(filename, []byte(newContent), 0644)
|
ioutil.WriteFile(filename, []byte(newContent), 0644)
|
||||||
case r.Diff:
|
case r.Diff:
|
||||||
|
Loading…
Reference in New Issue
Block a user