Skip to content

Commit 3c677e3

Browse files
committed
gopls/internal/lsp/cache: move SuggestedFixFromCommand into cache
Change-Id: Id468b7b2749bae70430bcde70a1d3c5ceaaa92f8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/543919 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent ab6af7d commit 3c677e3

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cache
6+
7+
import "golang.org/x/tools/gopls/internal/lsp/protocol"
8+
9+
// SuggestedFixFromCommand returns a suggested fix to run the given command.
10+
func SuggestedFixFromCommand(cmd protocol.Command, kind protocol.CodeActionKind) SuggestedFix {
11+
return SuggestedFix{
12+
Title: cmd.Title,
13+
Command: &cmd,
14+
ActionKind: kind,
15+
}
16+
}

gopls/internal/lsp/cache/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func goGetQuickFixes(moduleMode bool, uri protocol.DocumentURI, pkg string) ([]s
198198
if err != nil {
199199
return nil, err
200200
}
201-
return []source.SuggestedFix{source.SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
201+
return []source.SuggestedFix{SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
202202
}
203203

204204
func editGoDirectiveQuickFix(moduleMode bool, uri protocol.DocumentURI, version string) ([]source.SuggestedFix, error) {
@@ -214,7 +214,7 @@ func editGoDirectiveQuickFix(moduleMode bool, uri protocol.DocumentURI, version
214214
if err != nil {
215215
return nil, err
216216
}
217-
return []source.SuggestedFix{source.SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
217+
return []source.SuggestedFix{SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
218218
}
219219

220220
// encodeDiagnostics gob-encodes the given diagnostics.
@@ -366,7 +366,7 @@ func toSourceDiagnostic(srcAnalyzer *settings.Analyzer, gobDiag *gobDiagnostic)
366366
log.Fatalf("internal error in NewApplyFixCommand: %v", err)
367367
}
368368
for _, kind := range kinds {
369-
fixes = append(fixes, source.SuggestedFixFromCommand(cmd, kind))
369+
fixes = append(fixes, SuggestedFixFromCommand(cmd, kind))
370370
}
371371
}
372372
diag.SuggestedFixes = fixes

gopls/internal/lsp/cache/pkg.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ var (
7575
RemoveIntermediateTestVariants = source.RemoveIntermediateTestVariants
7676
IsCommandLineArguments = source.IsCommandLineArguments
7777
BundleQuickFixes = source.BundleQuickFixes
78-
SuggestedFixFromCommand = source.SuggestedFixFromCommand
7978
ToProtocolEdits = source.ToProtocolEdits
8079
NewFilterer = source.NewFilterer
8180
)

gopls/internal/lsp/mod/diagnostics.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func ModUpgradeDiagnostics(ctx context.Context, snapshot *cache.Snapshot, fh fil
173173
Severity: protocol.SeverityInformation,
174174
Source: source.UpgradeNotification,
175175
Message: fmt.Sprintf("%v can be upgraded", req.Mod.Path),
176-
SuggestedFixes: []source.SuggestedFix{source.SuggestedFixFromCommand(cmd, protocol.QuickFix)},
176+
SuggestedFixes: []source.SuggestedFix{cache.SuggestedFixFromCommand(cmd, protocol.QuickFix)},
177177
})
178178
}
179179

@@ -274,7 +274,7 @@ func ModVulnerabilityDiagnostics(ctx context.Context, snapshot *cache.Snapshot,
274274
if err != nil {
275275
return nil, err // TODO: bug report
276276
}
277-
sf := source.SuggestedFixFromCommand(cmd, protocol.QuickFix)
277+
sf := cache.SuggestedFixFromCommand(cmd, protocol.QuickFix)
278278
switch _, typ := foundVuln(finding); typ {
279279
case vulnImported:
280280
infoFixes = append(infoFixes, sf)
@@ -301,7 +301,7 @@ func ModVulnerabilityDiagnostics(ctx context.Context, snapshot *cache.Snapshot,
301301
if err != nil {
302302
return nil, err // TODO: bug report
303303
}
304-
sf := source.SuggestedFixFromCommand(latest, protocol.QuickFix)
304+
sf := cache.SuggestedFixFromCommand(latest, protocol.QuickFix)
305305
if len(warningFixes) > 0 {
306306
warningFixes = append(warningFixes, sf)
307307
}
@@ -454,7 +454,7 @@ func suggestGovulncheckAction(fromGovulncheck bool, uri protocol.DocumentURI) (s
454454
if err != nil {
455455
return source.SuggestedFix{}, err
456456
}
457-
return source.SuggestedFixFromCommand(resetVulncheck, protocol.QuickFix), nil
457+
return cache.SuggestedFixFromCommand(resetVulncheck, protocol.QuickFix), nil
458458
}
459459
vulncheck, err := command.NewRunGovulncheckCommand("Run govulncheck to verify", command.VulncheckArgs{
460460
URI: uri,
@@ -463,7 +463,7 @@ func suggestGovulncheckAction(fromGovulncheck bool, uri protocol.DocumentURI) (s
463463
if err != nil {
464464
return source.SuggestedFix{}, err
465465
}
466-
return source.SuggestedFixFromCommand(vulncheck, protocol.QuickFix), nil
466+
return cache.SuggestedFixFromCommand(vulncheck, protocol.QuickFix), nil
467467
}
468468

469469
func getVulnMessage(mod string, vulns []string, used, fromGovulncheck bool) string {

gopls/internal/lsp/source/fix.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ func singleFile(sf singleFileFixFunc) suggestedFixFunc {
9494
}
9595
}
9696

97-
func SuggestedFixFromCommand(cmd protocol.Command, kind protocol.CodeActionKind) SuggestedFix {
98-
return SuggestedFix{
99-
Title: cmd.Title,
100-
Command: &cmd,
101-
ActionKind: kind,
102-
}
103-
}
104-
10597
// CanFix returns true if Analyzer.Fix can fix the Diagnostic.
10698
//
10799
// It returns true by default: only if the analyzer is configured explicitly to

0 commit comments

Comments
 (0)