Skip to content

Commit b4a7b92

Browse files
findleyrdennypenta
authored andcommitted
gopls/internal/cache: failure to extract diagnostic fixes is an error
Although the LSP specifies that diagnostic data should be transmitted unmodified to codeAction requests, we can't control whether clients abide by this rule. Therefore, a failure to extract fixes should be treated as a user-facing error, not a bug. Fixes golang/go#68819 Change-Id: I57e629cf381ee1112d98d22e728449995679b05f Reviewed-on: https://go-review.googlesource.com/c/tools/+/628237 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent e7e32d7 commit b4a7b92

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

gopls/internal/cache/diagnostics.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,26 @@ func bundleLazyFixes(sd *Diagnostic) bool {
191191

192192
// BundledLazyFixes extracts any bundled codeActions from the
193193
// diag.Data field.
194-
func BundledLazyFixes(diag protocol.Diagnostic) []protocol.CodeAction {
194+
func BundledLazyFixes(diag protocol.Diagnostic) ([]protocol.CodeAction, error) {
195195
var fix lazyFixesJSON
196196
if diag.Data != nil {
197197
err := protocol.UnmarshalJSON(*diag.Data, &fix)
198198
if err != nil {
199-
bug.Reportf("unmarshalling lazy fix: %v", err)
200-
return nil
199+
return nil, fmt.Errorf("unmarshalling fix from diagnostic data: %v", err)
201200
}
202201
}
203202

204203
var actions []protocol.CodeAction
205204
for _, action := range fix.Actions {
206205
// See bundleLazyFixes: for now we only support bundling commands.
207206
if action.Edit != nil {
208-
bug.Reportf("bundled fix %q includes workspace edits", action.Title)
209-
continue
207+
return nil, fmt.Errorf("bundled fix %q includes workspace edits", action.Title)
210208
}
211209
// associate the action with the incoming diagnostic
212210
// (Note that this does not mutate the fix.Fixes slice).
213211
action.Diagnostics = []protocol.Diagnostic{diag}
214212
actions = append(actions, action)
215213
}
216214

217-
return actions
215+
return actions, nil
218216
}

gopls/internal/server/code_action.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ func (s *server) codeActionsMatchingDiagnostics(ctx context.Context, uri protoco
265265
var actions []protocol.CodeAction
266266
var unbundled []protocol.Diagnostic // diagnostics without bundled code actions in their Data field
267267
for _, pd := range pds {
268-
bundled := cache.BundledLazyFixes(pd)
268+
bundled, err := cache.BundledLazyFixes(pd)
269+
if err != nil {
270+
return nil, err
271+
}
269272
if len(bundled) > 0 {
270273
for _, fix := range bundled {
271274
if enabled(fix.Kind) {

0 commit comments

Comments
 (0)