[tools] go/analysis/passes/inline: add lazy-fix mode for gopls

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Nov 17, 2025, 4:39:03 PM (4 days ago) Nov 17
to Alan Donovan, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Robert Findley, golang-co...@googlegroups.com

Gopher Robot submitted the change with unreviewed changes

Unreviewed changes

2 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: gopls/internal/test/marker/testdata/mcptools/file_diagnostics.txt
Insertions: 3, Deletions: 0.

@@ -3,8 +3,11 @@
Some diagnostics from the "printf" analyzer carry fixes, and those fixes have edits.
(Not all fixes have edits; some analyzers rely on gopls to compute them lazily.)

+The printf analyzer only reports a fix in files using >= go1.24.
+
-- flags --
-mcp
+-min_go_command=go1.24

-- settings.json --
{
```

Change information

Commit message:
go/analysis/passes/inline: add lazy-fix mode for gopls

Computation of inliner fixes can be expensive due to its
(unnecessary) strategy of formatting and parsing the file
repeatedly. Rather than fix that right now, this CL makes
the computation of fixes lazy when the analyzer is running
within gopls. An undocumented analyzer flag, set by gopls'
init, causes the analyzer to return an empty list of edits,
which triggers gopls to compute the edits lazily based on
the Diagnostic.Category string. As luck would have it, we
already have a lazy fix in place for the refactor.inline.call
Code Action, so we simply use that name again for the Category.

The change broke an MCP test that assumed that the inline
analyzer's fixes carry edits. There is a TODO in the
MCP code not to rely on this assumption, but rather than
do it, I rewrote the test to use the printf analyzer
instead.

For golang/go#75773
Change-Id: I5388e472e841cb23351fb9e90d8d7721dae3df07
Auto-Submit: Alan Donovan <adon...@google.com>
Reviewed-by: Robert Findley <rfin...@google.com>
Files:
  • M go/analysis/passes/inline/inline.go
  • M gopls/internal/golang/fix.go
  • M gopls/internal/settings/analysis.go
  • M gopls/internal/test/marker/testdata/mcptools/file_diagnostics.txt
  • M internal/refactor/inline/inline.go
Change size: M
Delta: 5 files changed, 132 insertions(+), 98 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Robert Findley
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I5388e472e841cb23351fb9e90d8d7721dae3df07
Gerrit-Change-Number: 721180
Gerrit-PatchSet: 6
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Robert Findley <rfin...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages