fix: improve graph path handling and error messages

- Handle nil idea_dir in config (don't override default with nil)
- Expand environment variables and ~ in paths during setup
- Add get_idea_dir() helper function for consistent path access
- Remove trailing slashes from paths
- Add fallback to non-recursive glob if recursive finds no files
- Show actual path being used in error messages for debugging
- Better error messages when directory doesn't exist or has no .md files
This commit is contained in:
2026-01-10 23:06:46 -05:00
parent 937f20b892
commit c706e8ee4f
3 changed files with 62 additions and 6 deletions

View File

@@ -92,13 +92,45 @@ end
---Builds the complete graph from markdown files
---@return GraphData
function M.build_graph()
local idea_dir = config.options.idea_dir
-- Get idea_dir using the getter function if available, otherwise direct access
local idea_dir = config.get_idea_dir and config.get_idea_dir() or config.options.idea_dir
local graph = types.create_graph_data()
-- Find all markdown files
local files = vim.fn.glob(idea_dir .. "/**/*.md", false, true)
-- Validate idea_dir
if not idea_dir or idea_dir == "" then
vim.notify("❌ idea_dir is not configured. Please set it in setup().", vim.log.levels.ERROR)
return graph
end
-- Expand any environment variables or ~ in path (in case getter wasn't used)
idea_dir = vim.fn.expand(idea_dir)
-- Remove trailing slash if present
idea_dir = idea_dir:gsub("/$", "")
-- Check if directory exists
if vim.fn.isdirectory(idea_dir) == 0 then
vim.notify("❌ idea_dir does not exist: " .. idea_dir, vim.log.levels.ERROR)
return graph
end
-- Find all markdown files (try recursive first, then flat)
local glob_pattern = idea_dir .. "/**/*.md"
local files = vim.fn.glob(glob_pattern, false, true)
-- Fallback: try non-recursive if recursive finds nothing
if #files == 0 then
local files_flat = vim.fn.glob(idea_dir .. "/*.md", false, true)
if #files_flat > 0 then
files = files_flat
end
end
if #files == 0 then
vim.notify(
string.format("📂 No .md files found in: %s", idea_dir),
vim.log.levels.WARN
)
return graph
end