Skip to content

Commit

Permalink
Merge pull request #374 from ziglang/techatrix/prevent-duplicate-zls
Browse files Browse the repository at this point in the history
prevent cases where ZLS is started multiple times
  • Loading branch information
Vexu authored Dec 30, 2024
2 parents 3780215 + 840c16e commit 56e39b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/zigSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vscode from "vscode";
import path from "path";

import axios from "axios";
import { debounce } from "lodash-es";
import semver from "semver";

import * as minisign from "./minisign";
Expand Down Expand Up @@ -537,13 +538,13 @@ export async function setupZig(context: vscode.ExtensionContext) {
const watcher1 = vscode.workspace.createFileSystemWatcher("**/.zigversion");
const watcher2 = vscode.workspace.createFileSystemWatcher("**/build.zig.zon");

const refreshZigInstallation = async () => {
const refreshZigInstallation = debounce(async () => {
if (!vscode.workspace.getConfiguration("zig").get<string>("path")) {
await installZig(context);
} else {
await updateStatus(context);
}
};
}, 200);

const onDidChangeActiveTextEditor = (editor: vscode.TextEditor | undefined) => {
if (editor?.document.languageId === "zig") {
Expand Down
9 changes: 5 additions & 4 deletions src/zls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function restartClient(context: vscode.ExtensionContext): Promise<v

try {
const newClient = await startClient(result.exe, result.version);
await stopClient();
void stopClient();
client = newClient;
updateStatusItem(result.version);
} catch (reason) {
Expand Down Expand Up @@ -94,11 +94,12 @@ async function startClient(zlsPath: string, zlsVersion: semver.SemVer): Promise<

async function stopClient(): Promise<void> {
if (!client) return;
const oldClient = client;
client = null;
// The `stop` call will send the "shutdown" notification to the LSP
await client.stop();
await oldClient.stop();
// The `dipose` call will send the "exit" request to the LSP which actually tells the child process to exit
await client.dispose();
client = null;
await oldClient.dispose();
}

/** returns the file system path to the zls executable */
Expand Down

0 comments on commit 56e39b9

Please sign in to comment.