nvim stuff

This commit is contained in:
doyle 2022-06-18 18:34:51 +10:00
parent fb42918273
commit 502844d1e0

View File

@ -85,42 +85,55 @@ lua <<EOF
vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, bufopts) vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<A-a>', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', '<A-r>', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'gR', vim.lsp.buf.rename, bufopts)
end end
-- Request additional completion capabilities from the LSP server(s) -- Request additional completion capabilities from the LSP server(s)
local lspconfig = require('lspconfig') local lspconfig = require('lspconfig')
local servers = { 'clangd', }
for _, lsp in ipairs(servers) do -- Clangd LSP Setup
lspconfig[lsp].setup { on_attach = custom_on_attach, capabilities = custom_capabilities, } -- ===========================================================================
end lspconfig.clangd.setup {
on_attach = custom_on_attach,
capabilities = custom_capabilities,
single_file_support = false, --- Don't launch LSP if the directory does not have LSP metadata
}
-- Autocomplete Setup -- Autocomplete Setup
-- =========================================================================== -- ===========================================================================
local luasnip = require 'luasnip' local luasnip = require 'luasnip'
local cmp = require 'cmp' local cmp = require 'cmp'
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
cmp.setup { cmp.setup {
snippet = { snippet = {
expand = function(args) luasnip.lsp_expand(args.body) end, expand = function(args) luasnip.lsp_expand(args.body) end,
}, },
completion = { autocomplete = false },
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(4), ['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-u>'] = cmp.mapping.scroll_docs(-4), ['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-l>'] = cmp.mapping.scroll_docs(-1), -- Scroll the docs up by 1 line ['<C-k>'] = cmp.mapping.scroll_docs(-1), -- Scroll the docs up by 1 line
['<C-h>'] = cmp.mapping.scroll_docs(1), -- Scroll the docs down by 1 line ['<C-j>'] = cmp.mapping.scroll_docs(1), -- Scroll the docs down by 1 line
['<CR>'] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, ['<CR>'] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, },
['<C-j>'] = cmp.mapping(function(fallback) -- Move down the autocomplete list ['<Tab>'] = cmp.mapping(function(fallback) -- Move down the autocomplete list
cmp.complete()
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else else
fallback() fallback()
end end
end, { 'i', 's' }), end, { 'i', 's' }),
['<C-k>'] = cmp.mapping(function(fallback) -- Move up the autocomplete list ['<S-Tab>'] = cmp.mapping(function(fallback) -- Move up the autocomplete list
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.jumpable(-1) then elseif luasnip.jumpable(-1) then
@ -131,23 +144,18 @@ lua <<EOF
end, { 'i', 's' }), end, { 'i', 's' }),
}), }),
sources = { sources = {
{ name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'nvim_lsp' },
{ name = 'luasnip' },
}, },
} }
-- Clangd LSP Setup
-- ===========================================================================
lspconfig.clangd.setup {
single_file_support = false, --- Don't launch LSP if the directory does not have LSP metadata
}
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
ensure_installed = { "c", "cpp" }, -- A list of parser names, or "all" ensure_installed = { "c", "cpp" }, -- A list of parser names, or "all"
sync_install = false, -- Install parsers synchronously (only applied to `ensure_installed`) sync_install = false, -- Install parsers synchronously (only applied to `ensure_installed`)
ignore_install = { }, -- List of parsers to ignore installing (for "all") ignore_install = { }, -- List of parsers to ignore installing (for "all")
highlight = { highlight = {
enable = true, -- `false` will disable the whole extension enable = false, -- `false` will disable the whole extension
-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is