Skip to content
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
18 changes: 7 additions & 11 deletions src/domain/graph/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import fs from 'node:fs';
import path from 'node:path';
import { closeDb, getNodeId as getNodeIdQuery, initSchema, openDb } from '../../db/index.js';
import { debug, info } from '../../infrastructure/logger.js';
import { EXTENSIONS, IGNORE_DIRS, normalizePath } from '../../shared/constants.js';
import { isSupportedFile, normalizePath, shouldIgnore } from '../../shared/constants.js';
import { DbError } from '../../shared/errors.js';
import { createParseTreeCache, getActiveEngine } from '../parser.js';
import { type IncrementalStmts, rebuildFile } from './builder/incremental.js';
import { appendChangeEvents, buildChangeEvent, diffSymbols } from './change-journal.js';
import { appendJournalEntries } from './journal.js';

function shouldIgnore(filePath: string): boolean {
function shouldIgnorePath(filePath: string): boolean {
const parts = filePath.split(path.sep);
return parts.some((p) => IGNORE_DIRS.has(p));
}

function isTrackedExt(filePath: string): boolean {
return EXTENSIONS.has(path.extname(filePath));
return parts.some((p) => shouldIgnore(p));
}

/** Prepare all SQL statements needed by the watcher's incremental rebuild. */
Expand Down Expand Up @@ -146,11 +142,11 @@ function collectTrackedFiles(dir: string, result: string[]): void {
return;
}
for (const entry of entries) {
if (IGNORE_DIRS.has(entry.name) || entry.name.startsWith('.')) continue;
if (shouldIgnore(entry.name)) continue;
const full = path.join(dir, entry.name);
if (entry.isDirectory()) {
collectTrackedFiles(full, result);
} else if (EXTENSIONS.has(path.extname(entry.name))) {
} else if (isSupportedFile(entry.name)) {
result.push(full);
}
}
Expand Down Expand Up @@ -268,8 +264,8 @@ function startPollingWatcher(ctx: WatcherContext, pollIntervalMs: number): () =>
function startNativeWatcher(ctx: WatcherContext): () => void {
const watcher = fs.watch(ctx.rootDir, { recursive: true }, (_eventType, filename) => {
if (!filename) return;
if (shouldIgnore(filename)) return;
if (!isTrackedExt(filename)) return;
if (shouldIgnorePath(filename)) return;
if (!isSupportedFile(filename)) return;

ctx.pending.add(path.join(ctx.rootDir, filename));
scheduleDebouncedProcess(ctx);
Expand Down
Loading