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

fix: only watch lock files in workspace root #91

Merged
merged 6 commits into from
Jan 24, 2024
Merged
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
53 changes: 29 additions & 24 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { type ChildProcess, spawn } from "child_process";
import { createRequire } from "module";
import { type Socket, connect } from "net";
import { dirname, isAbsolute } from "path";
import { promisify } from "util";
import type * as resolve from "resolve";
import {
ExtensionContext,
OutputChannel,
RelativePattern,
TextEditor,
Uri,
commands,
Expand All @@ -22,14 +25,12 @@ import {
} from "vscode-languageclient/node";
import { Commands } from "./commands";
import { syntaxTree } from "./commands/syntaxTree";
import { selectAndDownload, updateToLatest } from "./downloader";
import { Session } from "./session";
import { StatusBar } from "./statusBar";
import { setContextValue } from "./utils";

import resolveImpl = require("resolve/async");
import { createRequire } from "module";
import type * as resolve from "resolve";
import { selectAndDownload, updateToLatest } from "./downloader";

const resolveAsync = promisify<string, resolve.AsyncOpts, string | undefined>(
resolveImpl,
Expand Down Expand Up @@ -192,28 +193,32 @@ export async function activate(context: ExtensionContext) {

await reloadClient();

// Best way to determine package updates. Will work for npm, yarn, pnpm and bun. (Might work for more files also).
// It is not possible to listen node_modules, because it is usually gitignored.
const watcher = workspace.createFileSystemWatcher("**/*lock*");
context.subscriptions.push(
watcher.onDidChange(async () => {
try {
// When the lockfile changes, reload the biome executable.
outputChannel.appendLine("Reloading biome executable.");
if (client.isRunning()) {
await client.stop();
}
await reloadClient();
if (client.isRunning()) {
await client.restart();
} else {
await client.start();
if (workspace.workspaceFolders?.[0]) {
// Best way to determine package updates. Will work for npm, yarn, pnpm and bun. (Might work for more files also).
// It is not possible to listen node_modules, because it is usually gitignored.
const watcher = workspace.createFileSystemWatcher(
new RelativePattern(workspace.workspaceFolders[0], "*lock*"),
Copy link
Member

@nhedger nhedger Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated to a RelativePattern, because otherwise the watcher won't work as expected. See microsoft/vscode#31602

);
context.subscriptions.push(
watcher.onDidChange(async () => {
try {
// When the lockfile changes, reload the biome executable.
outputChannel.appendLine("Reloading biome executable.");
if (client.isRunning()) {
await client.stop();
}
await reloadClient();
if (client.isRunning()) {
await client.restart();
} else {
await client.start();
}
} catch (error) {
outputChannel.appendLine(`Reloading client failed: ${error}`);
}
} catch (error) {
outputChannel.appendLine(`Reloading client failed: ${error}`);
}
}),
);
}),
);
}

const session = new Session(context, client);

Expand Down
Loading