Skip to content

Commit 8f85261

Browse files
committed
fix(vscode): make refresh silent on branch change
1 parent 1707e70 commit 8f85261

File tree

2 files changed

+57
-40
lines changed

2 files changed

+57
-40
lines changed

apps/vscode/src/refresh-workspace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let isRefreshing = false;
1111

1212
export function registerRefreshWorkspace(context: ExtensionContext) {
1313
context.subscriptions.push(
14-
commands.registerCommand(REFRESH_WORKSPACE, async () => {
14+
commands.registerCommand(REFRESH_WORKSPACE, async (silent = false) => {
1515
if (isRefreshing) {
1616
return;
1717
}
@@ -21,7 +21,7 @@ export function registerRefreshWorkspace(context: ExtensionContext) {
2121
getTelemetry().logUsage('misc.refresh-workspace');
2222

2323
try {
24-
await getNxlsClient().refreshWorkspace();
24+
await getNxlsClient().refreshWorkspace(silent);
2525
await getNxGraphServer(context).restart();
2626
refreshMcp();
2727
} catch (e) {

libs/vscode/lsp-client/src/nxls-client.ts

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
commands,
2121
Disposable,
2222
ExtensionContext,
23+
Progress,
2324
ProgressLocation,
2425
window,
2526
} from 'vscode';
@@ -115,51 +116,67 @@ export class NxlsClient {
115116
this.actor.send({ type: 'STOP' });
116117
}
117118

118-
public async refreshWorkspace() {
119-
await window.withProgress(
120-
{
121-
location: ProgressLocation.Notification,
122-
title: 'Refreshing Workspace',
123-
cancellable: false,
124-
},
125-
async (progress) => {
126-
try {
127-
if (this.actor.getSnapshot().matches('running')) {
119+
public async refreshWorkspace(silent = false) {
120+
const refreshLogic = async (
121+
progress?: Progress<{ message?: string; increment?: number }>,
122+
) => {
123+
try {
124+
if (this.actor.getSnapshot().matches('running')) {
125+
if (progress) {
128126
progress.report({ message: 'Stopping nx daemon', increment: 10 });
129-
try {
130-
await this.sendRequest(NxStopDaemonRequest, undefined);
131-
} catch (e) {
132-
// errors while stopping the daemon aren't critical
133-
}
134-
135-
this.stop();
136127
}
128+
try {
129+
await this.sendRequest(NxStopDaemonRequest, undefined);
130+
} catch (e) {
131+
// errors while stopping the daemon aren't critical
132+
}
133+
134+
this.stop();
135+
}
136+
if (progress) {
137137
progress.report({ increment: 30 });
138+
}
138139

140+
if (progress) {
139141
progress.report({ message: 'Restarting language server' });
140-
await waitFor(this.actor, (snapshot) => snapshot.matches('idle'));
141-
this.start();
142+
}
143+
await waitFor(this.actor, (snapshot) => snapshot.matches('idle'));
144+
this.start();
145+
if (progress) {
142146
progress.report({ message: 'Refreshing workspace', increment: 30 });
147+
}
143148

144-
await this.sendNotification(NxWorkspaceRefreshNotification);
145-
146-
await new Promise<void>((resolve) => {
147-
const disposable = this.onNotification(
148-
NxWorkspaceRefreshNotification,
149-
() => {
150-
disposable.dispose();
151-
resolve();
152-
},
153-
);
154-
});
155-
} catch (error) {
156-
logAndShowError(
157-
"Couldn't refresh workspace. Please view the logs for more information.",
158-
error,
149+
await this.sendNotification(NxWorkspaceRefreshNotification);
150+
151+
await new Promise<void>((resolve) => {
152+
const disposable = this.onNotification(
153+
NxWorkspaceRefreshNotification,
154+
() => {
155+
disposable.dispose();
156+
resolve();
157+
},
159158
);
160-
}
161-
},
162-
);
159+
});
160+
} catch (error) {
161+
logAndShowError(
162+
"Couldn't refresh workspace. Please view the logs for more information.",
163+
error,
164+
);
165+
}
166+
};
167+
168+
if (silent) {
169+
await refreshLogic();
170+
} else {
171+
await window.withProgress(
172+
{
173+
location: ProgressLocation.Notification,
174+
title: 'Refreshing Workspace',
175+
cancellable: false,
176+
},
177+
refreshLogic,
178+
);
179+
}
163180
}
164181

165182
public async sendRequest<P, R, E>(
@@ -393,7 +410,7 @@ function refreshWorkspaceOnBranchChange(
393410
`Branch changed from ${branch} to ${newBranch}, refreshing workspace`,
394411
);
395412
branch = newBranch;
396-
commands.executeCommand('nxConsole.refreshWorkspace');
413+
commands.executeCommand('nxConsole.refreshWorkspace', true);
397414
}
398415
});
399416
}

0 commit comments

Comments
 (0)