(title: string, action: (...args: any[]) => Promise<void> | void)
| 2 | |
| 3 | // biome-ignore lint/suspicious/noExplicitAny: <explanation> |
| 4 | export const commandWithLoading = async (title: string, action: (...args: any[]) => Promise<void> | void) => { |
| 5 | let hasError = false; |
| 6 | await vscode.window.withProgress( |
| 7 | { |
| 8 | location: vscode.ProgressLocation.Notification, |
| 9 | title: title, |
| 10 | cancellable: false, |
| 11 | }, |
| 12 | async (progress) => { |
| 13 | // Show initial notification |
| 14 | progress.report({ increment: 0, message: "" }); |
| 15 | |
| 16 | // Animate loading state |
| 17 | const loadingFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; |
| 18 | let frameIndex = 0; |
| 19 | |
| 20 | const animateLoading = setInterval(() => { |
| 21 | progress.report({ increment: 0, message: `${loadingFrames[frameIndex]}` }); |
| 22 | frameIndex = (frameIndex + 1) % loadingFrames.length; |
| 23 | }, 50); |
| 24 | |
| 25 | try { |
| 26 | await action(); |
| 27 | } catch (e) { |
| 28 | hasError = true; |
| 29 | } |
| 30 | // Stop the loading animation |
| 31 | clearInterval(animateLoading); |
| 32 | |
| 33 | // Update notification when process is finished |
| 34 | progress.report({ increment: 100, message: "" }); |
| 35 | } |
| 36 | ); |
| 37 | if (!hasError) { |
| 38 | vscode.window.showInformationMessage(`${title} executed.`).then(() => {}); |
| 39 | } |
| 40 | return; |
| 41 | }; |
| 42 | |
| 43 | export const getWorkspaceUri = () => { |
| 44 | const workspaceFolders = vscode.workspace.workspaceFolders; |
no outgoing calls
no test coverage detected