Skip to content
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

fix(vscode): register workspace change listener in all cases #2162

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix(vscode): register workspace change listener in all cases
  • Loading branch information
MaxKless committed Jun 14, 2024
commit 3d07c1f3faf83d9bf278c73048c3a9dad2108098
40 changes: 18 additions & 22 deletions apps/vscode/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { existsSync } from 'fs';
import { dirname, join, parse } from 'path';
import {
Disposable,
ExtensionContext,
ExtensionMode,
FileSystemWatcher,
RelativePattern,
commands,
tasks,
Expand Down Expand Up @@ -39,7 +39,7 @@ import { createNxlsClient, getNxlsClient } from '@nx-console/vscode/lsp-client';
import { initNxConfigDecoration } from '@nx-console/vscode/nx-config-decoration';
import { initNxConversion } from '@nx-console/vscode/nx-conversion';
import { initHelpAndFeedbackView } from '@nx-console/vscode/nx-help-and-feedback-view';
import { getNxWorkspace, stopDaemon } from '@nx-console/vscode/nx-workspace';
import { stopDaemon } from '@nx-console/vscode/nx-workspace';
import { initVscodeProjectGraph } from '@nx-console/vscode/project-graph';
import { enableTypeScriptPlugin } from '@nx-console/vscode/typescript-plugin';

Expand All @@ -57,7 +57,7 @@ import { registerRefreshWorkspace } from './refresh-workspace';
let nxProjectsTreeProvider: NxProjectTreeProvider;

let context: ExtensionContext;
let workspaceFileWatcher: FileSystemWatcher | undefined;
let workspaceFileWatcher: Disposable | undefined;

let isNxWorkspace = false;

Expand Down Expand Up @@ -86,6 +86,10 @@ export async function activate(c: ExtensionContext) {

if (vscodeWorkspacePath) {
await scanForWorkspace(vscodeWorkspacePath);

if (!isNxWorkspace && !workspaceFileWatcher) {
registerWorkspaceFileWatcher(context, vscodeWorkspacePath);
}
}

context.subscriptions.push(manuallySelectWorkspaceDefinitionCommand);
Expand All @@ -108,6 +112,7 @@ export async function activate(c: ExtensionContext) {
export async function deactivate() {
await stopDaemon();
await getNxlsClient()?.stop();
workspaceFileWatcher?.dispose();
getTelemetry().extensionDeactivated();
}

Expand Down Expand Up @@ -236,25 +241,16 @@ async function registerWorkspaceFileWatcher(
workspaceFileWatcher.dispose();
}

const workspaceLayout = (await getNxWorkspace())?.workspaceLayout;
const workspacePackageDirs = new Set<string>();
if (workspaceLayout?.appsDir) {
workspacePackageDirs.add(workspaceLayout.appsDir);
}
if (workspaceLayout?.libsDir) {
workspacePackageDirs.add(workspaceLayout.libsDir);
}
workspacePackageDirs.add('packages');
context.subscriptions.push(
watchFile(
new RelativePattern(workspacePath, '{workspace,angular,nx,project}.json'),
() => {
if (!isNxWorkspace) {
setTimeout(() => {
setWorkspace(workspacePath);
}, 1000);
}
workspaceFileWatcher = watchFile(
new RelativePattern(workspacePath, '{workspace,angular,nx,project}.json'),
() => {
if (!isNxWorkspace) {
setTimeout(() => {
setWorkspace(workspacePath);
}, 1000);
}
)
}
);

context.subscriptions.push(workspaceFileWatcher);
}