|
|
|
@ -1,86 +1,45 @@
|
|
|
|
|
return {
|
|
|
|
|
-- Autocompletion
|
|
|
|
|
{
|
|
|
|
|
'hrsh7th/nvim-cmp',
|
|
|
|
|
event = 'InsertEnter',
|
|
|
|
|
"neovim/nvim-lspconfig",
|
|
|
|
|
config = function()
|
|
|
|
|
local cmp = require('cmp')
|
|
|
|
|
|
|
|
|
|
cmp.setup({
|
|
|
|
|
sources = {
|
|
|
|
|
{name = 'nvim_lsp'},
|
|
|
|
|
},
|
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
|
['<C-d>'] = cmp.mapping.scroll_docs(4),
|
|
|
|
|
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
|
|
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
|
|
|
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
|
|
|
|
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
|
|
|
|
['<CR>'] = cmp.mapping.confirm({
|
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
|
select = true,
|
|
|
|
|
}),
|
|
|
|
|
['<C-e>'] = cmp.mapping.abort(),
|
|
|
|
|
}),
|
|
|
|
|
snippet = {
|
|
|
|
|
expand = function(args)
|
|
|
|
|
vim.snippet.expand(args.body)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
-- LSP
|
|
|
|
|
{
|
|
|
|
|
'neovim/nvim-lspconfig',
|
|
|
|
|
cmd = 'LspInfo',
|
|
|
|
|
event = {'BufReadPre', 'BufNewFile'},
|
|
|
|
|
dependencies = {
|
|
|
|
|
{'hrsh7th/cmp-nvim-lsp'},
|
|
|
|
|
},
|
|
|
|
|
init = function()
|
|
|
|
|
-- Reserve a space in the gutter
|
|
|
|
|
-- This will avoid an annoying layout shift in the screen
|
|
|
|
|
vim.opt.signcolumn = 'yes'
|
|
|
|
|
end,
|
|
|
|
|
config = function()
|
|
|
|
|
local lsp_defaults = require('lspconfig').util.default_config
|
|
|
|
|
|
|
|
|
|
-- Add cmp_nvim_lsp capabilities settings to lspconfig
|
|
|
|
|
-- This should be executed before you configure any language server
|
|
|
|
|
lsp_defaults.capabilities = vim.tbl_deep_extend(
|
|
|
|
|
'force',
|
|
|
|
|
lsp_defaults.capabilities,
|
|
|
|
|
require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
-- LspAttach is where you enable features that only work
|
|
|
|
|
-- if there is a language server active in the file
|
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
|
|
desc = 'LSP actions',
|
|
|
|
|
callback = function(event)
|
|
|
|
|
local opts = { buffer = event.buffer, remap = false }
|
|
|
|
|
local opts = { buffer = event.buffer, remap = false }
|
|
|
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
|
|
|
|
|
|
|
|
|
-- Enable built-in completion if supported
|
|
|
|
|
if client and client.supports_method('textDocument/completion') then
|
|
|
|
|
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>k', function() vim.lsp.buf.hover() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>r', function() vim.lsp.buf.rename() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>a', function() vim.lsp.buf.code_action() end, opts)
|
|
|
|
|
vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>d', function() vim.diagnostic.open_float() end, opts)
|
|
|
|
|
vim.keymap.set('n', '[d', function() vim.diagnostic.goto_prev() end, opts)
|
|
|
|
|
vim.keymap.set('n', ']d', function() vim.diagnostic.goto_next() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>Q', function() vim.diagnostic.set_qflist() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>F', function() vim.lsp.buf.format() end, opts)
|
|
|
|
|
-- LSP keybindings
|
|
|
|
|
vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>k', function() vim.lsp.buf.hover() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>r', function() vim.lsp.buf.rename() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>a', function() vim.lsp.buf.code_action() end, opts)
|
|
|
|
|
vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>d', function() vim.diagnostic.open_float() end, opts)
|
|
|
|
|
vim.keymap.set('n', '[d', function() vim.diagnostic.goto_prev() end, opts)
|
|
|
|
|
vim.keymap.set('n', ']d', function() vim.diagnostic.goto_next() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>Q', function() vim.diagnostic.set_qflist() end, opts)
|
|
|
|
|
vim.keymap.set('n', '<leader>F', function() vim.lsp.buf.format() end, opts)
|
|
|
|
|
|
|
|
|
|
-- Built-in completion keybindings
|
|
|
|
|
vim.keymap.set('i', '<C-Space>', '<C-x><C-o>', opts)
|
|
|
|
|
vim.keymap.set('i', '<C-n>', function()
|
|
|
|
|
if vim.fn.pumvisible() == 1 then
|
|
|
|
|
return '<C-n>'
|
|
|
|
|
else
|
|
|
|
|
return '<C-x><C-o>'
|
|
|
|
|
end
|
|
|
|
|
end, { buffer = event.buffer, expr = true })
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
local lsp = require('lspconfig')
|
|
|
|
|
|
|
|
|
|
-- require('lspconfig').gleam.setup({})
|
|
|
|
|
-- require('lspconfig').ocamllsp.setup({})
|
|
|
|
|
|
|
|
|
|
lsp.rust_analyzer.setup({
|
|
|
|
|
vim.lsp.config('rust_analyzer', {
|
|
|
|
|
settings = {
|
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
|
checkOnSave = {
|
|
|
|
@ -117,12 +76,14 @@ return {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
vim.lsp.enable('rust_analyzer')
|
|
|
|
|
|
|
|
|
|
lsp.pylsp.setup({})
|
|
|
|
|
lsp.ruff.setup({})
|
|
|
|
|
|
|
|
|
|
vim.lsp.enable('pylsp')
|
|
|
|
|
vim.lsp.enable('ruff')
|
|
|
|
|
vim.lsp.enable('ts_ls')
|
|
|
|
|
vim.lsp.enable('oxlint')
|
|
|
|
|
|
|
|
|
|
-- Workaround for rust_analzyer issue
|
|
|
|
|
-- Workaround for rust_analyzer diagnostic issue
|
|
|
|
|
for _, method in ipairs({ 'textDocument/diagnostic', 'workspace/diagnostic' }) do
|
|
|
|
|
local default_diagnostic_handler = vim.lsp.handlers[method]
|
|
|
|
|
vim.lsp.handlers[method] = function(err, result, context, config)
|
|
|
|
|