Evie Litherland-Smith
7d3109f60e
Make nvim-cmp standalone, lazy lone on InsertEnter and be used by neorg to enable treesitter integration (no LSP available) Move LSP config into lspconfig.lua Optimise some startup conditions
94 lines
3.3 KiB
Lua
94 lines
3.3 KiB
Lua
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 }
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
|
|
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
|
|
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)
|
|
|
|
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
|
for type, icon in pairs(signs) do
|
|
local hl = "DiagnosticSign" .. type
|
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
|
end
|
|
|
|
local lsp_flags = { debounce_text_changes = 150 }
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
local servers = {
|
|
"pyright",
|
|
"ruff_lsp",
|
|
"nil_ls",
|
|
"lua_ls",
|
|
"fortls",
|
|
"yamlls",
|
|
"vimls",
|
|
"bashls",
|
|
}
|
|
for _, name in ipairs(servers) do
|
|
require("lspconfig")[name].setup {
|
|
on_attach = on_attach,
|
|
flags = lsp_flags,
|
|
capabilities = capabilities,
|
|
}
|
|
end
|
|
|
|
local builtins = require "null-ls.builtins"
|
|
require("null-ls").setup {
|
|
sources = {
|
|
builtins.code_actions.gitsigns,
|
|
builtins.formatting.alejandra,
|
|
builtins.formatting.autoflake,
|
|
builtins.formatting.beautysh,
|
|
builtins.formatting.black,
|
|
builtins.formatting.fixjson,
|
|
builtins.formatting.isort,
|
|
builtins.formatting.mdformat,
|
|
builtins.formatting.shellharden,
|
|
builtins.formatting.stylua,
|
|
builtins.hover.dictionary,
|
|
},
|
|
on_attach = on_attach,
|
|
flags = lsp_flags,
|
|
capabilities = capabilities,
|
|
}
|
|
end
|
|
|
|
return {
|
|
"neovim/nvim-lspconfig",
|
|
event = { "BufReadPre", "BufNewFile" },
|
|
dependencies = { "cmp-nvim-lsp", "folke/neodev.nvim", "jose-elias-alvarez/null-ls.nvim" },
|
|
config = config,
|
|
}
|