Skip to content

Commit

Permalink
Handle more cases when browsing trees
Browse files Browse the repository at this point in the history
  • Loading branch information
kentookura committed Jan 26, 2024
1 parent 580b46a commit 8fdb1a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lua/forester.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ local function setup(config)
config = { opts = { tree_dirs = "trees" } }
end

require("cmp").register_source("forester", CompletionSource)
require("cmp").setup({
sources = { { name = "forester" } },
local cmp = require("cmp")

cmp.register_source("forester", CompletionSource)
cmp.setup({
sources = { { name = "forester", dup = 0 } },
})

local opts = config.opts
Expand Down
22 changes: 20 additions & 2 deletions lua/forester/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function M.parse(args)
end

local function available_tree_dirs(opts)
local configured_tree_dirs = util.map(opts.tree_dirs, function(dir)
local tree_dirs = opts.tree_dirs or { "trees" }
local configured_tree_dirs = util.map(tree_dirs, function(dir)
return "./" .. Path:new({ dir, sep = "/" }):normalize()
end)

Expand Down Expand Up @@ -86,11 +87,28 @@ M.commands = {
all_trees[k] = v
end
end
navigation.pick_tree(all_trees, {})
if #all_trees == 0 then
do
vim.print("No trees found!")
end
elseif #all_trees == 1 then
do
local path = all_trees[1].addr .. ".tree"
vim.print("Only found one tree. Opening...")
vim.cmd("edit " .. vim.fn.findfile(path))
end
else
do
navigation.pick_tree(all_trees, {})
end
end
end,

new = function(opts)
local prefixes = all_prefixes(opts)

-- if #prefixes = 0 then do

vim.ui.select(prefixes, { -- TODO: Don't select when #all_prefixes == 1
format_item = function(item)
return item.prefix
Expand Down

0 comments on commit 8fdb1a7

Please sign in to comment.