2023-05-20 12:44:21 +01:00
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
-- Mappings.
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
|
|
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
2023-06-05 15:56:25 +01:00
|
|
|
vim.keymap.set("n", "gd", "<cmd>TroubleToggle lsp_definitions<cr>")
|
|
|
|
vim.keymap.set("n", "gr", "<cmd>TroubleToggle lsp_references<cr>")
|
2023-05-20 12:44:21 +01:00
|
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
|
2023-07-16 21:41:45 +01:00
|
|
|
vim.keymap.set("n", "K", function() vim.lsp.buf.hover { popup_opts = { border = "rounded" } } end, bufopts)
|
2023-06-05 15:56:25 +01:00
|
|
|
vim.keymap.set("n", "<leader>D", "<cmd>TroubleToggle lsp_type_definitions<cr>")
|
2023-05-20 12:44:21 +01:00
|
|
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
|
|
|
|
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
|
|
|
|
vim.keymap.set(
|
|
|
|
"n",
|
|
|
|
"<leader>i",
|
|
|
|
function() vim.lsp.buf.format { bufnr = bufnr, timeout_ms = 2000, async = true } end,
|
|
|
|
bufopts
|
|
|
|
)
|
|
|
|
|
|
|
|
-- specific client tweaks
|
|
|
|
if client.name ~= "null-ls" then client.server_capabilities.documentFormattingProvider = false end
|
|
|
|
if client.name == "ruff_lsp" then client.server_capabilities.hoverProvider = false end
|
|
|
|
|
|
|
|
-- Attach navic and navbuddy if applicable
|
|
|
|
if client.server_capabilities.documentSymbolProvider then
|
|
|
|
require("nvim-navic").attach(client, bufnr)
|
|
|
|
require("nvim-navbuddy").attach(client, bufnr)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local config = function()
|
|
|
|
require("neodev").setup()
|
|
|
|
|
|
|
|
-- Mappings.
|
|
|
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
|
|
|
local opts = { noremap = true, silent = true }
|
|
|
|
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts)
|
|
|
|
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
|
|
|
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
|
|
|
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, opts)
|
|
|
|
|
2023-05-25 10:24:52 +01:00
|
|
|
local signs = require "ui.lsp_icons"
|
2023-05-20 12:44:21 +01:00
|
|
|
for type, icon in pairs(signs) do
|
|
|
|
local hl = "DiagnosticSign" .. type
|
|
|
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
|
|
|
end
|
|
|
|
|
2023-06-12 18:59:08 +01:00
|
|
|
local lsp_config = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
flags = { debounce_text_changes = 150 },
|
|
|
|
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
2023-05-20 12:44:21 +01:00
|
|
|
}
|
2023-06-16 16:41:55 +01:00
|
|
|
local lsp = require "lspconfig"
|
|
|
|
if vim.fn.executable "pyright" == 1 then
|
|
|
|
lsp["pyright"].setup(lsp_config)
|
|
|
|
elseif vim.fn.executable "pyslp" == 1 then
|
|
|
|
lsp["pylsp"].setup(lsp_config)
|
|
|
|
end
|
|
|
|
if vim.fn.executable "ruff-lsp" == 1 then lsp["ruff_lsp"].setup(lsp_config) end
|
2023-07-18 10:55:38 +01:00
|
|
|
if vim.fn.executable "lua-language-server" == 1 then
|
|
|
|
lsp["lua_ls"].setup {
|
|
|
|
on_attach = lsp_config.on_attach,
|
|
|
|
flags = lsp_config.flags,
|
|
|
|
capabilities = lsp_config.capabilities,
|
|
|
|
settings = { Lua = { workspace = { checkThirdParty = false } } },
|
|
|
|
}
|
|
|
|
end
|
2023-06-16 16:41:55 +01:00
|
|
|
if vim.fn.executable "nil" == 1 then lsp["nil_ls"].setup(lsp_config) end
|
|
|
|
if vim.fn.executable "fortls" == 1 then lsp["fortls"].setup(lsp_config) end
|
|
|
|
if vim.fn.executable "yaml-language-server" == 1 then lsp["yamlls"].setup(lsp_config) end
|
|
|
|
if vim.fn.executable "vim-language-server" == 1 then lsp["vimls"].setup(lsp_config) end
|
|
|
|
if vim.fn.executable "bash-language-server" == 1 then lsp["bashls"].setup(lsp_config) end
|
2023-05-20 12:44:21 +01:00
|
|
|
|
|
|
|
local builtins = require "null-ls.builtins"
|
|
|
|
require("null-ls").setup {
|
|
|
|
sources = {
|
|
|
|
builtins.code_actions.gitsigns,
|
|
|
|
builtins.formatting.alejandra,
|
|
|
|
builtins.formatting.beautysh,
|
|
|
|
builtins.formatting.black,
|
|
|
|
builtins.formatting.fixjson,
|
|
|
|
builtins.formatting.isort,
|
|
|
|
builtins.formatting.mdformat,
|
|
|
|
builtins.formatting.shellharden,
|
|
|
|
builtins.formatting.stylua,
|
|
|
|
builtins.hover.dictionary,
|
|
|
|
},
|
2023-06-12 18:59:08 +01:00
|
|
|
on_attach = lsp_config.on_attach,
|
|
|
|
flags = lsp_config.flags,
|
|
|
|
capabilities = lsp_config.capabilities,
|
2023-05-20 12:44:21 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-05-04 12:39:25 +01:00
|
|
|
return {
|
2023-05-16 09:22:33 +01:00
|
|
|
"neovim/nvim-lspconfig",
|
2023-05-20 12:44:21 +01:00
|
|
|
event = { "BufReadPre", "BufNewFile" },
|
2023-06-16 16:41:55 +01:00
|
|
|
dependencies = { "cmp-nvim-lsp", "folke/trouble.nvim", "folke/neodev.nvim", "jose-elias-alvarez/null-ls.nvim" },
|
2023-05-20 12:44:21 +01:00
|
|
|
config = config,
|
2023-05-04 12:39:25 +01:00
|
|
|
}
|