-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtelescope.lua
More file actions
80 lines (70 loc) · 2.17 KB
/
Copy pathtelescope.lua
File metadata and controls
80 lines (70 loc) · 2.17 KB
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
--- ### Frontend for compiler.nvim
local M = {}
function M.show()
local picker_util = require("compiler.picker-util")
-- Validate working directory
if not picker_util.validate_working_directory() then return end
-- Dependencies
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local state = require("telescope.actions.state")
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
-- Prepare compiler options
local compiler_data = picker_util.prepare_compiler_options()
local language = compiler_data.language
local language_options = compiler_data.options
local filetype = compiler_data.filetype
-- RUN ACTION ON SELECTED
-- ========================================================================
--- On option selected → Run action depending of the language.
local function on_option_selected(prompt_bufnr)
actions.close(prompt_bufnr) -- Close Telescope on selection
local selection = state.get_selected_entry()
if selection then
picker_util.execute_selection(
selection.value,
selection.display,
language_options,
language,
filetype
)
end
end
-- SHOW TELESCOPE
-- ========================================================================
local function open_telescope()
pickers
.new({}, {
prompt_title = "Compiler",
results_title = "Options",
finder = finders.new_table({
results = language_options,
entry_maker = function(entry)
return {
display = entry.text,
value = entry.value,
ordinal = entry.text,
}
end,
}),
sorter = conf.generic_sorter(),
attach_mappings = function(_, map)
map(
"i",
"<CR>",
function(prompt_bufnr) on_option_selected(prompt_bufnr) end
)
map(
"n",
"<CR>",
function(prompt_bufnr) on_option_selected(prompt_bufnr) end
)
return true
end,
})
:find()
end
open_telescope() -- Entry point
end
return M