tools/internal/tool
Alan Donovan cb85f8f57e gopls/internal/lsp/cmd: consolidate editing flags
Four operations (rename, fix, imports, format) apply
edits to the client's files. This change causes them
to behave the same w.r.t. the -write, -diff,
-preserve, and -list flags.

Specifically, the default behavior prints the edited
file contents (sans filename or newline).
The -write, -diff, and -list flags suppress the
default behavior but are otherwise orthogonal.
The -preserve flag causes -write to save backups.
(These semantics were based on the previous behavior
of 'format', which I suspect is the most important
of the subcommands by usage.)

Also:
- clarify the documentation of the fix operation,
  including examples of cases that now work, such
  as InvalidIfaceAssign (see the attached issue).
- support CodeAction edit commands, which may cause
  the server to make an ApplyEdit downcall. ApplyEdit
  is handled using the same logic and flags as the
  client-initiated edits.
- handle various discarded errors properly.
- remove unnecessary Contexts.
- add tests.

Note: this CL changes the behavior of the rename
and imports commands when multiple flags are provided.
Before, flags had precedence -w > -d > default.
Now, the -w -d -l flags are orthogonal and only if
none are provided is the changed output printed.
Also, the rename operation no longer prints the
name of each changed file.

Updates golang/go#60290

Change-Id: If986267ca4365e95f379d8243de6f302f7e756c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/497756
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-01 13:22:27 +00:00
..
tool.go gopls/internal/lsp/cmd: consolidate editing flags 2023-09-01 13:22:27 +00:00