-
Notifications
You must be signed in to change notification settings - Fork 59
FIx LS not working when webview closed issue #1035
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
Changes from all commits
dc7278a
4eb454d
2a565f5
9b3467f
e17712f
b5ba1bc
d7db138
2d5333d
3fc3550
129129d
ce726c0
ca2bafa
67362fa
905aaec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,30 +101,67 @@ const versionRegex = /(\d+\.\d+\.?\d*)/g; | |
|
|
||
| export class MILanguageClient { | ||
| private static _instances: Map<string, MILanguageClient> = new Map(); | ||
| private static lsChannelCache: Map<string, vscode.OutputChannel> = new Map(); | ||
| public languageClient: ExtendedLanguageClient | undefined; | ||
| private static lsChannels: Map<string, vscode.OutputChannel> = new Map(); | ||
| private static stopTimers: Map<string, NodeJS.Timeout> = new Map(); | ||
| private static stoppingInstances: Set<string> = new Set(); | ||
| private static readonly STOP_DEBOUNCE_MS = 30000; // 30 seconds | ||
| private languageClient: ExtendedLanguageClient | undefined; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| private COMPATIBLE_JDK_VERSION = "11"; // Minimum JDK version required to run the language server | ||
| private _errorStack: ErrorType[] = []; | ||
|
|
||
| constructor(private projectUri: string) { } | ||
|
|
||
| public static async getInstance(projectUri: string): Promise<MILanguageClient> { | ||
| public static async getInstance(projectUri: string): Promise<ExtendedLanguageClient> { | ||
| // Cancel any pending stop operation for this project | ||
| const existingTimer = this.stopTimers.get(projectUri); | ||
| if (existingTimer) { | ||
| clearTimeout(existingTimer); | ||
| this.stopTimers.delete(projectUri); | ||
| } | ||
|
|
||
| // If instance is currently stopping, wait for it to complete and create a new one | ||
| if (this.stoppingInstances.has(projectUri)) { | ||
| // Wait a bit for the stop operation to complete | ||
| await new Promise(resolve => setTimeout(resolve, 100)); | ||
| this.stoppingInstances.delete(projectUri); | ||
| } | ||
|
|
||
| if (!this._instances.has(projectUri)) { | ||
| const instance = new MILanguageClient(projectUri); | ||
| await instance.launch(projectUri); | ||
| this._instances.set(projectUri, instance); | ||
| } | ||
| return this._instances.get(projectUri)!; | ||
| const languageClient = this._instances.get(projectUri)!.languageClient; | ||
| if (!languageClient) { | ||
| const errorMessage = "Language client failed to initialize"; | ||
| window.showErrorMessage(errorMessage); | ||
| throw new Error(errorMessage); | ||
| } | ||
| return languageClient; | ||
| } | ||
|
|
||
| public static async stopInstance(projectUri: string) { | ||
| const instance = this._instances.get(projectUri); | ||
| if (instance) { | ||
| await instance.stop(); | ||
| this._instances.delete(projectUri); | ||
| // Cancel any existing timer for this project | ||
| const existingTimer = this.stopTimers.get(projectUri); | ||
| if (existingTimer) { | ||
| clearTimeout(existingTimer); | ||
| } | ||
|
|
||
| // Schedule the stop operation with debounce | ||
| const timer = setTimeout(async () => { | ||
| this.stoppingInstances.add(projectUri); | ||
| const instance = this._instances.get(projectUri); | ||
| if (instance) { | ||
| await instance.stop(); | ||
| this._instances.delete(projectUri); | ||
| } | ||
| this.stopTimers.delete(projectUri); | ||
| this.stoppingInstances.delete(projectUri); | ||
| }, this.STOP_DEBOUNCE_MS); | ||
|
|
||
| this.stopTimers.set(projectUri, timer); | ||
| } | ||
|
Comment on lines
+116
to
165
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "activator.ts" | grep -E "mi-extension.*lang-client"Repository: wso2/vscode-extensions Length of output: 188 Fix race between debounced A real race exists in the current implementation:
Replace the 100ms delay and bare 🤖 Prompt for AI Agents |
||
|
|
||
| public static async getAllInstances(): Promise<MILanguageClient[]> { | ||
|
|
@@ -136,10 +173,10 @@ export class MILanguageClient { | |
| } | ||
|
|
||
| public static getOrCreateOutputChannel(projectUri: string): vscode.OutputChannel { | ||
| let channel = this.lsChannelCache.get(projectUri); | ||
| let channel = this.lsChannels.get(projectUri); | ||
| if (!channel) { | ||
| channel = vscode.window.createOutputChannel(`Synapse Language Server - ${path.basename(projectUri)}`); | ||
| this.lsChannelCache.set(projectUri, channel); | ||
| this.lsChannels.set(projectUri, channel); | ||
| } | ||
| return channel; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.