Skip to content

Commit

Permalink
[FIX] Restart Language Server when changing interpreter
Browse files Browse the repository at this point in the history
This commit fixes the language server not reloading when changing Python
interpreter.
Also adds a shebang to the build script + few minor tweaks.
  • Loading branch information
delvsola committed Nov 22, 2023
1 parent 15b4309 commit 6845182
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions vscode/build_package.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
Expand Down
34 changes: 27 additions & 7 deletions vscode/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async function displayCrashMessage(context: ExtensionContext, crashInfo: string,
}
}

async function initLanguageServerClient(context: ExtensionContext, outputChannel: OutputChannel) {
async function initLanguageServerClient(context: ExtensionContext, outputChannel: OutputChannel, autoStart = false) {
let client = global.LSCLIENT;
try {
const interpreter = await getInterpreterDetails();
Expand Down Expand Up @@ -286,6 +286,10 @@ async function initLanguageServerClient(context: ExtensionContext, outputChannel
await displayCrashMessage(context, params["crashInfo"]);
})
);
if (autoStart) {
await client.start();
await client.sendNotification("Odoo/clientReady");
}
return client;
} catch (error) {
outputChannel.appendLine("Couldn't Start Language server.");
Expand Down Expand Up @@ -373,8 +377,8 @@ async function initStatusBar(context: ExtensionContext): Promise<void> {
global.STATUS_BAR = window.createStatusBarItem(StatusBarAlignment.Left, 100);
global.STATUS_BAR.command = "odoo.clickStatusBar"
context.subscriptions.push(global.STATUS_BAR);
global.STATUS_BAR.show();
await setStatusConfig(context);
global.STATUS_BAR.show();
}


Expand Down Expand Up @@ -413,6 +417,7 @@ async function initializeSubscriptions(context: ExtensionContext): Promise<void>
selectedConfigurationChange.event(async () => {
try {
if (!global.CAN_QUEUE_CONFIG_CHANGE) return;

if (global.CLIENT_IS_STOPPING) {
global.CAN_QUEUE_CONFIG_CHANGE = false;
await waitForClientStop();
Expand Down Expand Up @@ -452,7 +457,22 @@ async function initializeSubscriptions(context: ExtensionContext): Promise<void>
// Listen to changes to Python Interpreter
context.subscriptions.push(
onDidChangePythonInterpreter(async (e: IInterpreterDetails) => {
await global.LSCLIENT.restart();
let startClient = false;
global.CAN_QUEUE_CONFIG_CHANGE = false;
if (global.LSCLIENT) {
if (global.CLIENT_IS_STOPPING) {
await waitForClientStop();
}
if (global.LSCLIENT?.isRunning()) {
await stopClient();
}
await global.LSCLIENT.dispose();
}
if (await getCurrentConfig(context)) {
startClient = true;
}
global.LSCLIENT = await initLanguageServerClient(context, global.OUTPUT_CHANNEL, startClient);
global.CAN_QUEUE_CONFIG_CHANGE = true;
})
);

Expand Down Expand Up @@ -646,18 +666,18 @@ async function waitForClientStop() {
}

async function stopClient() {
if (global.LSCLIENT) {
global.LSCLIENT.info("Stopping LS Client.")
if (global.LSCLIENT && !global.CLIENT_IS_STOPPING) {
global.LSCLIENT.info("Stopping LS Client.");
global.CLIENT_IS_STOPPING = true;
await global.LSCLIENT.stop(15000);
global.CLIENT_IS_STOPPING = false;
clientStopped.fire(null);
global.LSCLIENT.info("LS Client stopped.")
global.LSCLIENT.info("LS Client stopped.");
}
}

export async function deactivate(): Promise<void> {
if (global.LSCLIENT) {
await global.LSCLIENT.dispose();
return global.LSCLIENT.dispose();
}
}

0 comments on commit 6845182

Please sign in to comment.