forked from rafi/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelescope.lua
More file actions
182 lines (155 loc) · 4.92 KB
/
telescope.lua
File metadata and controls
182 lines (155 loc) · 4.92 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
local myactions = {}
function myactions.send_to_qflist(prompt_bufnr)
require("telescope.actions").send_to_qflist(prompt_bufnr)
vim.api.nvim_command([[ botright copen ]])
end
function myactions.smart_send_to_qflist(prompt_bufnr)
require("telescope.actions").smart_send_to_qflist(prompt_bufnr)
vim.api.nvim_command([[ botright copen ]])
end
--- Scroll the results window up
---@param prompt_bufnr number: The prompt bufnr
function myactions.results_scrolling_up(prompt_bufnr)
myactions.scroll_results(prompt_bufnr, -1)
end
--- Scroll the results window down
---@param prompt_bufnr number: The prompt bufnr
function myactions.results_scrolling_down(prompt_bufnr)
myactions.scroll_results(prompt_bufnr, 1)
end
---@param prompt_bufnr number: The prompt bufnr
---@param direction number: 1|-1
function myactions.scroll_results(prompt_bufnr, direction)
local status = require("telescope.state").get_status(prompt_bufnr)
local default_speed = vim.api.nvim_win_get_height(status.results_win) / 2
local speed = status.picker.layout_config.scroll_speed or default_speed
require("telescope.actions.set").shift_selection(prompt_bufnr, math.floor(speed) * direction)
end
-- Custom pickers
local plugin_directories = function(opts)
local actions = require("telescope.actions")
local utils = require("telescope.utils")
local dir = vim.fn.stdpath("data") .. "/lazy"
opts = opts or {}
opts.cmd = vim.F.if_nil(opts.cmd, {
vim.o.shell,
"-c",
"find " .. vim.fn.shellescape(dir) .. " -mindepth 1 -maxdepth 1 -type d",
})
local dir_len = dir:len()
opts.entry_maker = function(line)
return {
value = line,
ordinal = line,
display = line:sub(dir_len + 2),
}
end
require("telescope.pickers")
.new(opts, {
layout_config = {
width = 0.65,
height = 0.7,
},
prompt_title = "[ Plugin directories ]",
finder = require("telescope.finders").new_table({
results = utils.get_os_command_output(opts.cmd),
entry_maker = opts.entry_maker,
}),
sorter = require("telescope.sorters").get_fuzzy_file(),
previewer = require("telescope.previewers.term_previewer").cat.new(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local entry = require("telescope.actions.state").get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd.lcd(entry.value)
end)
return true
end,
})
:find()
end
-- Custom window-sizes
---@param dimensions table
---@param size integer
---@return float
local function get_matched_ratio(dimensions, size)
for min_cols, scale in pairs(dimensions) do
if min_cols == "lower" or size >= min_cols then
return math.floor(size * scale)
end
end
return dimensions.lower
end
local function width_tiny(_, cols, _)
return get_matched_ratio({ [180] = 0.27, lower = 0.37 }, cols)
end
local function width_small(_, cols, _)
return get_matched_ratio({ [180] = 0.4, lower = 0.5 }, cols)
end
local function width_medium(_, cols, _)
return get_matched_ratio({ [180] = 0.5, [110] = 0.6, lower = 0.75 }, cols)
end
local function width_large(_, cols, _)
return get_matched_ratio({ [180] = 0.7, [110] = 0.8, lower = 0.85 }, cols)
end
-- Enable indent-guides in telescope preview
vim.api.nvim_create_autocmd("User", {
pattern = "TelescopePreviewerLoaded",
group = vim.api.nvim_create_augroup("rafi_telescope", {}),
callback = function(args)
if args.buf ~= vim.api.nvim_win_get_buf(0) then
return
end
vim.opt_local.listchars = vim.wo.listchars .. ",tab:▏\\ "
vim.opt_local.conceallevel = 0
vim.opt_local.wrap = true
vim.opt_local.list = true
vim.opt_local.number = true
end,
})
return {
{
"nvim-telescope/telescope.nvim",
dependencies = {
"stevearc/aerial.nvim",
"nvim-treesitter/nvim-treesitter",
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
},
keys = {
{
"<leader>co",
"<cmd>Telescope aerial<cr>",
desc = "Code Outline",
},
},
opts = {
defaults = {
border = {},
prompt_prefix = " ", -- ❯
},
},
config = function(_, opts)
require("telescope").setup(opts)
require("telescope").load_extension("aerial")
-- Highlights
local fg_bg = require("utils").fg_bg
local bg = require("utils").bg
local fg = require("utils").fg
local colors = require("plugins.colorscheme.nord.named_colors")
fg_bg("TelescopePromptPrefix", colors.red, colors.black2)
bg("TelescopeNormal", colors.darker_black)
fg_bg("TelescopePreviewTitle", colors.black, colors.green)
fg_bg("TelescopePromptTitle", colors.black, colors.red)
fg_bg("TelescopeSelection", colors.white, colors.black2)
fg_bg("TelescopeBorder", colors.darker_black, colors.darker_black)
fg_bg("TelescopePromptBorder", colors.black2, colors.black2)
fg_bg("TelescopePromptNormal", colors.white, colors.black2)
fg_bg("TelescopeResultsTitle", colors.darker_black, colors.darker_black)
fg_bg("TelescopePromptPrefix", colors.red, colors.black2)
end,
},
{
"stevearc/aerial.nvim",
config = true,
},
}