Skip to content

Commit 755d3bd

Browse files
committed
restart daemon watcher from button
1 parent ef64052 commit 755d3bd

File tree

12 files changed

+113
-31
lines changed

12 files changed

+113
-31
lines changed

apps/nxls/src/requests.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
NxProjectGraphOutputRequest,
2020
NxRecentCIPEDataRequest,
2121
NxSourceMapFilesToProjectsMapRequest,
22+
NxStartDaemonRequest,
2223
NxStartupMessageRequest,
2324
NxStopDaemonRequest,
2425
NxTargetsForConfigFileRequest,
@@ -43,6 +44,7 @@ import {
4344
getTargetsForConfigFile,
4445
getTransformedGeneratorSchema,
4546
hasAffectedProjects,
47+
nxStartDaemon,
4648
nxStopDaemon,
4749
parseTargetString,
4850
} from '@nx-console/language-server-workspace';
@@ -76,6 +78,18 @@ export function registerRequests(
7678
return await nxStopDaemon(WORKING_PATH, lspLogger);
7779
});
7880

81+
connection.onRequest(NxStartDaemonRequest, async () => {
82+
const WORKING_PATH = getWorkingPath();
83+
if (!WORKING_PATH) {
84+
return new ResponseError(
85+
1000,
86+
'Unable to get Nx info: no workspace path',
87+
);
88+
}
89+
90+
return await nxStartDaemon(WORKING_PATH, lspLogger);
91+
});
92+
7993
connection.onRequest(NxWorkspaceSerializedRequest, async ({ reset }) => {
8094
const WORKING_PATH = getWorkingPath();
8195
if (!WORKING_PATH) {

apps/vscode/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@
221221
"command": "nxConsole.showProblems",
222222
"when": "view == nxProjects && viewItem == projectGraphError",
223223
"group": "inline@1"
224+
},
225+
{
226+
"command": "nxConsole.restartDaemonWatcher",
227+
"when": "view == nxProjects && (viewItem == daemonDisabled || viewItem == daemonWatcherNotRunning)",
228+
"group": "inline@1"
224229
}
225230
],
226231
"editor/title": [
@@ -945,6 +950,12 @@
945950
"command": "nxConsole.showProblems",
946951
"icon": "$(eye)"
947952
},
953+
{
954+
"category": "Nx",
955+
"title": "Restart Daemon Watcher",
956+
"command": "nxConsole.restartDaemonWatcher",
957+
"icon": "$(refresh)"
958+
},
948959
{
949960
"category": "Nx Migrate",
950961
"title": "Refresh View",

libs/language-server/types/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export const NxWatcherOperationalNotification: NotificationType<{
4141
export const NxStopDaemonRequest: RequestType<undefined, undefined, unknown> =
4242
new RequestType('nx/stopDaemon');
4343

44+
export const NxStartDaemonRequest: RequestType<undefined, undefined, unknown> =
45+
new RequestType('nx/startDaemon');
46+
4447
export const NxWorkspaceRequest: RequestType<
4548
{ reset: boolean },
4649
NxWorkspace,

libs/language-server/workspace/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export * from './lib/get-project-folder-tree';
88
export * from './lib/nx-console-plugins';
99
export * from './lib/has-affected-projects';
1010
export * from './lib/get-source-map';
11-
export * from './lib/nx-stop-daemon';
11+
export * from './lib/nx-daemon';
1212
export * from './lib/get-nx-cloud-status';
1313
export * from './lib/get-cloud-onboarding-info';
1414
export * from './lib/get-pdv-data';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Logger } from '@nx-console/shared-utils';
2+
import { getPackageManagerCommand } from '@nx-console/shared-npm';
3+
import { execSync } from 'node:child_process';
4+
5+
export async function nxStopDaemon(workspacePath: string, logger: Logger) {
6+
const packageManagerCommands = await getPackageManagerCommand(
7+
workspacePath,
8+
logger,
9+
);
10+
const command = `${packageManagerCommands.exec} nx daemon --stop`;
11+
logger.log(`stopping daemon with ${command}`);
12+
execSync(command, {
13+
cwd: workspacePath,
14+
windowsHide: true,
15+
});
16+
}
17+
18+
export async function nxStartDaemon(workspacePath: string, logger: Logger) {
19+
const packageManagerCommands = await getPackageManagerCommand(
20+
workspacePath,
21+
logger,
22+
);
23+
const command = `${packageManagerCommands.exec} nx daemon --start`;
24+
logger.log(`starting daemon with ${command}`);
25+
26+
execSync(command, {
27+
cwd: workspacePath,
28+
windowsHide: true,
29+
});
30+
}

libs/language-server/workspace/src/lib/nx-stop-daemon.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

libs/shared/telemetry/src/lib/telemetry-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type TelemetryEvents =
1919
| 'misc.open-project-details-codelens'
2020
| 'misc.exception'
2121
| 'misc.nx-latest-no-provenance'
22+
| 'misc.restart-daemon-watcher'
2223
// migrate
2324
| 'migrate.open'
2425
| 'migrate.start'

libs/vscode/nx-project-view/src/lib/init-nx-project-view.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { showRefreshLoadingAtLocation } from '@nx-console/vscode-lsp-client';
1+
import {
2+
getNxlsClient,
3+
NxlsClient,
4+
showRefreshLoadingAtLocation,
5+
} from '@nx-console/vscode-lsp-client';
26
import { selectProject } from '@nx-console/vscode-nx-cli-quickpicks';
37
import { revealNxProject } from '@nx-console/vscode-nx-config-decoration';
48
import { getNxWorkspaceProjects } from '@nx-console/vscode-nx-workspace';
@@ -8,6 +12,14 @@ import { AtomizerDecorationProvider } from './atomizer-decorations';
812
import { NxProjectTreeProvider } from './nx-project-tree-provider';
913
import { NxTreeItem } from './nx-tree-item';
1014
import { ProjectGraphErrorDecorationProvider } from './project-graph-error-decorations';
15+
import {
16+
NxStartDaemonRequest,
17+
NxWorkspaceRefreshNotification,
18+
} from '@nx-console/language-server-types';
19+
import {
20+
logAndShowError,
21+
showErrorMessageWithOpenLogs,
22+
} from '@nx-console/vscode-output-channels';
1123

1224
export function initNxProjectView(
1325
context: ExtensionContext,
@@ -19,10 +31,14 @@ export function initNxProjectView(
1931
});
2032

2133
context.subscriptions.push(nxProjectTreeView);
22-
23-
commands.registerCommand(
24-
'nxConsole.showProjectConfiguration',
25-
showProjectConfiguration,
34+
context.subscriptions.push(
35+
commands.registerCommand(
36+
'nxConsole.showProjectConfiguration',
37+
showProjectConfiguration,
38+
),
39+
commands.registerCommand('nxConsole.restartDaemonWatcher', async () => {
40+
await tryRestartDaemonWatcher();
41+
}),
2642
);
2743

2844
AtomizerDecorationProvider.register(context);
@@ -66,3 +82,17 @@ export async function showProjectConfiguration(selection: NxTreeItem) {
6682
const target = viewItem.nxTarget;
6783
return revealNxProject(project, root, target);
6884
}
85+
86+
async function tryRestartDaemonWatcher() {
87+
getTelemetry().logUsage('misc.restart-daemon-watcher');
88+
89+
const nxlsClient = getNxlsClient();
90+
try {
91+
await nxlsClient.sendRequest(NxStartDaemonRequest, undefined);
92+
} catch (e) {
93+
showErrorMessageWithOpenLogs('Failed to start Nx daemon watcher');
94+
return;
95+
}
96+
97+
await nxlsClient.sendNotification(NxWorkspaceRefreshNotification);
98+
}

libs/vscode/nx-project-view/src/lib/nx-tree-item.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ export class NxTreeItem extends TreeItem {
6060
return;
6161
}
6262

63-
if (this.contextValue === 'daemonDisabled') {
63+
if (
64+
this.contextValue === 'daemonDisabled' ||
65+
this.contextValue === 'daemonWatcherNotRunning'
66+
) {
6467
this.iconPath = new ThemeIcon('warning');
6568
return;
6669
}

libs/vscode/nx-project-view/src/lib/views/nx-project-base-view.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export abstract class BaseView {
259259
return {
260260
id: 'daemonDisabled',
261261
contextValue: 'daemonDisabled',
262-
label: `Nx Daemon is Disabled`,
262+
label: `Nx Daemon is disabled`,
263263
collapsible: TreeItemCollapsibleState.None,
264264
};
265265
}
@@ -268,7 +268,7 @@ export abstract class BaseView {
268268
return {
269269
id: 'daemonWatcherNotRunning',
270270
contextValue: 'daemonWatcherNotRunning',
271-
label: `Nx Daemon is Not Running`,
271+
label: `Nx daemon watcher is not running`,
272272
collapsible: TreeItemCollapsibleState.None,
273273
};
274274
}

0 commit comments

Comments
 (0)