Skip to content

Commit

Permalink
fix: file watcher should also watch for env sources
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Jan 19, 2025
1 parent f4c1ca0 commit 89a443e
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/miseFileWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from "node:path";
import * as vscode from "vscode";
import { isMiseExtensionEnabled } from "./configuration";
import type { MiseService } from "./miseService";
import { expandPath } from "./utils/fileUtils";
import { logger } from "./utils/logger";
import {
allowedFileTaskDirs,
Expand Down Expand Up @@ -50,35 +52,40 @@ export class MiseFileWatcher {
);
patterns.push(miseStandardConfigsPattern);

const configFiles = await this.miseService.getMiseConfigFiles();
for (const file of configFiles) {
const [configFiles, tasksSources, envs] = await Promise.all([
this.miseService.getMiseConfigFiles(),
this.miseService.getAllCachedTasksSources(),
this.miseService.getEnvWithInfo(),
]);

const envSources = envs
.map((env) => env.source ?? "")
.filter((source) => source !== "");

const filesToWatch = [
...new Set([
...configFiles.map((c) => c.path),
...tasksSources,
...envSources,
...idiomaticFiles
.values()
.map((f) => expandPath(path.join(rootFolder.uri.fsPath, f))),
]),
];

for (const file of filesToWatch) {
const miseDetectedConfigs = new vscode.RelativePattern(
vscode.Uri.file(file.path),
vscode.Uri.file(file),
"*",
);
patterns.push(miseDetectedConfigs);
}

const idiomaticFilesPattern = new vscode.RelativePattern(
rootFolder,
`{${[...idiomaticFiles].join(",")}}`,
);
patterns.push(idiomaticFilesPattern);

const taskDirsPattern = new vscode.RelativePattern(
rootFolder,
`{${allowedFileTaskDirs.map((dir) => `${dir}/**/*`)}}`,
);
patterns.push(taskDirsPattern);

const tasksSources = await this.miseService.getAllCachedTasksSources();
for (const taskSource of tasksSources) {
const taskSourcePattern = new vscode.RelativePattern(
vscode.Uri.file(taskSource),
"*",
);
patterns.push(taskSourcePattern);
}
}

for (const pattern of patterns) {
Expand Down

0 comments on commit 89a443e

Please sign in to comment.