From adb04d2e43933b63049169634aafb7ec83ffd212 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Nov 2025 04:50:05 +0000 Subject: [PATCH] debug(obsidian): add logging to diagnose nested folder display issue - Add debug logging to getVaultFiles() to show file counts - Add logging to listAllNotes() to show processing details - Add logging to buildFolderTree() to trace folder creation - Filter .md files in getVaultFiles() for better performance - Log sample file paths to help diagnose API response format This will help identify why nested folders aren't appearing in the folder tree browser. --- modules/io/obsidian-bridge.js | 16 +++++++++++++++- modules/ui/obsidian-notes-editor.js | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/io/obsidian-bridge.js b/modules/io/obsidian-bridge.js index a2874726..af867320 100644 --- a/modules/io/obsidian-bridge.js +++ b/modules/io/obsidian-bridge.js @@ -79,7 +79,15 @@ const ObsidianBridge = (() => { } const data = await response.json(); - return data.files || []; + const files = data.files || []; + + // Filter to only .md files + const mdFiles = files.filter(f => f.endsWith(".md")); + + INFO && console.log(`getVaultFiles: Found ${files.length} total files, ${mdFiles.length} markdown files`); + DEBUG && console.log("Sample files:", mdFiles.slice(0, 10)); + + return mdFiles; } catch (error) { ERROR && console.error("Failed to get vault files:", error); throw error; @@ -435,6 +443,8 @@ Add your lore here... const allFiles = await getVaultFiles(); const notes = []; + INFO && console.log(`listAllNotes: Processing ${allFiles.length} files`); + for (const filePath of allFiles) { try { const content = await getNote(filePath); @@ -453,6 +463,10 @@ Add your lore here... // Sort by path notes.sort((a, b) => a.path.localeCompare(b.path)); + + INFO && console.log(`listAllNotes: Returning ${notes.length} notes`); + DEBUG && console.log("Sample note paths:", notes.slice(0, 5).map(n => n.path)); + return notes; } diff --git a/modules/ui/obsidian-notes-editor.js b/modules/ui/obsidian-notes-editor.js index 07500096..126b179d 100644 --- a/modules/ui/obsidian-notes-editor.js +++ b/modules/ui/obsidian-notes-editor.js @@ -360,13 +360,18 @@ async function promptCreateNewNote(elementId, elementType, coordinates) { function buildFolderTree(notes) { const root = {folders: {}, files: []}; + INFO && console.log(`buildFolderTree: Processing ${notes.length} notes`); + notes.forEach((note, index) => { const parts = note.path.split("/"); const fileName = parts[parts.length - 1]; + DEBUG && console.log(`Processing note ${index}: ${note.path} (${parts.length} parts)`); + if (parts.length === 1) { // Root level file root.files.push({name: fileName, index, path: note.path}); + DEBUG && console.log(` -> Added to root files: ${fileName}`); } else { // Navigate/create folder structure let current = root; @@ -374,14 +379,18 @@ function buildFolderTree(notes) { const folderName = parts[i]; if (!current.folders[folderName]) { current.folders[folderName] = {folders: {}, files: []}; + DEBUG && console.log(` -> Created folder: ${folderName}`); } current = current.folders[folderName]; } // Add file to final folder current.files.push({name: fileName, index, path: note.path}); + DEBUG && console.log(` -> Added to folder: ${fileName}`); } }); + INFO && console.log("Folder tree structure:", root); + return root; }