Not only does this show a diff of the selected code action before you apply it, it uses Telescope for display and selection of the desired code action.
138 lines
4.3 KiB
Lua
138 lines
4.3 KiB
Lua
return {
|
|
'neovim/nvim-lspconfig',
|
|
|
|
dependencies = {
|
|
-- Language server management plugins
|
|
'williamboman/mason.nvim',
|
|
'williamboman/mason-lspconfig.nvim',
|
|
|
|
-- Completion plugins
|
|
'hrsh7th/cmp-nvim-lsp', -- Source for built-in language server client
|
|
'hrsh7th/cmp-buffer', -- Source for buffer words
|
|
'hrsh7th/cmp-path', -- Source for filesystem paths
|
|
'hrsh7th/cmp-cmdline', -- Source for command-line
|
|
'hrsh7th/nvim-cmp', -- Completion engine combines and use the above
|
|
|
|
-- LSP UI plugins
|
|
'aznhe21/actions-preview.nvim',
|
|
|
|
-- Lue vim module support in lua language server
|
|
'folke/neodev.nvim',
|
|
|
|
-- Snippet pluggins
|
|
'L3MON4D3/LuaSnip',
|
|
'saadparwaiz1/cmp_luasnip',
|
|
|
|
-- TODO: https://github.com/j-hui/fidget.nvim
|
|
|
|
-- TODO: https://github.com/nvimtools/none-ls.nvim
|
|
|
|
-- TODO: https://github.com/mfussenegger/nvim-dap
|
|
-- TODO: https://github.com/rcarriga/nvim-dap-ui
|
|
},
|
|
|
|
config = function()
|
|
require('mason').setup()
|
|
require('mason-lspconfig').setup({
|
|
ensure_installed = {
|
|
'clangd',
|
|
'cmake',
|
|
'jsonls',
|
|
'lua_ls',
|
|
'lemminx',
|
|
'vimls',
|
|
'yamlls',
|
|
},
|
|
automatic_installation = false,
|
|
handlers = {
|
|
-- Default handler, sets up everything unless a custom language server
|
|
-- setup handler is defined below
|
|
function(server_name)
|
|
require('lspconfig')[server_name].setup({})
|
|
end,
|
|
|
|
['lua_ls'] = function()
|
|
require('neodev').setup()
|
|
local lspconfig = require('lspconfig')
|
|
lspconfig.lua_ls.setup({
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = {
|
|
disable = { 'missing-fields', },
|
|
globals = { 'vim', },
|
|
}
|
|
}
|
|
}
|
|
})
|
|
end
|
|
},
|
|
})
|
|
|
|
local cmp = require('cmp')
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
require('luasnip').lsp_expand(args.body)
|
|
end
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
['<C-l>'] = cmp.mapping.confirm({ select = true }),
|
|
}),
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
{ name = 'buffer' },
|
|
{ name = 'path' },
|
|
{ name = 'cmdline' },
|
|
},
|
|
})
|
|
|
|
-- Disable displaying diagnostics as virtual text
|
|
vim.diagnostic.config({ virtual_text = false })
|
|
|
|
-- Diagnostic mappings
|
|
-- TODO: trouble.nvim mappings instead? https://youtu.be/MuUrCcvE-Yw?t=631
|
|
vim.keymap.set('n', '<C-n>', vim.diagnostic.goto_next, { noremap = true })
|
|
vim.keymap.set('n', '<C-p>', vim.diagnostic.goto_prev, { noremap = true })
|
|
vim.keymap.set('n', '<leader>sd', vim.diagnostic.open_float, { noremap = true })
|
|
|
|
-- Mappings to create once a language server attaches to a buffer
|
|
local augroup = vim.api.nvim_create_augroup('lsp', { clear = true })
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
pattern = '*',
|
|
group = augroup,
|
|
callback = function(ev)
|
|
local opts = { noremap = true, buffer = ev.buf }
|
|
|
|
-- TODO: inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#pum#confirm() : "\<TAB>"
|
|
-- Should I drop this? It's only for expanding snippets because
|
|
-- coc.nvim was being weird about it
|
|
|
|
-- Fixit mapping, or close enough, actually any code action
|
|
vim.keymap.set('n', '<leader>fi',
|
|
require("actions-preview").code_actions, opts)
|
|
|
|
-- Goto definition mapping
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
|
-- TODO: nnoremap <silent> <leader>gt <Plug>(coc-type-definition)
|
|
-- TODO: nnoremap <silent> <leader>gu <Plug>(coc-references-used)
|
|
|
|
-- Get references to symbol under cursor, store in quickfix window
|
|
vim.keymap.set('n', '<leader>gr', vim.lsp.buf.references, opts)
|
|
|
|
-- Refactoring mappings
|
|
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
|
|
|
-- Format whole buffer mapping
|
|
vim.keymap.set('n', '<leader>gq', vim.lsp.buf.format, opts)
|
|
|
|
-- Help mappings
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
|
vim.keymap.set('i', '<C-h>', vim.lsp.buf.signature_help, opts)
|
|
end
|
|
})
|
|
end
|
|
}
|