Skip to content

Commit 45e5ff2

Browse files
committed
[IMP] use WorkdoneProgress to report loading status and git lock status
1 parent db2e795 commit 45e5ff2

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

client/extension.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,25 @@ const RESTART_COMMAND_MD = `[$(list-unordered) Show all configurations](command:
207207

208208
async function setStatusConfig(context: ExtensionContext) {
209209
const config = await getCurrentConfig(context);
210+
let icon: string;
211+
let text_git = "";
212+
switch (global.LOADING_STATUS) {
213+
case "LOADING":
214+
icon = "$(loading~spin) ";
215+
break;
216+
case "READY":
217+
icon = "";
218+
break;
219+
case "GIT_LOCKED":
220+
icon = "$(lock) ";
221+
text_git = " (awaiting git)";
222+
break;
223+
default:
224+
icon = "";
225+
break;
226+
}
210227
let text = (config ? `Odoo (${config})` : `Odoo (Default)`);
211-
global.STATUS_BAR.text = (global.IS_LOADING) ? "$(loading~spin) " + text : text;
228+
global.STATUS_BAR.text = icon + text + text_git;
212229

213230
let tooltipMd = '';
214231
if (config && config !== 'Disabled') {
@@ -337,13 +354,16 @@ async function initLanguageServerClient(context: ExtensionContext, outputChannel
337354
}
338355

339356
context.subscriptions.push(
340-
client.onNotification("$Odoo/loadingStatusUpdate", async (state: String) => {
341-
switch (state) {
357+
client.onNotification("$Odoo/loadingStatusUpdate", async (status: string) => {
358+
switch (status) {
342359
case "start":
343-
global.IS_LOADING = true;
360+
global.LOADING_STATUS = "LOADING";
344361
break;
345362
case "stop":
346-
global.IS_LOADING = false;
363+
global.LOADING_STATUS = "READY";
364+
break;
365+
case "git_locked":
366+
global.LOADING_STATUS = "GIT_LOCKED";
347367
break;
348368
}
349369
await setStatusConfig(context);
@@ -372,8 +392,8 @@ async function initLanguageServerClient(context: ExtensionContext, outputChannel
372392
client.onNotification("$Odoo/restartNeeded", async () => {
373393
if (global.LSCLIENT) {
374394
global.LSCLIENT.restart();
375-
global.IS_LOADING = false;
376-
setStatusConfig(context);
395+
global.LOADING_STATUS = "READY";
396+
await setStatusConfig(context);
377397
}
378398
})
379399
);
@@ -525,8 +545,8 @@ async function initializeSubscriptions(context: ExtensionContext): Promise<void>
525545
"odoo.restartServer", async () => {
526546
if (global.LSCLIENT) {
527547
global.LSCLIENT.restart();
528-
global.IS_LOADING = false;
529-
setStatusConfig(context);
548+
global.LOADING_STATUS = "READY";
549+
await setStatusConfig(context);
530550
}
531551
}),
532552
commands.registerCommand("odoo.showServerConfig", async () => {
@@ -696,7 +716,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
696716

697717
deleteOldFiles(context);
698718
global.LSCLIENT.info('Starting the extension.');
699-
setStatusConfig(context);
719+
await setStatusConfig(context);
700720
global.LSCLIENT.start();
701721
}
702722
catch (error) {
@@ -716,7 +736,7 @@ async function waitForClientStop() {
716736
async function stopClient() {
717737
if (global.LSCLIENT && !global.CLIENT_IS_STOPPING) {
718738
global.LSCLIENT.info("Stopping LS Client.");
719-
global.IS_LOADING = false;
739+
global.LOADING_STATUS = "READY";
720740
global.CLIENT_IS_STOPPING = true;
721741
await global.LSCLIENT.stop(15000);
722742
global.CLIENT_IS_STOPPING = false;
@@ -839,8 +859,8 @@ async function showConfigProfileQuickPick(context: ExtensionContext) {
839859
const ok = await changeSelectedConfig(context, selection.label);
840860
if (ok && global.LSCLIENT) {
841861
global.LSCLIENT.restart();
842-
global.IS_LOADING = false;
843-
setStatusConfig(context);
862+
global.LOADING_STATUS = "READY";
863+
await setStatusConfig(context);
844864
}
845865
}
846866
}

client/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ declare global {
77
var LSCLIENT: LanguageClient;
88
var STATUS_BAR: StatusBarItem;
99
var OUTPUT_CHANNEL: OutputChannel;
10-
var IS_LOADING: boolean;
10+
var LOADING_STATUS: String;
1111
var SERVER_PID: number;
1212
var CLIENT_IS_STOPPING: boolean;
1313
var CAN_QUEUE_CONFIG_CHANGE: boolean;

0 commit comments

Comments
 (0)