Skip to content

Commit 0e7c866

Browse files
feat: setup monitoring on serverMode
1 parent 2e2ffaf commit 0e7c866

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/upgrade/upgradeManager.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { commands, type ExtensionContext, workspace, type WorkspaceFolder } from "vscode";
4+
import { commands, type ExtensionContext, type Event, workspace, type WorkspaceFolder } from "vscode";
55

66
import { Jdtls } from "../java/jdtls";
77
import { languageServerApiManager } from "../languageServerApi/languageServerApiManager";
@@ -12,6 +12,8 @@ import notificationManager from "./display/notificationManager";
1212
import { Settings } from "../settings";
1313
import assessmentManager, { getDirectDependencies } from "./assessmentManager";
1414
import { checkOrInstallAppModExtensionForUpgrade, checkOrPopupToInstallAppModExtensionForModernization } from "./utility";
15+
import { contextManager } from "../contextManager";
16+
import { LanguageServerMode } from "../languageServerApi/LanguageServerMode";
1517

1618
const DEFAULT_UPGRADE_PROMPT = "Upgrade Java project dependency to latest version.";
1719

@@ -21,6 +23,8 @@ function shouldRunCheckup() {
2123
}
2224

2325
class UpgradeManager {
26+
private static watcherSetup = false;
27+
2428
public static initialize(context: ExtensionContext) {
2529
notificationManager.initialize(context);
2630

@@ -55,6 +59,8 @@ class UpgradeManager {
5559
return;
5660
}
5761

62+
UpgradeManager.setupWatcherForServerModeChange();
63+
5864
const hasJavaError: boolean = await Jdtls.checkImportStatus();
5965
if (hasJavaError) {
6066
sendInfo(_operationId, { skipReason: "hasJavaError" });
@@ -92,6 +98,23 @@ class UpgradeManager {
9298
}
9399
})();
94100
}
101+
102+
private static setupWatcherForServerModeChange() {
103+
if (UpgradeManager.watcherSetup) {
104+
return;
105+
}
106+
107+
const extensionApi = languageServerApiManager.getExtensionApi();
108+
if (extensionApi.onDidServerModeChange) {
109+
const onDidServerModeChange: Event<string> = extensionApi.onDidServerModeChange;
110+
contextManager.context.subscriptions.push(onDidServerModeChange((mode: LanguageServerMode) => {
111+
if (mode !== LanguageServerMode.LightWeight) {
112+
UpgradeManager.scan();
113+
}
114+
}));
115+
UpgradeManager.watcherSetup = true;
116+
}
117+
}
95118
}
96119

97120
export default UpgradeManager;

0 commit comments

Comments
 (0)