Skip to content

Commit

Permalink
Merge pull request #719 from ejgallego/code_fix_restart_async
Browse files Browse the repository at this point in the history
[code] Wait for shutdown to complete before we start the client again.
  • Loading branch information
ejgallego authored May 17, 2024
2 parents 004bde6 + 970aa54 commit 5c98534
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
the scheduler for the visible area of the document; combined with
the new lazy checking mode, this provides checking on scroll, a
feature inspired from Isabelle IDE (@ejgallego, #717)
- Have VSCode wait for full LSP client shutdown on server restart
(@ejgallgo, #719)

# coq-lsp 0.1.8.1: Spring fix
-----------------------------
Expand Down
53 changes: 27 additions & 26 deletions editor/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function activateCoqLSP(
return settings;
}

function coqCommand(command: string, fn: () => void) {
function coqCommand(command: string, fn: () => void | Promise<void>) {
let disposable = commands.registerCommand("coq-lsp." + command, fn);
context.subscriptions.push(disposable);
}
Expand Down Expand Up @@ -165,7 +165,7 @@ export function activateCoqLSP(

const stop = () => {
if (client && client.isRunning()) {
client
return client
.dispose(2000)
.finally(updateStatusBar)
.finally(() => {
Expand All @@ -174,7 +174,7 @@ export function activateCoqLSP(
perfDataHook.dispose();
heatMap.dispose();
});
}
} else return Promise.resolve();
};

const start = () => {
Expand Down Expand Up @@ -204,35 +204,36 @@ export function activateCoqLSP(
resolve(client);
});

cP.then((client) =>
client
.start()
.then(updateStatusBar)
.then(() => {
if (window.activeTextEditor) {
goalsCall(
window.activeTextEditor,
TextEditorSelectionChangeKind.Command
);
}
})
).catch((error) => {
let emsg = error.toString();
console.log(`Error in coq-lsp start: ${emsg}`);
setFailedStatuBar(emsg);
});
return cP
.then((client) =>
client
.start()
.then(updateStatusBar)
.then(() => {
if (window.activeTextEditor) {
goalsCall(
window.activeTextEditor,
TextEditorSelectionChangeKind.Command
);
}
})
)
.catch((error) => {
let emsg = error.toString();
console.log(`Error in coq-lsp start: ${emsg}`);
setFailedStatuBar(emsg);
});
};

const restart = () => {
stop();
start();
const restart = async () => {
await stop().finally(start);
};

const toggle = () => {
const toggle = async () => {
if (client && client.isRunning()) {
stop();
await stop();
} else {
start();
await start();
}
};

Expand Down

0 comments on commit 5c98534

Please sign in to comment.