diff --git a/apps/vscode/src/refresh-workspace.ts b/apps/vscode/src/refresh-workspace.ts index eae339992b..6c95d4c0f3 100644 --- a/apps/vscode/src/refresh-workspace.ts +++ b/apps/vscode/src/refresh-workspace.ts @@ -11,7 +11,7 @@ let isRefreshing = false; export function registerRefreshWorkspace(context: ExtensionContext) { context.subscriptions.push( - commands.registerCommand(REFRESH_WORKSPACE, async () => { + commands.registerCommand(REFRESH_WORKSPACE, async (silent = false) => { if (isRefreshing) { return; } @@ -21,7 +21,7 @@ export function registerRefreshWorkspace(context: ExtensionContext) { getTelemetry().logUsage('misc.refresh-workspace'); try { - await getNxlsClient().refreshWorkspace(); + await getNxlsClient().refreshWorkspace(silent); await getNxGraphServer(context).restart(); refreshMcp(); } catch (e) { diff --git a/libs/vscode/lsp-client/src/nxls-client.ts b/libs/vscode/lsp-client/src/nxls-client.ts index dbcd284acd..3ecc2ef001 100644 --- a/libs/vscode/lsp-client/src/nxls-client.ts +++ b/libs/vscode/lsp-client/src/nxls-client.ts @@ -20,6 +20,7 @@ import { commands, Disposable, ExtensionContext, + Progress, ProgressLocation, window, } from 'vscode'; @@ -115,51 +116,67 @@ export class NxlsClient { this.actor.send({ type: 'STOP' }); } - public async refreshWorkspace() { - await window.withProgress( - { - location: ProgressLocation.Notification, - title: 'Refreshing Workspace', - cancellable: false, - }, - async (progress) => { - try { - if (this.actor.getSnapshot().matches('running')) { + public async refreshWorkspace(silent = false) { + const refreshLogic = async ( + progress?: Progress<{ message?: string; increment?: number }>, + ) => { + try { + if (this.actor.getSnapshot().matches('running')) { + if (progress) { progress.report({ message: 'Stopping nx daemon', increment: 10 }); - try { - await this.sendRequest(NxStopDaemonRequest, undefined); - } catch (e) { - // errors while stopping the daemon aren't critical - } - - this.stop(); } + try { + await this.sendRequest(NxStopDaemonRequest, undefined); + } catch (e) { + // errors while stopping the daemon aren't critical + } + + this.stop(); + } + if (progress) { progress.report({ increment: 30 }); + } + if (progress) { progress.report({ message: 'Restarting language server' }); - await waitFor(this.actor, (snapshot) => snapshot.matches('idle')); - this.start(); + } + await waitFor(this.actor, (snapshot) => snapshot.matches('idle')); + this.start(); + if (progress) { progress.report({ message: 'Refreshing workspace', increment: 30 }); + } - await this.sendNotification(NxWorkspaceRefreshNotification); - - await new Promise((resolve) => { - const disposable = this.onNotification( - NxWorkspaceRefreshNotification, - () => { - disposable.dispose(); - resolve(); - }, - ); - }); - } catch (error) { - logAndShowError( - "Couldn't refresh workspace. Please view the logs for more information.", - error, + await this.sendNotification(NxWorkspaceRefreshNotification); + + await new Promise((resolve) => { + const disposable = this.onNotification( + NxWorkspaceRefreshNotification, + () => { + disposable.dispose(); + resolve(); + }, ); - } - }, - ); + }); + } catch (error) { + logAndShowError( + "Couldn't refresh workspace. Please view the logs for more information.", + error, + ); + } + }; + + if (silent) { + await refreshLogic(); + } else { + await window.withProgress( + { + location: ProgressLocation.Notification, + title: 'Refreshing Workspace', + cancellable: false, + }, + refreshLogic, + ); + } } public async sendRequest( @@ -393,7 +410,7 @@ function refreshWorkspaceOnBranchChange( `Branch changed from ${branch} to ${newBranch}, refreshing workspace`, ); branch = newBranch; - commands.executeCommand('nxConsole.refreshWorkspace'); + commands.executeCommand('nxConsole.refreshWorkspace', true); } }); }