Skip to content
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

prevent cases where ZLS is started multiple times #374

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -452,15 +453,15 @@ 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 {
updateStatusItem(statusItem, zigProvider.getZigVersion());
updateLanguageStatusItem(languageStatusItem, zigProvider.getZigVersion());
updateZigEnvironmentVariableCollection(context, zigProvider.getZigPath());
}
};
}, 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
Loading