Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/calm-filters-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@codegraphy-dev/core": patch
"@codegraphy-dev/extension": patch
---

Persist discovery-time Filter and Git-ignore accounting, restore it from the Graph Cache, and report Filter-excluded workspace files separately from Nodes excluded in the Graph View.
4 changes: 3 additions & 1 deletion packages/core/src/analysis/workspaceAnalyze.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IFileAnalysisResult, IPluginNodeType } from '@codegraphy-dev/plugin-api';
import type { IDiscoveredFile } from '../discovery/contracts';
import type { IDiscoveredFile, WorkspaceFilterAccounting } from '../discovery/contracts';
import type { IGraphData } from '../graph/contracts';
import { throwIfWorkspaceAnalysisAborted } from './abort';
import type { IWorkspaceFileAnalysisResult } from './fileAnalysis';
Expand Down Expand Up @@ -41,6 +41,7 @@ export interface WorkspacePipelineAnalysisSource {
_completeGraphData?: IGraphData;
_lastDiscoveredDirectories: string[];
_lastDiscoveredFiles: IDiscoveredFile[];
_filterAccounting: WorkspaceFilterAccounting;
_lastFileAnalysis: Map<string, IFileAnalysisResult>;
_lastFileConnections: Map<string, IProjectedConnection[]>;
_lastGitIgnoredPaths?: string[];
Expand Down Expand Up @@ -164,6 +165,7 @@ export async function analyzeWorkspaceWithAnalyzer(
source._lastFileConnections = analysisResult.fileConnections;
source._lastDiscoveredDirectories = discoveryResult.directories ?? [];
source._lastDiscoveredFiles = discoveryResult.files;
source._filterAccounting = discoveryResult.filterAccounting;
source._lastGitIgnoredPaths = discoveryResult.gitIgnoredPaths ?? [];
source._lastWorkspaceRoot = workspaceRoot;

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/analysis/workspaceDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { WorkspaceFilterAccounting } from '../discovery/contracts';
import { DEFAULT_EXCLUDE } from '../discovery/pathMatching';

export interface WorkspacePipelineDiscoveryConfig {
Expand All @@ -10,6 +11,7 @@ export interface WorkspacePipelineDiscoveryResult<TFile> {
directories?: string[];
durationMs: number;
files: TFile[];
filterAccounting: Extract<WorkspaceFilterAccounting, { kind: 'current' }>;
gitIgnoredPaths?: string[];
limitReached: boolean;
totalFound: number;
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/discovery/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,22 @@ export interface IDiscoveredFile {
gitIgnored?: boolean;
}

export type WorkspaceFilterAccounting =
| {
kind: 'current';
excludedFileCount: number;
gitIgnoredPathCount: number;
}
| { kind: 'unavailable' };

/**
* Result of a discovery operation.
*/
export interface IDiscoveryResult {
/** Eligible discovered files, capped by maxFiles */
files: IDiscoveredFile[];
/** Filter and Git ignored state accounting captured by this discovery. */
filterAccounting: Extract<WorkspaceFilterAccounting, { kind: 'current' }>;
/** Discovered directory paths relative to the workspace root */
directories: string[];
/** Discovered file and directory paths reported by Git as ignored */
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/discovery/file/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ export class FileDiscovery {
directories,
)
: new Set<string>();
const filterExcludedFileCount = candidateFiles
.filter(file => (
!gitIgnoredPaths.has(file.relativePath)
&& matchesAnyPattern(file.relativePath, filterPatterns)
))
.length;
const eligibleFiles = candidateFiles.filter(file => (
!matchesAnyPattern(file.relativePath, filterPatterns)
&& !gitIgnoredPaths.has(file.relativePath)
Expand Down Expand Up @@ -339,6 +345,11 @@ export class FileDiscovery {
cacheFilePaths,
cachePathPrefixes: gitWorkspacePaths?.ignoredPathPrefixes ?? [],
directories: eligibleDirectories,
filterAccounting: {
kind: 'current',
excludedFileCount: filterExcludedFileCount,
gitIgnoredPathCount: gitIgnoredPaths.size + (gitWorkspacePaths?.ignoredPathPrefixes.length ?? 0),
},
gitIgnoredPaths: [
...gitIgnoredPaths,
...(gitWorkspacePaths?.ignoredPathPrefixes ?? []),
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export type {
IDiscoveredFile,
IDiscoveryOptions,
IDiscoveryResult,
WorkspaceFilterAccounting,
} from './discovery/contracts';
export { createAbortError, throwIfAborted } from './discovery/abort';
export { FileDiscovery } from './discovery/file/service';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/indexing/engineGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async function persistMetadata(runtime: WorkspaceEngineRuntime): Promise<void> {
registry: state.registry,
});
await persistWorkspaceIndexMetadata({
filterAccounting: state.filterAccounting,
pluginBuildSignature: createWorkspaceIndexPluginBuildSignature(state.loadedPackagePlugins),
pluginSignature,
failedPluginIds: state.failedPluginIds,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/indexing/engineSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function discoverWorkspaceEngineFiles(
});
state.discoveredDirectories = state.discoveryResult.directories ?? [];
state.discoveredFiles = state.discoveryResult.files;
state.filterAccounting = state.discoveryResult.filterAccounting;
}

export function createWorkspaceEngineDisabledPlugins(runtime: WorkspaceEngineRuntime): Set<string> {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/indexing/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createCodeGraphyWorkspaceSettingsSignature,
} from '../workspace/signatures';
import type { CodeGraphyWorkspaceSettings } from '../workspace/settings';
import type { WorkspaceFilterAccounting } from '../discovery/contracts';
import type { IndexCodeGraphyWorkspacePlugin } from './contracts';

function runtimeSignaturePlugins(registry: CorePluginRegistry): IPlugin[] {
Expand Down Expand Up @@ -70,6 +71,7 @@ export function createWorkspaceIndexPluginBuildSignature(
}

export async function persistWorkspaceIndexMetadata(input: {
filterAccounting: WorkspaceFilterAccounting;
pluginSignature: string | null;
pluginBuildSignature: string | null;
failedPluginIds: ReadonlySet<string>;
Expand All @@ -79,6 +81,7 @@ export async function persistWorkspaceIndexMetadata(input: {
workspaceRoot: string;
}): Promise<void> {
await persistCodeGraphyWorkspaceIndexMetadata(input.workspaceRoot, {
filterAccounting: input.filterAccounting,
pluginSignature: input.pluginSignature,
pluginBuildSignature: input.pluginBuildSignature,
failedPluginIds: [...input.failedPluginIds].sort((left, right) => left.localeCompare(right)),
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/indexing/state.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createEmptyWorkspaceAnalysisCache, type IWorkspaceAnalysisCache } from '../analysis/cache';
import type { IProjectedConnection } from '../analysis/projectedConnection';
import type { IFileAnalysisResult } from '@codegraphy-dev/plugin-api';
import type { IDiscoveredFile } from '../discovery/contracts';
import type { IDiscoveredFile, WorkspaceFilterAccounting } from '../discovery/contracts';
import type { IGraphData } from '../graph/contracts';

export interface WorkspaceIndexEngineState {
cache: IWorkspaceAnalysisCache;
discoveredDirectories: string[];
discoveredFiles: IDiscoveredFile[];
filterAccounting: WorkspaceFilterAccounting;
gitIgnoredPaths: string[];
fileAnalysis: Map<string, IFileAnalysisResult>;
fileConnections: Map<string, IProjectedConnection[]>;
Expand All @@ -22,6 +23,7 @@ export function createWorkspaceIndexEngineState(
cache,
discoveredDirectories: [],
discoveredFiles: [],
filterAccounting: { kind: 'unavailable' },
gitIgnoredPaths: [],
fileAnalysis: new Map(),
fileConnections: new Map(),
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/indexing/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export async function indexCodeGraphyWorkspace(
}, recovery);
}
await persistWorkspaceIndexMetadata({
filterAccounting: discoveryResult.filterAccounting,
pluginBuildSignature,
pluginSignature,
failedPluginIds,
Expand Down
22 changes: 19 additions & 3 deletions packages/core/src/workspace/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'node:path';
import { randomUUID } from 'node:crypto';
import { z } from 'zod';
import { WORKSPACE_ANALYSIS_CACHE_VERSION } from '../analysis/cache';
import type { WorkspaceFilterAccounting } from '../discovery/contracts';
import { looseStringArraySchema } from '../values';
import { getWorkspaceMetaPath } from './paths';
import { getWorkspaceAnalysisDatabasePath } from '../graphCache/database/storage';
Expand All @@ -13,7 +14,7 @@ import {
} from '../graphCache/database/writeCoordination/model';

export interface CodeGraphyWorkspaceMeta {
version: 1;
version: 2;
lastIndexedAt: string | null;
lastIndexedCommit?: string | null;
pluginSignature: string | null;
Expand All @@ -22,11 +23,21 @@ export interface CodeGraphyWorkspaceMeta {
analysisVersion: string | null;
pendingChangedFiles: string[];
failedPluginIds: string[];
filterAccounting: WorkspaceFilterAccounting;
}

const optionalNullableStringSchema = z.union([z.string(), z.null()]).optional().catch(undefined);
const filterAccountingSchema = z.discriminatedUnion('kind', [
z.object({
kind: z.literal('current'),
excludedFileCount: z.number().int().nonnegative(),
gitIgnoredPathCount: z.number().int().nonnegative(),
}),
z.object({ kind: z.literal('unavailable') }),
]);

const codeGraphyWorkspaceMetaSchema = z.looseObject({
version: z.literal(2),
analysisVersion: optionalNullableStringSchema,
lastIndexedAt: optionalNullableStringSchema,
lastIndexedCommit: optionalNullableStringSchema,
Expand All @@ -35,6 +46,7 @@ const codeGraphyWorkspaceMetaSchema = z.looseObject({
pluginSignature: optionalNullableStringSchema,
pluginBuildSignature: optionalNullableStringSchema,
settingsSignature: optionalNullableStringSchema,
filterAccounting: filterAccountingSchema,
}).transform((meta): CodeGraphyWorkspaceMeta => ({
...createDefaultCodeGraphyWorkspaceMeta(),
...(meta.analysisVersion !== undefined ? { analysisVersion: meta.analysisVersion } : {}),
Expand All @@ -45,12 +57,13 @@ const codeGraphyWorkspaceMetaSchema = z.looseObject({
...(meta.settingsSignature !== undefined ? { settingsSignature: meta.settingsSignature } : {}),
pendingChangedFiles: meta.pendingChangedFiles,
failedPluginIds: meta.failedPluginIds,
version: 1,
filterAccounting: meta.filterAccounting,
version: 2,
}));

export function createDefaultCodeGraphyWorkspaceMeta(): CodeGraphyWorkspaceMeta {
return {
version: 1,
version: 2,
lastIndexedAt: null,
lastIndexedCommit: null,
pluginSignature: null,
Expand All @@ -59,6 +72,7 @@ export function createDefaultCodeGraphyWorkspaceMeta(): CodeGraphyWorkspaceMeta
analysisVersion: WORKSPACE_ANALYSIS_CACHE_VERSION,
pendingChangedFiles: [],
failedPluginIds: [],
filterAccounting: { kind: 'unavailable' },
};
}

Expand Down Expand Up @@ -148,6 +162,7 @@ export async function persistCodeGraphyWorkspaceIndexMetadata(
pluginBuildSignature?: string | null;
settingsSignature: string;
failedPluginIds?: readonly string[];
filterAccounting: WorkspaceFilterAccounting;
resolvedChangedFilePaths?: readonly string[];
},
): Promise<void> {
Expand All @@ -171,5 +186,6 @@ export async function persistCodeGraphyWorkspaceIndexMetadata(
failedPluginIds: metadata.failedPluginIds === undefined
? previous.failedPluginIds
: [...metadata.failedPluginIds],
filterAccounting: metadata.filterAccounting,
}));
}
12 changes: 12 additions & 0 deletions packages/core/tests/analysis/workspaceAnalyze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function createSource() {
_completeGraphData: undefined as IGraphData | undefined,
_lastDiscoveredDirectories: [] as string[],
_lastDiscoveredFiles: [] as IDiscoveredFile[],
_filterAccounting: { kind: 'unavailable' as const },
_lastFileAnalysis: new Map(),
_lastFileConnections: new Map<string, IProjectedConnection[]>(),
_lastGitIgnoredPaths: [] as string[],
Expand All @@ -51,6 +52,7 @@ function createDependencies() {
directories: [] as string[],
durationMs: 3,
files: [] as IDiscoveredFile[],
filterAccounting: { kind: 'current' as const, excludedFileCount: 0, gitIgnoredPathCount: 0 },
gitIgnoredPaths: [] as string[],
limitReached: false,
totalFound: 0,
Expand Down Expand Up @@ -134,6 +136,7 @@ describe('pipeline/analysis/analyze', () => {
directories: ['src/new-folder'],
durationMs: 4,
files,
filterAccounting: { kind: 'current', excludedFileCount: 1, gitIgnoredPathCount: 1 },
gitIgnoredPaths: ['src/index.ts'],
limitReached: false,
totalFound: 1,
Expand Down Expand Up @@ -185,6 +188,11 @@ describe('pipeline/analysis/analyze', () => {
new Set<string>(['plugin.python']),
);
expect(source._lastDiscoveredFiles).toEqual(files);
expect(source._filterAccounting).toEqual({
kind: 'current',
excludedFileCount: 1,
gitIgnoredPathCount: 1,
});
expect(source._lastDiscoveredDirectories).toEqual(['src/new-folder']);
expect(source._lastGitIgnoredPaths).toEqual(['src/index.ts']);
expect(source._lastFileAnalysis).toBe(fileAnalysis);
Expand Down Expand Up @@ -254,6 +262,7 @@ describe('pipeline/analysis/analyze', () => {
directories: [],
durationMs: 5,
files: [] as IDiscoveredFile[],
filterAccounting: { kind: 'current', excludedFileCount: 0, gitIgnoredPathCount: 0 },
limitReached: true,
totalFound: 27,
});
Expand All @@ -276,6 +285,7 @@ describe('pipeline/analysis/analyze', () => {
directories: [],
durationMs: 4,
files,
filterAccounting: { kind: 'current', excludedFileCount: 0, gitIgnoredPathCount: 0 },
limitReached: false,
totalFound: 1,
});
Expand Down Expand Up @@ -330,6 +340,7 @@ describe('pipeline/analysis/analyze', () => {
directories: [],
durationMs: 4,
files: [] as IDiscoveredFile[],
filterAccounting: { kind: 'current' as const, excludedFileCount: 0, gitIgnoredPathCount: 0 },
limitReached: false,
totalFound: 0,
};
Expand Down Expand Up @@ -358,6 +369,7 @@ describe('pipeline/analysis/analyze', () => {
directories: [],
durationMs: 2,
files: [] as IDiscoveredFile[],
filterAccounting: { kind: 'current', excludedFileCount: 0, gitIgnoredPathCount: 0 },
limitReached: false,
totalFound: 0,
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/analysis/workspaceDiscovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('pipeline/discovery', () => {
const discover = vi.fn(async () => ({
durationMs: 2,
files: ['src/index.ts'],
filterAccounting: { kind: 'current' as const, excludedFileCount: 0, gitIgnoredPathCount: 0 },
limitReached: false,
totalFound: 1,
}));
Expand Down
36 changes: 36 additions & 0 deletions packages/core/tests/discovery/file/discovery.discover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,45 @@ describe('FileDiscovery discover', () => {
});

expect(result.files.map(file => file.relativePath)).toEqual([path.join('src', 'app.ts')]);
expect(result.filterAccounting).toEqual({
kind: 'current',
excludedFileCount: 1,
gitIgnoredPathCount: 27,
});
expect(onProgress.mock.calls.map(([progress]) => progress.current)).toEqual([1]);
});

it('accounts for mixed TypeScript, Godot, and Unity plugin Filters separately from Git ignored state', async () => {
initGitRepo();
createFile('.gitignore', 'ignored/**\n');
createFile('src/app.ts');
createFile('dist/app.js');
createFile('.godot/editor/project_metadata.cfg');
createFile('Assets/Player.prefab');
createFile('Assets/Player.prefab.meta');
createFile('ProjectSettings/ProjectSettings.asset');
createFile('ignored/generated.ts');

const result = await discovery.discover({
rootPath: tempDir,
filter: [
'**/dist/**',
'**/.godot/**',
'**/*.meta',
'**/[Pp]roject[Ss]ettings/**',
],
});

expect(result.filterAccounting).toEqual({
kind: 'current',
excludedFileCount: 3,
gitIgnoredPathCount: 2,
});
expect(result.files.map(file => file.relativePath)).toContain('src/app.ts');
expect(result.files.map(file => file.relativePath)).toContain('Assets/Player.prefab');
expect(result.gitIgnoredPaths).toContain('ignored');
});

it('uses Git paths without recursively reading ignored or filtered workspace trees', async () => {
initGitRepo();
createFile('.gitignore', 'ignored/**\n');
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/indexing/analysis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('indexing/analysis', () => {
discoveryResult: {
durationMs: 1,
files,
filterAccounting: { kind: 'current', excludedFileCount: 0, gitIgnoredPathCount: 0 },
directories: [],
gitIgnoredPaths: [],
limitReached: false,
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/workspace/meta.concurrent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('workspace metadata concurrency', () => {
reportOwnership?.();
await ownedCommitGate;
await persistCodeGraphyWorkspaceIndexMetadata(workspaceRoot, {
filterAccounting: { kind: 'current', excludedFileCount: 2, gitIgnoredPathCount: 1 },
pluginSignature: 'plugins-sha',
settingsSignature: 'settings-sha',
resolvedChangedFilePaths: ['src/resolved.ts'],
Expand Down
Loading