-
-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathui.lua
More file actions
359 lines (318 loc) · 12.6 KB
/
Copy pathui.lua
File metadata and controls
359 lines (318 loc) · 12.6 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
--- ### UI toggle functions.
-- DESCRIPTION:
-- While you could technically delete this file, we encourage you
-- to keep it as it takes a lot of complexity out of `../4-mappings.lua`.
-- Functions:
-- -> set_tabulation
-- -> toggle_animations
-- -> toggle_autoformat
-- -> toggle_autopairs
-- -> toggle_background
-- -> toggle_buffer_inlay_hints
-- -> toggle_buffer_syntax
-- -> toggle_codelens
-- -> toggle_coverage_signs
-- -> toggle_css_colors
-- -> toggle_cmp
-- -> toggle_conceal
-- -> toggle_diagnostics
-- -> toggle_foldcolumn
-- -> toggle_inlay_hints
-- -> toggle_buffer_semantic_tokens
-- -> toggle_line_numbers
-- -> toggle_lsp_signature
-- -> toggle_paste
-- -> toggle_signcolumn
-- -> toggle_spell
-- -> toggle_statusline
-- -> toggle_tabline
-- -> toggle_ui_notifications
-- -> toggle_url_hl
-- -> toggle_wrap
-- -> toggle_zen_mode
local M = {}
local utils = require("base.utils")
local function bool2str(bool) return bool and "ON" or "OFF" end
--- Set tabulation value for the current buffer.
--- Enter a positive number to set tabulation to n spaces.
--- Or enter a negative number to set tabulation to n tabs.
---
--- NOTE: It will also be used when you autoformat your code.
function M.set_tabulation()
local input_avail, input = pcall(vim.fn.input, "[Tabulation] \n\n- Enter a possitive number to use spaces.\nOr\n- Enter a negative number to use tabs.\n\nThe value will be used when you press TAB for the current buffer, and also when you format your code.\n\nValue: ")
if input_avail then
local indent = tonumber(input)
if not indent or indent == 0 then return end
vim.bo.expandtab = (indent > 0) -- local to buffer
indent = math.abs(indent)
vim.bo.tabstop = indent -- local to buffer
vim.bo.softtabstop = indent -- local to buffer
vim.bo.shiftwidth = indent -- local to buffer
utils.notify(string.format("Buffer [Indent]: `%d`, [Expand tab]`%s`", indent, vim.bo.expandtab and "expandtab" or "noexpandtab"))
end
end
--- Toggle animations
function M.toggle_animations()
if vim.g.minianimate_disable then
vim.g.minianimate_disable = false
else
vim.g.minianimate_disable = true
end
local state = vim.g.minianimate_disable
utils.notify(string.format("Global [Animations]: `%s`", bool2str(not state)))
end
--- Toggle auto format
function M.toggle_autoformat()
vim.g.autoformat_enabled = not vim.g.autoformat_enabled
utils.notify(string.format("Global [Autoformat]: `%s`", bool2str(vim.g.autoformat_enabled)))
end
--- Toggle autopairs
function M.toggle_autopairs()
if not utils.is_available("nvim-autopairs") then -- guard clause
utils.notify("Plugin 'autopairs.nvim' not available")
return
end
local autopairs = require("nvim-autopairs")
if autopairs.state.disabled then
autopairs.enable()
else
autopairs.disable()
end
vim.g.autopairs_enabled = not autopairs.state.disabled
utils.notify(string.format("Global [Autopairs]: `%s`", bool2str(not autopairs.state.disabled)))
end
--- Toggle background="dark"|"light"
--- It will only work if your colorscheme implements this feature.
function M.toggle_background()
vim.go.background = vim.go.background == "light" and "dark" or "light"
utils.notify(string.format("Global [background]: `%s`", vim.go.background))
end
--- Toggle buffer local auto format
--- @param bufnr? number the buffer to toggle `autoformat` on.
function M.toggle_buffer_autoformat(bufnr)
bufnr = bufnr or 0
local old_val = vim.b[bufnr].autoformat_enabled
if old_val == nil then old_val = vim.g.autoformat_enabled end
vim.b[bufnr].autoformat_enabled = not old_val
utils.notify(string.format("Buffer [Autoformat]: `%s`", bool2str(vim.b[bufnr].autoformat_enabled)))
end
--- Toggle LSP inlay hints (buffer)
--- @param bufnr? number the buffer to toggle the `inlay hints` on.
function M.toggle_buffer_inlay_hints(bufnr)
bufnr = bufnr or 0
vim.b[bufnr].inlay_hints_enabled = not vim.b[bufnr].inlay_hints_enabled
vim.lsp.inlay_hint.enable(vim.b[bufnr].inlay_hints_enabled, { bufnr = bufnr })
utils.notify(string.format("Buffer [Inlay hints]: `%s`", bool2str(vim.b[bufnr].inlay_hints_enabled)))
end
--- Toggle buffer semantic token highlighting for all language servers that support it
--- @param bufnr? number the buffer to toggle `semantic tokens` on.
function M.toggle_buffer_semantic_tokens(bufnr)
bufnr = bufnr or 0
vim.b[bufnr].semantic_tokens_enabled = not vim.b[bufnr].semantic_tokens_enabled
for _, client in ipairs(vim.lsp.get_clients({ bufnr = bufnr })) do
if client.server_capabilities.semanticTokensProvider then
vim.lsp.semantic_tokens[vim.b[bufnr].semantic_tokens_enabled and "start" or "stop"](bufnr, client.id)
utils.notify(string.format("Buffer [LSP semantic highlighting]: `%s`", bool2str(vim.b[bufnr].semantic_tokens_enabled)))
end
end
end
--- Toggle syntax highlighting and treesitter
--- @param bufnr? number the buffer to toggle `treesitter` on.
function M.toggle_buffer_syntax(bufnr)
-- HACK: this should just be `bufnr = bufnr or 0` but it looks like
-- `vim.treesitter.stop` has a bug with `0` being current.
bufnr = (bufnr and bufnr ~= 0) and bufnr or vim.api.nvim_win_get_buf(0)
local ts_avail, parsers = pcall(require, "nvim-treesitter.parsers")
if vim.bo[bufnr].syntax == "OFF" then
if ts_avail and parsers.has_parser() then vim.treesitter.start(bufnr) end
vim.bo[bufnr].syntax = "ON"
if not vim.b.semantic_tokens_enabled then M.toggle_buffer_semantic_tokens(bufnr) end
else
if ts_avail and parsers.has_parser() then vim.treesitter.stop(bufnr) end
vim.bo[bufnr].syntax = "off"
if vim.b.semantic_tokens_enabled then M.toggle_buffer_semantic_tokens(bufnr) end
end
utils.notify(string.format("Buffer [Syntax]: `%s`", bool2str(vim.bo[bufnr].syntax)))
end
--- Toggle codelens
--- @param bufnr? number the buffer to toggle `codelens` on.
function M.toggle_codelens(bufnr)
bufnr = bufnr or 0
vim.g.codelens_enabled = not vim.g.codelens_enabled
if vim.g.codelens_enabled then
vim.lsp.codelens.refresh({ bufnr = bufnr })
else
vim.lsp.codelens.clear()
end
utils.notify(string.format("Buffer [CodeLens]: `%s`", bool2str(vim.g.codelens_enabled)))
end
--- Toggle coverage signs
function M.toggle_coverage_signs()
vim.g.coverage_signs_enabled = not vim.g.coverage_signs_enabled
if vim.g.coverage_signs_enabled then
utils.notify("Global [Coverage signs]: `ON`" ..
"\n\n- Git signs will be temporary disabled." ..
"\n- Diagnostic signs won't be automatically disabled.")
vim.cmd("Gitsigns toggle_signs")
require("coverage").load(true)
else
utils.notify("Global [Coverage signs]: `OFF` \n\n- Git signs re-enabled.")
require("coverage").hide()
vim.cmd("Gitsigns toggle_signs")
end
end
--- Toggle CSS #colors
function M.toggle_css_colors()
if not utils.is_available("nvim-highlight-colors") then -- guard clause
utils.notify("Plugin 'nvim-highlight-colors' not available")
return
end
vim.cmd("HighlightColors toggle")
local state = require("nvim-highlight-colors").is_active()
utils.notify(string.format("Global [CSS #colors]: `%s`", bool2str(state)))
end
--- Toggle cmp entrirely
function M.toggle_cmp()
if not utils.is_available("nvim-cmp") then -- guard clause
utils.notify("Plugin 'nvim-cmp' not available")
return
end
vim.g.cmp_enabled = not vim.g.cmp_enabled
utils.notify(
string.format("Global [AutoCompletion]: `%s`", bool2str(vim.g.cmp_enabled))
)
end
--- Toggle conceal=2|0
function M.toggle_conceal()
vim.opt.conceallevel = vim.opt.conceallevel:get() == 0 and 2 or 0 -- global
utils.notify(string.format("Buffer [Conceal]: `%s`", bool2str(vim.opt.conceallevel:get() == 2)))
end
--- Toggle diagnostics
function M.toggle_diagnostics()
vim.g.diagnostics_mode = (vim.g.diagnostics_mode - 1) % 4
vim.diagnostic.config(require("base.utils").diagnostics_enum[vim.g.diagnostics_mode])
if vim.g.diagnostics_mode == 0 then
utils.notify("Global [LSP diagnostics mode]: `OFF`")
elseif vim.g.diagnostics_mode == 1 then
utils.notify("Global [LSP diagnostics mode]: `Statusbar only`")
elseif vim.g.diagnostics_mode == 2 then
utils.notify("Global [LSP diagnostics mode]: `Virtual text only`")
else
utils.notify("Global [LSP diagnostics mode]: `All diagnostics ON`")
end
end
local last_active_foldcolumn
--- Toggle foldcolumn=0|1
function M.toggle_foldcolumn()
local curr_foldcolumn = vim.wo.foldcolumn
if curr_foldcolumn ~= "0" then last_active_foldcolumn = curr_foldcolumn end
vim.wo.foldcolumn = curr_foldcolumn == "0" and (last_active_foldcolumn or "1") or "0"
utils.notify(string.format("Window [Fold column]: `%s`", vim.wo.foldcolumn))
end
--- Toggle LSP inlay hints (global)
--- @param bufnr? number the buffer to toggle the `inlay_hints` on.
function M.toggle_inlay_hints(bufnr)
bufnr = bufnr or 0
vim.g.inlay_hints_enabled = not vim.g.inlay_hints_enabled -- flip global state
vim.b.inlay_hints_enabled = not vim.g.inlay_hints_enabled -- sync buffer state
vim.lsp.buf.inlay_hint.enable(vim.g.inlay_hints_enabled, { bufnr = bufnr }) -- apply state
utils.notify(string.format("Global [Inlay hints]: %s", bool2str(vim.g.inlay_hints_enabled)))
end
--- Toggle line numbers
function M.toggle_line_numbers()
local number = vim.wo.number
local relativenumber = vim.wo.relativenumber
if not number and not relativenumber then -- mode 1
vim.wo.number = true
elseif number and not relativenumber then -- mode 2
vim.wo.relativenumber = true
elseif number and relativenumber then
vim.wo.number = false -- mode 3
else -- not number and relativenumber
vim.wo.relativenumber = false -- mode 4
end
utils.notify(string.format("Window [Line number] `%s`, [Relative Number] `%s`", bool2str(vim.wo.number), bool2str(vim.wo.relativenumber)))
end
--- Toggle lsp signature
function M.toggle_lsp_signature()
if not utils.is_available("lsp_signature.nvim") then -- guard clause
utils.notify("Plugin 'lsp_signature.nvim' not available")
return
end
local state = require('lsp_signature').toggle_float_win() -- global
utils.notify(string.format("Global [LSP signature]: `%s`", bool2str(state)))
end
--- Toggle paste
function M.toggle_paste()
vim.opt.paste = not vim.opt.paste:get()
utils.notify(string.format("Global [Paste mode]: `%s`", bool2str(vim.opt.paste:get())))
end
--- Toggle signcolumn="auto"|"no"
function M.toggle_signcolumn()
if vim.wo.signcolumn == "no" then
vim.wo.signcolumn = "yes"
elseif vim.wo.signcolumn == "yes" then
vim.wo.signcolumn = "auto"
else
vim.wo.signcolumn = "no"
end
utils.notify(string.format("Window [Sign column]: `%s`", vim.wo.signcolumn))
end
--- Toggle spell
function M.toggle_spell()
vim.wo.spell = not vim.wo.spell
utils.notify(string.format("Window [Spell check]: `%s`", bool2str(vim.wo.spell)))
end
--- Toggle laststatus=3|2|0
function M.toggle_statusline()
local laststatus = vim.opt.laststatus:get()
local status
if laststatus == 0 then
vim.opt.laststatus = 2
status = "LOCAL"
elseif laststatus == 2 then
vim.opt.laststatus = 3
status = "GLOBAL"
elseif laststatus == 3 then
vim.opt.laststatus = 0
status = "OFF"
end
utils.notify(string.format("Toggle [Status line]: `%s`", status))
end
--- Toggle showtabline=2|0
function M.toggle_tabline()
vim.opt.showtabline = vim.opt.showtabline:get() == 0 and 2 or 0
utils.notify(string.format("Global [vim.opt.showtabline]: `%s`", bool2str(vim.opt.showtabline:get() == 2)))
end
local notify_state
--- Toggle notifications
function M.toggle_notifications()
vim.g.notifications_enabled = not vim.g.notifications_enabled
if vim.g.notifications_enabled then
vim.notify = notify_state
else
notify_state = vim.notify
end
utils.notify(string.format("Global [vim.g.notifications_enabled]: `%s`", bool2str(vim.g.notifications_enabled)))
end
--- Toggle URL highlight
function M.toggle_url_hl()
vim.g.url_hl_enabled = not vim.g.url_hl_enabled
require("base.utils").set_url_hl()
utils.notify(string.format("Global [URL highlight]: `%s`", bool2str(vim.g.url_hl_enabled)))
end
--- Toggle line wrap
function M.toggle_wrap()
vim.wo.wrap = not vim.wo.wrap
utils.notify(string.format("Window [Line Wrap]: `%s`", bool2str(vim.wo.wrap)))
end
--- Toggle zen mode
function M.toggle_zen_mode()
if not utils.is_available("zen-mode.nvim") then -- guard clause
utils.notify("Plugin 'zen-mode.nvim' not available")
return
end
vim.cmd("ZenMode")
utils.notify(string.format("Global [Zen mode]: `%s`", bool2str(vim.g.zen_mode)))
end
return M