MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getFixAllQuickFixes

Method getFixAllQuickFixes

internal/ls/codeactions.go:162–212  ·  view source on GitHub ↗

getFixAllQuickFixes returns per-provider "Fix all in file" quickfix entries for providers that matched at least 2 diagnostics in the full file.

(
	ctx context.Context,
	program *compiler.Program,
	file *ast.SourceFile,
	uri lsproto.DocumentUri,
	fixIdSeen map[string]*CodeFixProvider,
)

Source from the content-addressed store, hash-verified

160// getFixAllQuickFixes returns per-provider "Fix all in file" quickfix entries for providers
161// that matched at least 2 diagnostics in the full file.
162func (l *LanguageService) getFixAllQuickFixes(
163 ctx context.Context,
164 program *compiler.Program,
165 file *ast.SourceFile,
166 uri lsproto.DocumentUri,
167 fixIdSeen map[string]*CodeFixProvider,
168) ([]lsproto.CommandOrCodeAction, error) {
169 var actions []lsproto.CommandOrCodeAction
170
171 // Deduplicate providers; multiple fixIds may map to the same provider.
172 var seen collections.Set[*CodeFixProvider]
173 for _, provider := range fixIdSeen {
174 if seen.Has(provider) {
175 continue
176 }
177 seen.Add(provider)
178
179 if provider.GetAllCodeActions == nil {
180 continue
181 }
182
183 if !hasMultipleFixableDiagnostics(ctx, program, file, provider.ErrorCodes) {
184 continue
185 }
186
187 fixContext := &CodeFixContext{
188 SourceFile: file,
189 Program: program,
190 LS: l,
191 }
192 combined, err := provider.GetAllCodeActions(ctx, fixContext)
193 if err != nil {
194 return nil, err
195 }
196 if combined != nil && len(combined.Changes) > 0 {
197 kind := lsproto.CodeActionKindQuickFix
198 changes := map[lsproto.DocumentUri][]*lsproto.TextEdit{
199 uri: combined.Changes,
200 }
201 actions = append(actions, lsproto.CommandOrCodeAction{
202 CodeAction: &lsproto.CodeAction{
203 Title: combined.Description,
204 Kind: &kind,
205 Edit: &lsproto.WorkspaceEdit{Changes: &changes},
206 },
207 })
208 }
209 }
210
211 return actions, nil
212}
213
214// hasMultipleFixableDiagnostics returns true if the file has at least 2 diagnostics
215// matching the given error codes. Checks all diagnostic sources (semantic,

Callers 1

ProvideCodeActionsMethod · 0.95

Calls 5

lenFunction · 0.85
AddMethod · 0.65
appendFunction · 0.50
HasMethod · 0.45

Tested by

no test coverage detected