@@ -6,9 +6,7 @@ package source
6
6
7
7
import (
8
8
"context"
9
- "encoding/json"
10
9
11
- "golang.org/x/tools/gopls/internal/bug"
12
10
"golang.org/x/tools/gopls/internal/lsp/progress"
13
11
"golang.org/x/tools/gopls/internal/lsp/protocol"
14
12
"golang.org/x/tools/gopls/internal/settings"
@@ -107,81 +105,3 @@ func CombineDiagnostics(tdiags []*Diagnostic, adiags []*Diagnostic, outT, outA *
107
105
108
106
* outT = append (* outT , tdiags ... )
109
107
}
110
-
111
- // quickFixesJSON is a JSON-serializable list of quick fixes
112
- // to be saved in the protocol.Diagnostic.Data field.
113
- type quickFixesJSON struct {
114
- // TODO(rfindley): pack some sort of identifier here for later
115
- // lookup/validation?
116
- Fixes []protocol.CodeAction
117
- }
118
-
119
- // BundleQuickFixes attempts to bundle sd.SuggestedFixes into the
120
- // sd.BundledFixes field, so that it can be round-tripped through the client.
121
- // It returns false if the quick-fixes cannot be bundled.
122
- func BundleQuickFixes (sd * Diagnostic ) bool {
123
- if len (sd .SuggestedFixes ) == 0 {
124
- return true
125
- }
126
- var actions []protocol.CodeAction
127
- for _ , fix := range sd .SuggestedFixes {
128
- if fix .Edits != nil {
129
- // For now, we only support bundled code actions that execute commands.
130
- //
131
- // In order to cleanly support bundled edits, we'd have to guarantee that
132
- // the edits were generated on the current snapshot. But this naively
133
- // implies that every fix would have to include a snapshot ID, which
134
- // would require us to republish all diagnostics on each new snapshot.
135
- //
136
- // TODO(rfindley): in order to avoid this additional chatter, we'd need
137
- // to build some sort of registry or other mechanism on the snapshot to
138
- // check whether a diagnostic is still valid.
139
- return false
140
- }
141
- action := protocol.CodeAction {
142
- Title : fix .Title ,
143
- Kind : fix .ActionKind ,
144
- Command : fix .Command ,
145
- }
146
- actions = append (actions , action )
147
- }
148
- fixes := quickFixesJSON {
149
- Fixes : actions ,
150
- }
151
- data , err := json .Marshal (fixes )
152
- if err != nil {
153
- bug .Reportf ("marshalling quick fixes: %v" , err )
154
- return false
155
- }
156
- msg := json .RawMessage (data )
157
- sd .BundledFixes = & msg
158
- return true
159
- }
160
-
161
- // BundledQuickFixes extracts any bundled codeActions from the
162
- // diag.Data field.
163
- func BundledQuickFixes (diag protocol.Diagnostic ) []protocol.CodeAction {
164
- if diag .Data == nil {
165
- return nil
166
- }
167
- var fix quickFixesJSON
168
- if err := json .Unmarshal (* diag .Data , & fix ); err != nil {
169
- bug .Reportf ("unmarshalling quick fix: %v" , err )
170
- return nil
171
- }
172
-
173
- var actions []protocol.CodeAction
174
- for _ , action := range fix .Fixes {
175
- // See BundleQuickFixes: for now we only support bundling commands.
176
- if action .Edit != nil {
177
- bug .Reportf ("bundled fix %q includes workspace edits" , action .Title )
178
- continue
179
- }
180
- // associate the action with the incoming diagnostic
181
- // (Note that this does not mutate the fix.Fixes slice).
182
- action .Diagnostics = []protocol.Diagnostic {diag }
183
- actions = append (actions , action )
184
- }
185
-
186
- return actions
187
- }
0 commit comments