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

@@ -31,7 +31,25 @@ M.options = {
---@param user_opts IdeaDropOptions|nil User configuration options
---@return nil
function M.setup(user_opts)
M.options = vim.tbl_deep_extend("force", M.options, user_opts or {})
user_opts = user_opts or {}
-- Handle nil idea_dir (don't override default with nil)
if user_opts.idea_dir == nil then
user_opts.idea_dir = M.options.idea_dir
end
-- Expand environment variables and ~ in idea_dir
if user_opts.idea_dir then
user_opts.idea_dir = vim.fn.expand(user_opts.idea_dir)
end
M.options = vim.tbl_deep_extend("force", M.options, user_opts)
end
---Gets the idea directory path (expanded)
---@return string
function M.get_idea_dir()
return vim.fn.expand(M.options.idea_dir or "")
end
return M

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

View File

@@ -437,11 +437,17 @@ function M.open(opts)
vim.api.nvim_win_set_option(state.win, "cursorline", false)
-- Build graph data
vim.notify("Building graph...", vim.log.levels.INFO)
local config = require("ideaDrop.core.config")
local idea_dir = vim.fn.expand(config.options.idea_dir or "")
vim.notify(string.format("Building graph from: %s", idea_dir), vim.log.levels.INFO)
state.graph = data.build_graph()
if #state.graph.node_list == 0 then
vim.notify("No notes found to visualize", vim.log.levels.WARN)
vim.notify(
string.format("No notes found to visualize in: %s", idea_dir),
vim.log.levels.WARN
)
M.close()
return
end