.dotfiles/nvim/lua/autocompletion.lua

120 lines
3.7 KiB
Lua
Raw Normal View History

2021-12-15 12:31:17 +01:00
-- Setup nvim-cmp.
2023-06-16 01:47:30 +02:00
local cmp = require 'cmp'
2021-12-15 12:31:17 +01:00
cmp.setup({
snippet = {
expand = function(args)
2023-06-16 01:47:30 +02:00
require('luasnip').lsp_expand(args.body)
2021-12-15 12:31:17 +01:00
end,
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
2023-06-16 01:50:56 +02:00
['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
2022-01-23 23:24:50 +01:00
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
2021-12-15 12:31:17 +01:00
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp',
entry_filter = function(entry, ctx)
return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()] ~= 'Text'
2023-06-16 01:50:56 +02:00
end,
},
2023-06-16 01:47:30 +02:00
{ name = 'luasnip' },
2023-06-16 01:50:56 +02:00
{ name = 'buffer', keyword_length = 5 },
}),
experimental = {
native_menu = false,
ghost_text = true,
2021-12-15 12:31:17 +01:00
}
})
2022-01-24 23:54:15 +01:00
-- Use cmdline & path source for ':'
2021-12-15 12:31:17 +01:00
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
2022-01-24 23:54:15 +01:00
local on_attach = function(client, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
2021-12-15 12:31:17 +01:00
2022-10-05 18:50:22 +02:00
local opts = { noremap = true, silent = true, buffer=0 }
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
vim.keymap.set("n", "gD", "<cmd>Telescope lsp_implementations<CR>", opts)
vim.keymap.set("n", "gf", function() vim.lsp.buf.format {async = true} end, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "ge", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "gs", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "gR", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "gH", vim.lsp.buf.code_action, opts)
2022-01-24 23:54:15 +01:00
end
2023-06-16 01:50:56 +02:00
-- LSP INSTALLER
2023-02-23 15:26:09 +01:00
require("mason").setup()
require("mason-lspconfig").setup()
2023-06-16 01:50:56 +02:00
2022-01-24 23:54:15 +01:00
2023-02-23 15:26:09 +01:00
require("mason-lspconfig").setup_handlers {
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function (server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {
on_attach = on_attach,
capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
}
end,
-- Next, you can provide a dedicated handler for specific servers.
-- For example, a handler override for the `rust_analyzer`:
["rust_analyzer"] = function ()
require("rust-tools").setup {}
end
}
2023-06-16 01:50:56 +02:00
-- EXTRA SETUP
2023-02-23 15:25:27 +01:00
require'lspconfig'.lua_ls.setup {
2023-06-16 01:50:56 +02:00
settings = {
Lua = {
2023-02-23 15:25:27 +01:00
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
2023-06-16 01:50:56 +02:00
diagnostics = {
-- Get the language server to recognize the `vim` global
2023-02-23 15:25:27 +01:00
globals = {'vim'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
2023-06-16 01:50:56 +02:00
},
},
},
}
2022-09-12 20:04:17 +02:00
2023-02-23 15:26:09 +01:00
2023-06-16 01:50:56 +02:00
-- LSP SIGNATURE
2022-09-12 20:04:17 +02:00
require "lsp_signature".setup {
handler_opts = {
border = "rounded"
},
toggle_key = "<M-r>",
}