Compare commits
1 Commits
a6fc668de5
...
helpgrep
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d21cd45701 |
@@ -1,3 +0,0 @@
|
||||
local opts = { buffer = true, remap = false, silent = true }
|
||||
vim.keymap.set('n', '0', ':PreProcIfWrap<CR>', opts)
|
||||
vim.keymap.set('v', '0', ':PreProcIfWrap<CR>', opts)
|
||||
@@ -1,6 +1,2 @@
|
||||
vim.opt.commentstring = '//%s'
|
||||
vim.opt.matchpairs:append('<:>')
|
||||
|
||||
local opts = { buffer = true, remap = false, silent = true }
|
||||
vim.keymap.set('n', '0', ':PreProcIfWrap<CR>', opts)
|
||||
vim.keymap.set('v', '0', ':PreProcIfWrap<CR>', opts)
|
||||
|
||||
@@ -72,48 +72,57 @@ return {
|
||||
},
|
||||
|
||||
config = function()
|
||||
local lspconfig_default_opts = {
|
||||
-- Broadcast full client capabilities to language servers
|
||||
capabilities = vim.tbl_deep_extend(
|
||||
'force', vim.lsp.protocol.make_client_capabilities(),
|
||||
require('cmp_nvim_lsp').default_capabilities()),
|
||||
}
|
||||
|
||||
local lspconfig_custom_opts = {
|
||||
clangd = {
|
||||
cmd = { 'clangd', '--completion-style=detailed' },
|
||||
},
|
||||
|
||||
lua_ls = {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
disable = { 'missing-fields', },
|
||||
globals = { 'vim', },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
pyright = {
|
||||
settings = {
|
||||
pyright = {
|
||||
disableOrganizeImports = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = vim.tbl_deep_extend(
|
||||
'force', capabilities, require('cmp_nvim_lsp').default_capabilities())
|
||||
|
||||
require('mason').setup()
|
||||
require('mason-lspconfig').setup({
|
||||
automatic_installation = false,
|
||||
ensure_installed = ensure_installed,
|
||||
|
||||
handlers = {
|
||||
-- Default handler, sets up everything unless a custom language server
|
||||
-- setup handler is defined below
|
||||
function(server_name)
|
||||
local opts = vim.tbl_deep_extend("force",
|
||||
lspconfig_default_opts, lspconfig_custom_opts[server_name] or {})
|
||||
require('lspconfig')[server_name].setup(opts)
|
||||
require('lspconfig')[server_name].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end,
|
||||
|
||||
['clangd'] = function()
|
||||
require('lspconfig').clangd.setup({
|
||||
capabilities = capabilities,
|
||||
cmd = { 'clangd', '--completion-style=detailed' }
|
||||
})
|
||||
end,
|
||||
|
||||
['lua_ls'] = function()
|
||||
require('neodev').setup()
|
||||
require('lspconfig').lua_ls.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
disable = { 'missing-fields', },
|
||||
globals = { 'vim', },
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
end,
|
||||
|
||||
['pyright'] = function()
|
||||
require('lspconfig').pyright.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
pyright = {
|
||||
disableOrganizeImports = true, -- Use ruff import sorter instead
|
||||
},
|
||||
}
|
||||
})
|
||||
end,
|
||||
|
||||
},
|
||||
})
|
||||
|
||||
@@ -163,9 +172,6 @@ return {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
|
||||
-- Don't preselect any completion items, fixes wird behaviour in gopls
|
||||
preselect = cmp.PreselectMode.None,
|
||||
})
|
||||
require("cmp_git").setup({})
|
||||
|
||||
@@ -174,12 +180,11 @@ return {
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
pattern = '*',
|
||||
group = augroup,
|
||||
callback = function(event)
|
||||
local opts = { noremap = true, buffer = event.buf }
|
||||
callback = function(ev)
|
||||
local opts = { noremap = true, buffer = ev.buf }
|
||||
|
||||
-- Fixit mapping, or close enough, actually any code action
|
||||
vim.keymap.set('n', '<leader>fi',
|
||||
require('actions-preview').code_actions, opts)
|
||||
vim.keymap.set('n', '<leader>fi', require('actions-preview').code_actions, opts)
|
||||
|
||||
-- Goto mappings
|
||||
local tb = require('telescope.builtin')
|
||||
@@ -190,7 +195,7 @@ return {
|
||||
vim.keymap.set('n', 'gr', tb.lsp_references, opts)
|
||||
vim.keymap.set('n', '<leader>ic', tb.lsp_incoming_calls, opts)
|
||||
vim.keymap.set('n', '<leader>oc', tb.lsp_outgoing_calls, opts)
|
||||
vim.keymap.set('n', '<leader>sd', tb.lsp_document_symbols, opts)
|
||||
vim.keymap.set('n', '<leader>ss', tb.lsp_document_symbols, opts)
|
||||
vim.keymap.set('n', '<leader>sw', tb.lsp_workspace_symbols, opts)
|
||||
|
||||
-- Refactoring mappings
|
||||
@@ -207,8 +212,7 @@ return {
|
||||
|
||||
-- Swtich file using clangd extension
|
||||
-- TODO: limit this to only filetypes supported by clangd
|
||||
vim.keymap.set('n', '<leader>sf',
|
||||
':ClangdSwitchSourceHeader<CR>', { silent = true })
|
||||
vim.keymap.set('n', '<leader>sf', ':ClangdSwitchSourceHeader<CR>', { silent = true })
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@ return {
|
||||
'nvim-telescope/telescope-fzy-native.nvim',
|
||||
'nvim-tree/nvim-web-devicons',
|
||||
'axkirillov/easypick.nvim',
|
||||
'benfowler/telescope-luasnip.nvim',
|
||||
'catgoose/telescope-helpgrep.nvim',
|
||||
},
|
||||
config = function()
|
||||
local telescope = require('telescope')
|
||||
local actions = require('telescope.actions')
|
||||
telescope.setup({
|
||||
defaults = {
|
||||
mappings = {
|
||||
@@ -21,23 +22,38 @@ return {
|
||||
['<C-s>'] = 'select_horizontal',
|
||||
['<C-h>'] = 'preview_scrolling_left',
|
||||
['<C-l>'] = 'preview_scrolling_right',
|
||||
}
|
||||
},
|
||||
},
|
||||
layout_config = {
|
||||
height = 0.7,
|
||||
}
|
||||
},
|
||||
},
|
||||
extensions = {
|
||||
helpgrep = {
|
||||
mappings = {
|
||||
i = {
|
||||
["<CR>"] = actions.select_default,
|
||||
["<C-v>"] = actions.select_vertical,
|
||||
},
|
||||
n = {
|
||||
["<CR>"] = actions.select_default,
|
||||
["<C-s>"] = actions.select_horizontal,
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
telescope.load_extension('fzy_native')
|
||||
telescope.load_extension('luasnip')
|
||||
|
||||
local builtin = require('telescope.builtin')
|
||||
local opts = { noremap = true }
|
||||
vim.keymap.set('n', '<leader>gF', builtin.find_files, opts)
|
||||
vim.keymap.set('n', '<leader>gf', builtin.git_files, opts)
|
||||
vim.keymap.set('n', '<leader>gg', builtin.live_grep, opts)
|
||||
vim.keymap.set('n', '<leader>rg', builtin.grep_string, opts)
|
||||
vim.keymap.set('n', '<leader>gb', builtin.buffers, opts)
|
||||
vim.keymap.set('n', '<leader>gh', builtin.help_tags, opts)
|
||||
vim.keymap.set('n', '<leader>ht', builtin.help_tags, opts)
|
||||
vim.keymap.set('n', '<leader>gh', require('telescope-helpgrep').live_grep, opts)
|
||||
vim.keymap.set('n', '<leader>bl', builtin.current_buffer_fuzzy_find, opts)
|
||||
|
||||
require('easypick').setup({
|
||||
|
||||
@@ -116,37 +116,13 @@ end, {
|
||||
complete = 'file',
|
||||
})
|
||||
|
||||
-- :Rg grep for the given string, word under the cursor, or visual selection
|
||||
-- then fuzzy find the results. Bang to enable regex in given string.
|
||||
-- :Rg grep for the given string and fuzzy find the results, bang to enable
|
||||
-- regex in given string
|
||||
-- FIXME: Support visual select modes
|
||||
vim.api.nvim_create_user_command('Rg', function(opts)
|
||||
local search = opts.args
|
||||
if opts.range == 2 then
|
||||
local lines = vim.fn.getline(vim.fn.line("'<"), vim.fn.line("'>"))
|
||||
local start_col = vim.fn.col("'<")
|
||||
local end_col = vim.fn.col("'>")
|
||||
if #lines == 1 then
|
||||
lines[1] = string.sub(lines[1], start_col, end_col)
|
||||
else
|
||||
lines[1] = string.sub(lines[1], start_col)
|
||||
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
||||
end
|
||||
search = table.concat(lines, "\n")
|
||||
elseif #search == 0 then
|
||||
search = vim.fn.expand('<cword>')
|
||||
end
|
||||
local grep_opts = { search = search}
|
||||
local grep_opts = { search = opts.args }
|
||||
if opts.bang then
|
||||
grep_opts['use_regex'] = true
|
||||
end
|
||||
require('telescope.builtin').grep_string(grep_opts)
|
||||
end, { bang = true, range = true, nargs = '*' })
|
||||
|
||||
vim.api.nvim_create_user_command('PreProcIfWrap', function(opts)
|
||||
local buffer = vim.api.nvim_get_current_buf()
|
||||
vim.api.nvim_buf_set_lines(
|
||||
buffer, opts.line2, opts.line2, true, { '#endif' })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
buffer, opts.line1 - 1, opts.line1 - 1, true, { '#if 0' })
|
||||
local window = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_cursor(window, { opts.line1, 5 })
|
||||
end, { range = true })
|
||||
end, { bang = true, nargs = '*' })
|
||||
|
||||
@@ -43,7 +43,3 @@ vim.keymap.set('t', '<C-w><C-g>', '<C-\\><C-n>:Gdb<CR>:startinsert<CR>', opts)
|
||||
vim.keymap.set('t', '<C-w><C-e>', '<C-\\><C-n>:Program<CR>', opts)
|
||||
vim.keymap.set('t', '<C-w><C-s>', '<C-\\><C-n>:Source<CR>', opts)
|
||||
vim.keymap.set('t', '<C-w><C-a>', '<C-\\><C-n>:Asm<CR>', opts)
|
||||
|
||||
-- Mappings to grep for then fuzzy find the word under the cursor or visual selection
|
||||
vim.keymap.set('n', '<leader>rg', ':Rg<CR>', opts)
|
||||
vim.keymap.set('v', '<leader>rg', ":'<,'>Rg<CR>", opts)
|
||||
|
||||
@@ -75,7 +75,7 @@ local function special(group, name, title)
|
||||
end
|
||||
|
||||
-- Construct a statusline for generic buffer types.
|
||||
local function generic(group, name)
|
||||
local function generic(group, name, show_lsp)
|
||||
-- Display current mode with dynamic highlights.
|
||||
local line = '%#' .. group .. '# ' .. name .. ' '
|
||||
-- Display spell or paste if set with dusk highlights in a group to swallow
|
||||
@@ -131,11 +131,11 @@ function _G.statusline_active()
|
||||
return special('StatusLineLight', 'Terminal', '%f')
|
||||
elseif vim.o.previewwindow then
|
||||
if mode == 'Normal' then mode = 'Preview' end
|
||||
return generic('StatusLineLight', mode)
|
||||
return generic('StatusLineLight', mode, false)
|
||||
elseif vim.o.filetype == 'man' then
|
||||
return special('StatusLineDusk', 'Manual', '%f')
|
||||
end
|
||||
return generic('StatusLineLight', mode)
|
||||
return generic('StatusLineLight', mode, true)
|
||||
end
|
||||
|
||||
function _G.statusline_inactive()
|
||||
@@ -152,11 +152,11 @@ function _G.statusline_inactive()
|
||||
elseif vim.o.buftype == 'terminal' then
|
||||
line = special('StatusLineDusk', 'Terminal', '%f')
|
||||
elseif vim.o.previewwindow then
|
||||
line = generic('StatusLineDusk', 'Preview')
|
||||
line = generic('StatusLineDusk', 'Preview', false)
|
||||
elseif vim.o.filetype == 'man' then
|
||||
line = special('StatusLineDusk', 'Manual', '%f')
|
||||
else
|
||||
line = generic('StatusLineDusk', 'Idle')
|
||||
line = generic('StatusLineDusk', 'Idle', false)
|
||||
end
|
||||
return line
|
||||
end
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
# Go LuaSnip Snippets
|
||||
|
||||
local luasnip = require('luasnip')
|
||||
local snip = luasnip.snippet
|
||||
local text = luasnip.text_node
|
||||
local ins = luasnip.insert_node
|
||||
local func = luasnip.function_node
|
||||
local node = luasnip.snippet_node
|
||||
local key = require("luasnip.nodes.key_indexer").new_key
|
||||
|
||||
local function short_name(name)
|
||||
local short = string.lower(string.sub(name, 1, 1))
|
||||
for i = 2, #name do
|
||||
local char = string.sub(name, i, i)
|
||||
if char == string.upper(char) then
|
||||
short = short .. char
|
||||
end
|
||||
end
|
||||
return string.lower(short)
|
||||
end
|
||||
|
||||
local snippets = {
|
||||
|
||||
snip('func', {
|
||||
text('func '),
|
||||
node(1, {
|
||||
func(function(args)
|
||||
if string.len(args[1][1]) > 0 then
|
||||
return '(' .. short_name(args[1][1]) .. ' *'
|
||||
end
|
||||
return ''
|
||||
end, key('type')),
|
||||
ins(1, '', { key = 'type' }),
|
||||
func(function(args)
|
||||
if string.len(args[1][1]) > 0 then
|
||||
return ') '
|
||||
end
|
||||
return ''
|
||||
end, key('type')),
|
||||
}),
|
||||
ins(2, 'name'),
|
||||
text('('),
|
||||
ins(3, ''),
|
||||
text(') '),
|
||||
ins(4, '', { key = 'return' }),
|
||||
func(function(args)
|
||||
if string.len(args[1][1]) > 0 then
|
||||
return ' '
|
||||
end
|
||||
return ''
|
||||
end, key('return')),
|
||||
text({ '{', '\t' }),
|
||||
ins(0, ''),
|
||||
text({ '', '}' }),
|
||||
}),
|
||||
|
||||
}
|
||||
|
||||
return snippets
|
||||
@@ -1,8 +0,0 @@
|
||||
# Go SnipMate snippets
|
||||
|
||||
snippet main
|
||||
package main
|
||||
|
||||
func main() {
|
||||
$0
|
||||
}
|
||||
Reference in New Issue
Block a user