createFixAllAction creates a source.fixAll code action that applies all auto-fixable code fixes across the file.
( ctx context.Context, program *compiler.Program, file *ast.SourceFile, uri lsproto.DocumentUri, )
| 259 | // createFixAllAction creates a source.fixAll code action that applies all auto-fixable |
| 260 | // code fixes across the file. |
| 261 | func (l *LanguageService) createFixAllAction( |
| 262 | ctx context.Context, |
| 263 | program *compiler.Program, |
| 264 | file *ast.SourceFile, |
| 265 | uri lsproto.DocumentUri, |
| 266 | ) (*lsproto.CommandOrCodeAction, error) { |
| 267 | kind := lsproto.CodeActionKindSourceFixAll |
| 268 | lspChanges := make(map[lsproto.DocumentUri][]*lsproto.TextEdit) |
| 269 | |
| 270 | for _, provider := range codeFixProviders { |
| 271 | if provider.GetAllCodeActions == nil { |
| 272 | continue |
| 273 | } |
| 274 | |
| 275 | fixContext := &CodeFixContext{ |
| 276 | SourceFile: file, |
| 277 | Program: program, |
| 278 | LS: l, |
| 279 | } |
| 280 | |
| 281 | combined, err := provider.GetAllCodeActions(ctx, fixContext) |
| 282 | if err != nil { |
| 283 | return nil, err |
| 284 | } |
| 285 | if combined != nil && len(combined.Changes) > 0 { |
| 286 | lspChanges[uri] = append(lspChanges[uri], combined.Changes...) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | if len(lspChanges) == 0 { |
| 291 | return nil, nil |
| 292 | } |
| 293 | |
| 294 | return &lsproto.CommandOrCodeAction{ |
| 295 | CodeAction: &lsproto.CodeAction{ |
| 296 | Title: diagnostics.Fix_All.Localize(locale.FromContext(ctx)), |
| 297 | Kind: &kind, |
| 298 | Edit: &lsproto.WorkspaceEdit{Changes: &lspChanges}, |
| 299 | }, |
| 300 | }, nil |
| 301 | } |
| 302 | |
| 303 | // getOrganizeImportsActionTitle returns the appropriate title for the given organize imports kind |
| 304 | func getOrganizeImportsActionTitle(ctx context.Context, kind lsproto.CodeActionKind) string { |
no test coverage detected