Skip to content

Commit dd58b40

Browse files
authored
Skip empty files in indexing, add more partitions (#964)
* Skip empty files and show empty and unindexed files in list files command * Add more partitions
1 parent 7fc3cfa commit dd58b40

File tree

3 files changed

+67
-14
lines changed

3 files changed

+67
-14
lines changed

src/main.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,49 @@ export default class CopilotPlugin extends Plugin {
343343
callback: async () => {
344344
try {
345345
const indexedFiles = await this.vectorStoreManager.getIndexedFiles();
346-
if (indexedFiles.length === 0) {
347-
new Notice("No indexed files found.");
346+
const indexedFilePaths = new Set(indexedFiles);
347+
const allMarkdownFiles = this.app.vault.getMarkdownFiles();
348+
const emptyFiles = new Set<string>();
349+
const unindexedFiles = new Set<string>();
350+
351+
// Categorize files
352+
for (const file of allMarkdownFiles) {
353+
const content = await this.app.vault.cachedRead(file);
354+
if (!content || content.trim().length === 0) {
355+
emptyFiles.add(file.path);
356+
} else if (!indexedFilePaths.has(file.path)) {
357+
unindexedFiles.add(file.path);
358+
}
359+
}
360+
361+
if (indexedFiles.length === 0 && emptyFiles.size === 0 && unindexedFiles.size === 0) {
362+
new Notice("No files found to list.");
348363
return;
349364
}
350365

351366
// Create content for the file
352367
const content = [
353-
"# Copilot Indexed Files",
354-
`Total files indexed: ${indexedFiles.length}`,
368+
"# Copilot Files Status",
369+
`- Indexed files: ${indexedFiles.length}`,
370+
`- Unindexed files: ${unindexedFiles.size}`,
371+
`- Empty files: ${emptyFiles.size}`,
355372
"",
356-
"## Files",
373+
"## Indexed Files",
357374
...indexedFiles.map((file) => `- [[${file}]]`),
375+
"",
376+
"## Unindexed Files",
377+
...(unindexedFiles.size > 0
378+
? Array.from(unindexedFiles)
379+
.sort()
380+
.map((file) => `- [[${file}]]`)
381+
: ["No unindexed files found."]),
382+
"",
383+
"## Empty Files",
384+
...(emptyFiles.size > 0
385+
? Array.from(emptyFiles)
386+
.sort()
387+
.map((file) => `- [[${file}]]`)
388+
: ["No empty files found."]),
358389
].join("\n");
359390

360391
// Create or update the file in the vault

src/search/indexOperations.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,28 +249,33 @@ export class IndexOperations {
249249
// Get all markdown files that should be indexed under current rules
250250
const allMarkdownFiles = this.app.vault.getMarkdownFiles();
251251
const filesToIndex = new Set<TFile>();
252+
const emptyFiles = new Set<string>();
252253

253254
for (const file of allMarkdownFiles) {
254-
// Always skip excluded files
255+
// Skip excluded files
255256
if (excludedFiles.has(file.path)) {
256257
continue;
257258
}
258259

260+
// Check actual content
261+
const content = await this.app.vault.cachedRead(file);
262+
if (!content || content.trim().length === 0) {
263+
emptyFiles.add(file.path);
264+
continue;
265+
}
266+
259267
const shouldBeIndexed = includedFiles.size === 0 || includedFiles.has(file.path);
268+
const isIndexed = indexedFilePaths.has(file.path);
260269

261-
if (shouldBeIndexed) {
262-
// Add file if:
263-
// 1. It's not currently indexed but should be (newly included)
264-
// 2. It's indexed but has been modified since last index
265-
if (!indexedFilePaths.has(file.path) || file.stat.mtime > latestMtime) {
266-
filesToIndex.add(file);
267-
}
270+
if (shouldBeIndexed && (!isIndexed || file.stat.mtime > latestMtime)) {
271+
filesToIndex.add(file);
268272
}
269273
}
270274

271275
if (getSettings().debug) {
272276
console.log(`Files to index: ${filesToIndex.size}`);
273277
console.log(`Previously indexed: ${indexedFilePaths.size}`);
278+
console.log(`Empty files skipped: ${emptyFiles.size}`);
274279
}
275280

276281
return Array.from(filesToIndex);

src/settings/components/QASettings.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,24 @@ const QASettings: React.FC<QASettingsProps> = ({ vectorStoreManager }) => {
139139
description="Number of partitions for Copilot index. Default is 1. Increase if you have issues indexing large vaults. Warning: Changes require clearing and rebuilding the index!"
140140
value={settings.numPartitions.toString()}
141141
onChange={handlePartitionsChange}
142-
options={["1", "2", "3", "4", "5", "6", "7", "8"]}
142+
options={[
143+
"1",
144+
"2",
145+
"3",
146+
"4",
147+
"5",
148+
"6",
149+
"7",
150+
"8",
151+
"12",
152+
"16",
153+
"20",
154+
"24",
155+
"28",
156+
"32",
157+
"36",
158+
"40",
159+
]}
143160
/>
144161
<TextAreaComponent
145162
name="Exclusions"

0 commit comments

Comments
 (0)