Skip to content

Commit 31a74af

Browse files
committed
finder
1 parent 34d3784 commit 31a74af

File tree

29 files changed

+336
-250
lines changed

29 files changed

+336
-250
lines changed

'

Lines changed: 0 additions & 178 deletions
This file was deleted.

TODO.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TODO
2+
3+
- [ ] remove `tool.telescope` and `tool.trouble` mods

lua/down.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ local down = {
1313
event = require("down.event"),
1414
util = require("down.util"),
1515
log = require("down.util.log"),
16-
trouble = require("trouble.providers.down"),
17-
telescope = require("telescope._extensions.down"),
1816
}
1917

2018
--- Load the user configuration, and load into config

lua/down/config.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ function Config:check_tests(mods)
133133
end
134134
end
135135

136+
---@param mod down.Mod.Mod`
137+
---@return boolean
136138
function Config.check_mod_test(mod)
137-
return mod
138-
and mod.id
139+
return mod ~= nil
140+
and mod.id ~= nil
139141
and modconf.check_id(mod.id)
140142
and type(mod) == "table"
141-
and mod.tests
143+
and mod.tests ~= nil
142144
and type(mod.tests) == "table"
143145
and not vim.tbl_isempty(mod.tests)
144146
end

lua/down/mod.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ Mod.mods = {}
105105

106106
Mod.default = {
107107
mods = {
108-
"tool.telescope",
108+
-- "tool.telescope",
109+
"find",
109110
"note",
110111
"workspace",
111112
},

lua/down/mod/find/fzflua/init.lua

Whitespace-only changes.

lua/down/mod/find/init.lua

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
local mod = require("down.mod")
2+
3+
---@alias down.mod.find.Finder "telescope" | "mini" | "snacks" | "fzflua" | "builtin"
4+
5+
local has_telescope, telescope = pcall(require, "telescope")
6+
local has_mini, mini = pcall(require, "mini.pick")
7+
local has_snacks, snacks = pcall(require, "mini.snacks")
8+
local has_fzflua, fzflua = pcall(require, "fzflua")
9+
10+
---@class down.mod.find.Find: down.Mod
11+
local F = mod.new("find")
12+
13+
---@class down.mod.find.Config: down.mod.Config
14+
---@field public default? down.mod.find.Finder The default finder
15+
---@field public finders? down.mod.find.Finder[] The default finder
16+
F.config = {
17+
default = nil,
18+
finders = nil,
19+
enabled = true,
20+
}
21+
22+
---@alias down.mod.find.Picker
23+
---| 'file'
24+
---| 'link'
25+
---| 'tag'
26+
---| 'workspace'
27+
---| 'task'
28+
---| 'note'
29+
---| 'template'
30+
---| 'markdown'
31+
---| 'project'
32+
33+
---@param n down.mod.find.Picker
34+
---@return fun()|table
35+
F.picker = function(n)
36+
local p = require("down.mod.find." .. F.config.default)
37+
if p and p.picker then F.picker = p.picker end
38+
if n and p.down and p.down[n] then
39+
if type(p.down[n]) == 'function' then
40+
return p.down[n]
41+
end
42+
end
43+
return p
44+
end
45+
46+
---@class down.mod.find.telescope.Commands: { [string]: down.Command }
47+
F.commands = {
48+
find = {
49+
args = 0,
50+
name = "find",
51+
enabled = true,
52+
callback = function(e) F.picker("file")() end,
53+
commands = {
54+
tags = {
55+
callback = function(e) F.picker("tag")()end,
56+
enabled = false,
57+
name = "find.links",
58+
args = 0,
59+
},
60+
project = {
61+
callback = function(e) F.picker("project")()end,
62+
enabled = false,
63+
name = "find.links",
64+
args = 0,
65+
},
66+
notes = {
67+
callback = function(e) F.picker("note")()end,
68+
enabled = false,
69+
name = "find.links",
70+
args = 0,
71+
},
72+
links = {
73+
callback = function(e) F.picker("link") ()end,
74+
enabled = true,
75+
name = "find.links",
76+
args = 0,
77+
},
78+
tasks = {
79+
callback = function(e) F.picker("task")()end,
80+
enabled = true,
81+
name = "find.tags",
82+
args = 0,
83+
},
84+
files = {
85+
callback = function(e)F.picker("file")()end,
86+
enabled = true,
87+
name = "find.files",
88+
args = 0,
89+
},
90+
workspace = {
91+
callback = function(e)F.picker("workspace")()end,
92+
enabled = true,
93+
name = "find.workspace",
94+
args = 0,
95+
},
96+
},
97+
},
98+
}
99+
100+
---@class down.mod.find.Maps: { [string]: down.Map }
101+
F.maps = {
102+
{ "n", ",dF", "<cmd>Down find file<CR>", "Down find files" },
103+
{ "n", ",dm", "<cmd>Down find markdown<CR>", "Down find md files" },
104+
{ "n", ",dL", "<cmd>Down find link<CR>", "Down find links" },
105+
{
106+
"n",
107+
",dW",
108+
"<cmd>Down find workspace<CR>",
109+
"Down find workspaces",
110+
},
111+
}
112+
113+
F.data = {}
114+
115+
F.load = function()
116+
if not F.config.finders then
117+
F.config.finders = { "builtin" }
118+
if has_telescope then
119+
table.insert(F.config.finders, "telescope")
120+
end
121+
if has_mini then
122+
table.insert(F.config.finders, "mini")
123+
end
124+
if has_snacks then
125+
table.insert(F.config.finders, "snacks")
126+
end
127+
if has_fzflua then
128+
table.insert(F.config.finders, "fzflua")
129+
end
130+
end
131+
if not F.config.default then
132+
if #F.config.finders > 0 then
133+
if vim.list_contains(F.config.finders, "telescope") then
134+
F.config.default = "telescope"
135+
else
136+
F.config.default = F.config.finders[1]
137+
end
138+
else
139+
table.insert(F.config.finders, "builtin")
140+
F.config.default = "builtin"
141+
end
142+
end
143+
F.picker = require("down.mod.find." .. F.config.default).picker
144+
vim.print(F)
145+
end
146+
147+
F.setup = function()
148+
return {
149+
loaded = true,
150+
dependencies = F.config.finders,
151+
}
152+
end
153+
154+
F.post_load = function()
155+
vim.print("FIND POST LOAD")
156+
end
157+
158+
return F

lua/down/mod/find/mini/init.lua

Whitespace-only changes.

lua/down/mod/find/snacks/init.lua

Whitespace-only changes.

0 commit comments

Comments
 (0)