From 62ecde22f18893fe8f0181cb17e61ec838ce4e15 Mon Sep 17 00:00:00 2001 From: Logan Yang Date: Mon, 23 Dec 2024 18:12:29 -0800 Subject: [PATCH 1/2] Skip empty files and show empty and unindexed files in list files command --- src/main.ts | 41 ++++++++++++++++++++++++++++++----- src/search/indexOperations.ts | 21 +++++++++++------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4ae8b804..fb59acf9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -343,18 +343,49 @@ export default class CopilotPlugin extends Plugin { callback: async () => { try { const indexedFiles = await this.vectorStoreManager.getIndexedFiles(); - if (indexedFiles.length === 0) { - new Notice("No indexed files found."); + const indexedFilePaths = new Set(indexedFiles); + const allMarkdownFiles = this.app.vault.getMarkdownFiles(); + const emptyFiles = new Set(); + const unindexedFiles = new Set(); + + // Categorize files + for (const file of allMarkdownFiles) { + const content = await this.app.vault.cachedRead(file); + if (!content || content.trim().length === 0) { + emptyFiles.add(file.path); + } else if (!indexedFilePaths.has(file.path)) { + unindexedFiles.add(file.path); + } + } + + if (indexedFiles.length === 0 && emptyFiles.size === 0 && unindexedFiles.size === 0) { + new Notice("No files found to list."); return; } // Create content for the file const content = [ - "# Copilot Indexed Files", - `Total files indexed: ${indexedFiles.length}`, + "# Copilot Files Status", + `- Indexed files: ${indexedFiles.length}`, + `- Unindexed files: ${unindexedFiles.size}`, + `- Empty files: ${emptyFiles.size}`, "", - "## Files", + "## Indexed Files", ...indexedFiles.map((file) => `- [[${file}]]`), + "", + "## Unindexed Files", + ...(unindexedFiles.size > 0 + ? Array.from(unindexedFiles) + .sort() + .map((file) => `- [[${file}]]`) + : ["No unindexed files found."]), + "", + "## Empty Files", + ...(emptyFiles.size > 0 + ? Array.from(emptyFiles) + .sort() + .map((file) => `- [[${file}]]`) + : ["No empty files found."]), ].join("\n"); // Create or update the file in the vault diff --git a/src/search/indexOperations.ts b/src/search/indexOperations.ts index 7cfd26fe..da555a36 100644 --- a/src/search/indexOperations.ts +++ b/src/search/indexOperations.ts @@ -249,28 +249,33 @@ export class IndexOperations { // Get all markdown files that should be indexed under current rules const allMarkdownFiles = this.app.vault.getMarkdownFiles(); const filesToIndex = new Set(); + const emptyFiles = new Set(); for (const file of allMarkdownFiles) { - // Always skip excluded files + // Skip excluded files if (excludedFiles.has(file.path)) { continue; } + // Check actual content + const content = await this.app.vault.cachedRead(file); + if (!content || content.trim().length === 0) { + emptyFiles.add(file.path); + continue; + } + const shouldBeIndexed = includedFiles.size === 0 || includedFiles.has(file.path); + const isIndexed = indexedFilePaths.has(file.path); - if (shouldBeIndexed) { - // Add file if: - // 1. It's not currently indexed but should be (newly included) - // 2. It's indexed but has been modified since last index - if (!indexedFilePaths.has(file.path) || file.stat.mtime > latestMtime) { - filesToIndex.add(file); - } + if (shouldBeIndexed && (!isIndexed || file.stat.mtime > latestMtime)) { + filesToIndex.add(file); } } if (getSettings().debug) { console.log(`Files to index: ${filesToIndex.size}`); console.log(`Previously indexed: ${indexedFilePaths.size}`); + console.log(`Empty files skipped: ${emptyFiles.size}`); } return Array.from(filesToIndex); From ffbce01c23d36b4575fab1a79bc2a1ea35db42a0 Mon Sep 17 00:00:00 2001 From: Logan Yang Date: Mon, 23 Dec 2024 18:20:17 -0800 Subject: [PATCH 2/2] Add more partitions --- src/settings/components/QASettings.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/settings/components/QASettings.tsx b/src/settings/components/QASettings.tsx index 1a2d2509..6525571b 100644 --- a/src/settings/components/QASettings.tsx +++ b/src/settings/components/QASettings.tsx @@ -139,7 +139,24 @@ const QASettings: React.FC = ({ vectorStoreManager }) => { 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!" value={settings.numPartitions.toString()} onChange={handlePartitionsChange} - options={["1", "2", "3", "4", "5", "6", "7", "8"]} + options={[ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "12", + "16", + "20", + "24", + "28", + "32", + "36", + "40", + ]} />