(view: EditorView)
| 370 | } |
| 371 | |
| 372 | export async function showCodeActionsMenu(view: EditorView): Promise<boolean> { |
| 373 | if (!supportsCodeActions(view)) return false; |
| 374 | |
| 375 | const items = await fetchCodeActions(view); |
| 376 | if (!items.length) { |
| 377 | toast("No code actions available"); |
| 378 | return false; |
| 379 | } |
| 380 | |
| 381 | const selectItems = items.map((item, i) => ({ |
| 382 | value: String(i), |
| 383 | text: item.title, |
| 384 | icon: item.icon, |
| 385 | disabled: item.disabled, |
| 386 | })); |
| 387 | |
| 388 | try { |
| 389 | const result = await select( |
| 390 | strings["code actions"] || "Code Actions", |
| 391 | selectItems as unknown as string[], |
| 392 | { hideOnSelect: true }, |
| 393 | ); |
| 394 | |
| 395 | if (result !== null && result !== undefined) { |
| 396 | const index = Number.parseInt(String(result), 10); |
| 397 | if (!Number.isNaN(index) && index >= 0 && index < items.length) { |
| 398 | await executeCodeAction(view, items[index]); |
| 399 | view.focus(); |
| 400 | return true; |
| 401 | } |
| 402 | } |
| 403 | } catch { |
| 404 | // User cancelled selection |
| 405 | } |
| 406 | |
| 407 | view.focus(); |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | export async function performQuickFix(view: EditorView): Promise<boolean> { |
| 412 | const items = await fetchCodeActions(view); |
no test coverage detected