Skip to content

fix(vscode): make refresh silent on branch change #2645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/vscode/src/refresh-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
93 changes: 55 additions & 38 deletions libs/vscode/lsp-client/src/nxls-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
commands,
Disposable,
ExtensionContext,
Progress,
ProgressLocation,
window,
} from 'vscode';
Expand Down Expand Up @@ -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<void>((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<void>((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<P, R, E>(
Expand Down Expand Up @@ -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);
}
});
}
Loading