neovim-confs/lua/custom/plugins/lsp.lua

490 lines
16 KiB
Lua
Raw Normal View History

2024-07-04 15:31:43 +02:00
local cmp = require 'cmp' -- this is nvim-cmp
2024-07-04 12:41:35 +02:00
return {
{
'neovim/nvim-lspconfig',
2024-07-04 15:24:34 +02:00
dependencies = {
-- Automatically install LSPs and related tools to stdpath for Neovim
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
'williamboman/mason-lspconfig.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim',
-- Useful status updates for LSP.
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
{ 'j-hui/fidget.nvim', opts = {} },
-- `neodev` configures Lua LSP for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
{ 'folke/neodev.nvim', opts = {} },
},
keys = {
{ '<C-k>', cmp.mapping.select_prev_item(), desc = 'Next completion' },
{ '<C-j>', cmp.mapping.select_next_item(), desc = 'Last completion' },
{ '<C-Space>', cmp.mapping.complete(), desc = 'Accept completion' },
{ '<C-e>', cmp.mapping.close(), desc = 'Hide completions' },
{ '<CR>', cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}, desc = 'Accept completion' },
{
'<Tab>',
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif require('luasnip').expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end, {
'i',
's',
}),
desc = 'Next completion',
},
{
'<S-Tab>',
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif require('luasnip').expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end, {
'i',
's',
}),
desc = 'Last completion',
},
},
2024-07-04 12:41:35 +02:00
config = function()
2024-07-04 14:43:32 +02:00
require 'custom.plugins.configs.lsp'
2024-07-04 12:41:35 +02:00
end,
},
2024-07-04 14:43:32 +02:00
-- See `:help gitsigns` to understand what the configuration keys do
{ -- Adds git related signs to the gutter, as well as utilities for managing changes
'lewis6991/gitsigns.nvim',
opts = {
signs = {
add = { text = '+' },
change = { text = '~' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
},
},
},
2024-07-04 15:24:34 +02:00
{
'folke/trouble.nvim',
cmd = 'Trouble',
opts = { use_diagnostic_signs = true },
-- stylua: ignore
keys = {
{ '<leader>rb', "<cmd>Trouble diagnostics toggle filter.buf=0<cr>", desc = 'Document Diagnostics (Trouble)' },
{ '<leader>rr', '<cmd>Trouble diagnostics toggle<cr>', desc = 'Workspace Diagnostics (Trouble)' },
{ '<leader>rq', "<cmd>Trouble qflist toggle<cr>", desc = 'Quickfix List (Trouble)' },
{ '<leader>rl', "<cmd>Trouble loclist toggle<cr>", desc = 'Location List (Trouble)' },
{ '<leader>rd', "<cmd>Trouble symbols<cr>", desc = 'LSP symbols (Trouble)' },
{ '<leader>rt', "<cmd>Trouble todo<cr>", desc = 'Todos (Trouble)' },
{
'[q',
function()
if require('trouble').is_open() then
require('trouble').previous({ skip_groups = true, jump = true })
else
vim.cmd.cprev()
end
end,
desc = 'Previous trouble/quickfix item',
},
{
']q',
function()
if require('trouble').is_open() then
require('trouble').next({ skip_groups = true, jump = true })
else
vim.cmd.cnext()
end
end,
desc = 'Next trouble/quickfix item',
},
},
},
{ -- Autocompletion
'hrsh7th/nvim-cmp',
2024-07-04 15:31:43 +02:00
enabled = not vim.g.started_by_firenvim,
2024-07-04 15:24:34 +02:00
event = 'InsertEnter',
dependencies = {
-- Snippet Engine & its associated nvim-cmp source
{
'L3MON4D3/LuaSnip',
build = (function()
-- Build Step is needed for regex support in snippets.
-- This step is not supported in many windows environments.
-- Remove the below condition to re-enable on windows.
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
return
end
return 'make install_jsregexp'
end)(),
dependencies = {
-- `friendly-snippets` contains a variety of premade snippets.
-- See the README about individual language/framework/plugin snippets:
-- https://github.com/rafamadriz/friendly-snippets
-- {
-- 'rafamadriz/friendly-snippets',
-- config = function()
-- require('luasnip.loaders.from_vscode').lazy_load()
-- end,
-- },
},
},
'saadparwaiz1/cmp_luasnip',
-- Adds other completion capabilities.
-- nvim-cmp does not ship with all sources by default. They are split
-- into multiple repos for maintenance purposes.
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
},
config = function()
-- See `:help cmp`
local cmp = require 'cmp'
local luasnip = require 'luasnip'
luasnip.config.setup {}
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
completion = { completeopt = 'menu,menuone,noinsert' },
-- For an understanding of why these mappings were
-- chosen, you will need to read `:help ins-completion`
--
-- No, but seriously. Please read `:help ins-completion`, it is really good!
mapping = cmp.mapping.preset.insert {
-- Select the [n]ext item
['<C-n>'] = cmp.mapping.select_next_item(),
-- Select the [p]revious item
['<C-p>'] = cmp.mapping.select_prev_item(),
-- Scroll the documentation window [b]ack / [f]orward
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
-- Accept ([y]es) the completion.
-- This will auto-import if your LSP supports it.
-- This will expand snippets if the LSP sent a snippet.
['<C-y>'] = cmp.mapping.confirm { select = true },
-- If you prefer more traditional completion keymaps,
-- you can uncomment the following lines
--['<CR>'] = cmp.mapping.confirm { select = true },
--['<Tab>'] = cmp.mapping.select_next_item(),
--['<S-Tab>'] = cmp.mapping.select_prev_item(),
-- Manually trigger a completion from nvim-cmp.
-- Generally you don't need this, because nvim-cmp will display
-- completions whenever it has completion options available.
['<C-Space>'] = cmp.mapping.complete {},
-- Think of <c-l> as moving to the right of your snippet expansion.
-- So if you have a snippet that's like:
-- function $name($args)
-- $body
-- end
--
-- <c-l> will move you to the right of each of the expansion locations.
-- <c-h> is similar, except moving you backwards.
['<C-l>'] = cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
end
end, { 'i', 's' }),
['<C-h>'] = cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
end
end, { 'i', 's' }),
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'path' },
},
}
end,
},
{ -- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
opts = {
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'vim', 'vimdoc' },
-- Autoinstall languages that are not installed
auto_install = true,
highlight = {
enable = true,
-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
-- If you are experiencing weird indenting issues, add the language to
-- the list of additional_vim_regex_highlighting and disabled languages for indent.
additional_vim_regex_highlighting = { 'ruby' },
},
indent = { enable = true, disable = { 'ruby' } },
},
config = function(_, opts)
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
-- Prefer git instead of curl in order to improve connectivity in some environments
require('nvim-treesitter.install').prefer_git = true
---@diagnostic disable-next-line: missing-fields
require('nvim-treesitter.configs').setup(opts)
-- There are additional nvim-treesitter modules that you can use to interact
-- with nvim-treesitter. You should go explore a few and see what interests you:
--
-- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
-- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
-- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
end,
},
{
'kevinhwang91/nvim-bqf',
ft = 'qf',
cmd = 'BqfAutoToggle',
event = 'QuickFixCmdPost',
opts = {
auto_resize_height = false,
func_map = {
tab = 'st',
split = 'sv',
vsplit = 'sg',
stoggleup = 'K',
stoggledown = 'J',
stogglevm = '<Space>',
ptoggleitem = 'p',
ptoggleauto = 'P',
ptogglemode = 'zp',
pscrollup = '<C-b>',
pscrolldown = '<C-f>',
prevfile = 'gk',
nextfile = 'gj',
prevhist = '<S-Tab>',
nexthist = '<Tab>',
},
preview = {
auto_preview = true,
should_preview_cb = function(bufnr)
-- file size greater than 100kb can't be previewed automatically
local filename = vim.api.nvim_buf_get_name(bufnr)
local fsize = vim.fn.getfsize(filename)
if fsize > 100 * 1024 then
return false
end
return true
end,
},
},
},
{
'rmagatti/goto-preview',
event = 'FileType',
2024-07-04 15:39:41 +02:00
keys = {
{
'gpd',
function()
require('goto-preview').goto_preview_definition()
end,
desc = 'Go to definition preview',
},
{
'gpD',
function()
require('goto-preview').goto_preview_declaration()
end,
desc = 'Go to declaration preview',
},
{
'gpi',
function()
require('goto-preview').goto_preview_implementation()
end,
desc = 'Go to implementaion preview',
},
{
'gpt',
function()
require('goto-preview').goto_preview_type_definition()
end,
desc = 'Go to type preview',
},
{
'gpt',
function()
require('goto-preview').goto_preview_type_references()
end,
desc = 'Preview references',
},
{
'gpc',
function()
require('goto-preview').close_all_win()
end,
desc = 'Close all preview windows',
},
},
2024-07-04 15:24:34 +02:00
config = function()
require('goto-preview').setup {}
end,
dependencies = 'nvim-telescope/telescope.nvim',
opts = {
width = 78,
height = 15,
default_mappings = false,
opacity = 10,
},
},
{ 'kosayoda/nvim-lightbulb', event = { 'BufReadPre', 'BufNewFile' } },
{
'mfussenegger/nvim-dap',
lazy = false,
init = function()
require('core.utils').load_mappings 'debug'
end,
config = function()
local dap = require 'dap'
local mason_registry = require 'mason-registry'
local codelldb_root = mason_registry.get_package('codelldb'):get_install_path() .. '/extension/'
local codelldb_path = codelldb_root .. 'adapter/codelldb'
local liblldb_path = codelldb_root .. 'lldb/lib/liblldb.so'
dap.defaults.fallback.external_terminal = {
command = '/home/plex/.local/bin/kitty',
args = {},
}
dap.adapters.gdb = {
type = 'executable',
command = 'gdb',
args = { '-i', 'dap' },
}
dap.adapters.codelldb = {
type = 'server',
port = '30333',
executable = {
command = codelldb_path,
args = { '--port', '30333' },
detached = false,
},
}
dap.configurations.cpp = {
{
name = 'Launch file',
type = 'codelldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
args = function()
return require('custom.utils').tokenize_args(vim.fn.input 'args: ')
end,
cwd = '${workspaceFolder}',
-- FIXME: perhaps we can put the stdio somewhere more practical
stopOnEntry = false,
},
}
dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cpp
end,
},
{
'rcarriga/nvim-dap-ui',
init = function()
require('core.utils').load_mappings 'debug'
end,
dependencies = {
'mfussenegger/nvim-dap',
'nvim-neotest/nvim-nio',
},
config = function(_, opts)
local dap = require 'dap'
local dapui = require 'dapui'
dapui.setup(opts)
dap.listeners.after.event_initialized['dapui_config'] = function()
dapui.open {}
end
dap.listeners.before.event_terminated['dapui_config'] = function()
-- dapui.close {}
end
dap.listeners.before.event_exited['dapui_config'] = function()
-- dapui.close {}
end
end,
},
{
'folke/lazydev.nvim',
ft = 'lua', -- only load on lua files
opts = {
library = {
-- See the configuration section for more details
-- Load luvit types when the `vim.uv` word is found
{ path = 'luvit-meta/library', words = { 'vim%.uv' } },
},
},
},
{ 'Bilal2453/luvit-meta', lazy = true }, -- optional `vim.uv` typings
{
'mrcjkb/rustaceanvim',
enabled = false,
version = '^4', -- Recommended
ft = { 'rust' },
config = function()
local dap = require 'dap'
vim.g.rustaceanvim = {
enable_clippy = true,
-- Plugin configuration
tools = {
enable_clippy = true,
},
-- LSP configuration
server = {
on_attach = function(client, bufnr)
-- you can also put keymaps in here
end,
settings = {
-- rust-analyzer language server configuration
['rust-analyzer'] = {
cargo = {
features = 'all',
},
},
},
},
-- DAP configuration
dap = {
-- FIXME: the rustaceanvim debug config does not map the stdout/stderr to the
-- opened terminal, effectively rendering debugging with it useless. Luckily,
-- we can use the regular nvim-dap and nvim-dap-ui.
adapter = dap.adapters.codelldb,
},
}
end,
},
{
'theHamsta/nvim-dap-virtual-text',
lazy = false, -- PERF: this can be done more elegant
config = function()
require('nvim-dap-virtual-text').setup()
end,
},
2024-07-04 12:41:35 +02:00
}