Skip to content

Commit 1871a2e

Browse files
committed
gopls/internal/lsp/source: move Go CodeActions logic from server
This change moves all the logic in server for Go-specific code actions to source.CodeActions. Some symbols are renamed, documented, and unexported. Unexporting several functions caused the brand-new unusedparams analyzer (on whose behalf this work was done) to report unused parameters, allowing further deletions. Yay. No behavior changes. Change-Id: I72b6ca45137a24bf855f3c7418bbe8b26ed0aefa Reviewed-on: https://go-review.googlesource.com/c/tools/+/556818 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent afcd676 commit 1871a2e

File tree

7 files changed

+615
-610
lines changed

7 files changed

+615
-610
lines changed

gopls/internal/lsp/cache/errors.go

-25
Original file line numberDiff line numberDiff line change
@@ -393,31 +393,6 @@ func BuildLink(target, path, anchor string) string {
393393
return link + "#" + anchor
394394
}
395395

396-
// suggestedAnalysisFixes converts edit-based fixes associated
397-
// with a gobDiagnostic to cache.SuggestedFixes.
398-
// It returns the cross product of fixes and kinds.
399-
func suggestedAnalysisFixes(diag *gobDiagnostic, kinds []protocol.CodeActionKind) []SuggestedFix {
400-
var fixes []SuggestedFix
401-
for _, fix := range diag.SuggestedFixes {
402-
edits := make(map[protocol.DocumentURI][]protocol.TextEdit)
403-
for _, e := range fix.TextEdits {
404-
uri := e.Location.URI
405-
edits[uri] = append(edits[uri], protocol.TextEdit{
406-
Range: e.Location.Range,
407-
NewText: string(e.NewText),
408-
})
409-
}
410-
for _, kind := range kinds {
411-
fixes = append(fixes, SuggestedFix{
412-
Title: fix.Message,
413-
Edits: edits,
414-
ActionKind: kind,
415-
})
416-
}
417-
}
418-
return fixes
419-
}
420-
421396
func parseGoListError(e packages.Error, dir string) (filename string, line, col8 int) {
422397
input := e.Pos
423398
if input == "" {

gopls/internal/lsp/source/change_quote.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func ConvertStringLiteral(pgf *ParsedGoFile, fh file.Handle, rng protocol.Range)
7878
Title: title,
7979
Kind: protocol.RefactorRewrite,
8080
Edit: &protocol.WorkspaceEdit{
81-
DocumentChanges: protocol.TextEditsToDocumentChanges(fh.URI(), fh.Version(), pedits),
81+
DocumentChanges: documentChanges(fh, pedits),
8282
},
8383
}, true
8484
}

gopls/internal/lsp/source/change_signature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func RemoveUnusedParameter(ctx context.Context, fh file.Handle, rng protocol.Ran
170170
if err != nil {
171171
return nil, fmt.Errorf("computing edits for %s: %v", uri, err)
172172
}
173-
changes = append(changes, protocol.TextEditsToDocumentChanges(fh.URI(), fh.Version(), pedits)...)
173+
changes = append(changes, documentChanges(fh, pedits)...)
174174
}
175175
return changes, nil
176176
}

0 commit comments

Comments
 (0)