Skip to content

Commit

Permalink
use relative pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger committed Jan 24, 2024
1 parent a190f86 commit 9a13fce
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type * as resolve from "resolve";
import {
ExtensionContext,
OutputChannel,
RelativePattern,
TextEditor,
Uri,
commands,
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*"),
);
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

0 comments on commit 9a13fce

Please sign in to comment.