* Apply a code action following the LSP spec: * "If both edit and command are supplied, first the edit is applied, then the command is executed"
( view: EditorView, action: CodeAction, )
| 248 | * "If both edit and command are supplied, first the edit is applied, then the command is executed" |
| 249 | */ |
| 250 | async function applyCodeAction( |
| 251 | view: EditorView, |
| 252 | action: CodeAction, |
| 253 | ): Promise<boolean> { |
| 254 | const plugin = LSPPlugin.get(view); |
| 255 | if (!plugin) return false; |
| 256 | |
| 257 | plugin.client.sync(); |
| 258 | |
| 259 | // Resolve to get the edit if not already present |
| 260 | const resolved = await resolveCodeAction(plugin, action); |
| 261 | let success = false; |
| 262 | |
| 263 | // Step 1: Apply workspace edit if present |
| 264 | if (resolved.edit) { |
| 265 | success = await applyWorkspaceEdit(view, resolved.edit); |
| 266 | } |
| 267 | |
| 268 | // Step 2: Execute command if present (after edit per LSP spec) |
| 269 | if (resolved.command) { |
| 270 | const commandSuccess = await executeCommand(plugin, resolved.command); |
| 271 | success = success || commandSuccess; |
| 272 | } |
| 273 | |
| 274 | plugin.client.sync(); |
| 275 | return success; |
| 276 | } |
| 277 | |
| 278 | export interface CodeActionItem { |
| 279 | title: string; |
no test coverage detected