-
Notifications
You must be signed in to change notification settings - Fork 464
/
helpers.lua
129 lines (121 loc) · 3.5 KB
/
helpers.lua
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
_G._command_panel = function()
require("telescope.builtin").keymaps({
lhs_filter = function(lhs)
return not string.find(lhs, "Þ")
end,
layout_config = {
width = 0.6,
height = 0.6,
prompt_position = "top",
},
})
end
_G._telescope_collections = function(picker_type)
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local conf = require("telescope.config").values
local finder = require("telescope.finders")
local pickers = require("telescope.pickers")
picker_type = picker_type or {}
local collections = vim.tbl_keys(require("search.tabs").collections)
pickers
.new(picker_type, {
prompt_title = "Telescope Collections",
finder = finder.new_table({ results = collections }),
sorter = conf.generic_sorter(picker_type),
attach_mappings = function(bufnr)
actions.select_default:replace(function()
actions.close(bufnr)
local selection = action_state.get_selected_entry()
require("search").open({ collection = selection[1] })
end)
return true
end,
})
:find()
end
_G._flash_esc_or_noh = function()
local flash_active, state = pcall(function()
return require("flash.plugins.char").state
end)
if flash_active and state then
state:hide()
else
pcall(vim.cmd.noh)
end
end
local _lazygit = nil
_G._toggle_lazygit = function()
if vim.fn.executable("lazygit") == 1 then
if not _lazygit then
_lazygit = require("toggleterm.terminal").Terminal:new({
cmd = "lazygit",
direction = "float",
close_on_exit = true,
hidden = true,
})
end
_lazygit:toggle()
else
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
end
end
_G._toggle_inlayhint = function()
if vim.lsp.inlay_hint.is_enabled() then
vim.lsp.inlay_hint.enable(false)
vim.notify("Disable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
else
vim.lsp.inlay_hint.enable(true)
vim.notify("Enable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
end
end
local _diagnostic = 1
_G._toggle_diagnostic = function()
if vim.diagnostic.is_enabled() then
if _diagnostic == 1 then
_diagnostic = 0
vim.diagnostic.hide()
vim.notify("Hide virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
else
_diagnostic = 1
vim.diagnostic.show()
vim.notify("Show virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
end
end
end
_G._async_compile_and_debug = function()
local file_ext = vim.fn.expand("%:e")
local file_path = vim.fn.expand("%:p")
local out_name = vim.fn.expand("%:p:h") .. "/" .. vim.fn.expand("%:t:r") .. ".out"
local compile_cmd
if file_ext == "cpp" or file_ext == "cc" then
compile_cmd = string.format("g++ -g %s -o %s", file_path, out_name)
elseif file_ext == "c" then
compile_cmd = string.format("gcc -g %s -o %s", file_path, out_name)
elseif file_ext == "go" then
compile_cmd = string.format("go build -o %s %s", out_name, file_path)
else
require("dap").continue()
return
end
local notify_title = "Debug Pre-compile"
vim.fn.jobstart(compile_cmd, {
on_exit = function(_, exit_code, _)
if exit_code == 0 then
vim.notify(
"Compilation succeeded! Executable: " .. out_name,
vim.log.levels.INFO,
{ title = notify_title }
)
require("dap").continue()
return
else
vim.notify(
"Compilation failed with exit code: " .. exit_code,
vim.log.levels.ERROR,
{ title = notify_title }
)
end
end,
})
end