1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
local pickers = require "telescope.pickers"
local finders = require "telescope.finders"
local previewers = require "telescope.previewers"
local utils = require "telescope.utils"
local actions = require "telescope.actions"
local action_state = require "telescope.actions.state"
local conf = require("telescope.config").values
local M = {}
local function getNavCmds()
return vim.call("projectionist#navigation_commands")
end
local function getPaths(type)
return getNavCmds()[type]
end
M.find = function (opts)
opts = opts or {}
opts.path_display = utils.get_default(opts.path_display, "hidden")
opts.ignore_filename = utils.get_default(opts.ignore_filename, true)
opts.include_extensions = utils.get_default(opts.include_extensions, false)
local results = {}
for type, _ in pairs(getNavCmds()) do
table.insert(results, {
filename = type,
text = type,
})
end
-- print(vim.inspect(results))
pickers.new(opts, {
promt_title = type,
finder = finders.new_table {
results = results,
entry_maker = function(entry)
return {
value = entry,
text = entry.text,
display = entry.text,
ordinal = entry.text,
filename = entry.filename,
}
end,
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
return
end
actions._close(prompt_bufnr, true)
M.findByType(selection.value.filename, opts)
end)
return true
end,
}):find()
end
M.findByType = function(type, opts)
opts = opts or {}
opts.path_display = utils.get_default(opts.path_display, "hidden")
opts.ignore_filename = utils.get_default(opts.ignore_filename, true)
opts.include_extensions = utils.get_default(opts.include_extensions, false)
local paths = getPaths(type)
local results = {}
for _, location in pairs(paths) do
local path = location[1] .. '/' .. location[2]
local findings = vim.call("projectionist#glob", path:gsub('*', '**/*'))
for _, find in ipairs(findings) do
table.insert(results, {
filename = find,
text = find,
})
end
end
-- print(vim.inspect(results))
pickers.new(opts, {
promt_title = type,
finder = finders.new_table {
results = results,
entry_maker = function(entry)
return {
value = entry,
text = entry.text,
display = entry.text,
ordinal = entry.text,
filename = entry.filename,
}
end,
},
previewer = previewers.builtin.new(opts),
sorter = conf.generic_sorter(opts),
}):find()
end
return M
|