Separate LSP config and nvim-cmp
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
This commit is contained in:
parent
2a3c867b11
commit
7d3109f60e
|
@ -1,31 +0,0 @@
|
||||||
-- Use an on_attach function to only map the following keys
|
|
||||||
-- after the language server attaches to the current buffer
|
|
||||||
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
|
|
||||||
return on_attach
|
|
|
@ -1,53 +0,0 @@
|
||||||
local cmp = require "cmp"
|
|
||||||
local luasnip = require "luasnip"
|
|
||||||
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
|
|
||||||
|
|
||||||
cmp.setup {
|
|
||||||
snippet = {
|
|
||||||
expand = function(args)
|
|
||||||
luasnip.lsp_expand(args.body) -- For `luasnip` users.
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
mapping = cmp.mapping.preset.insert {
|
|
||||||
["<C-u>"] = cmp.mapping.scroll_docs(-4), -- Up
|
|
||||||
["<C-d>"] = cmp.mapping.scroll_docs(4), -- Down
|
|
||||||
["<C-Space>"] = cmp.mapping.complete(),
|
|
||||||
["<CR>"] = cmp.mapping.confirm {
|
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
|
||||||
select = true,
|
|
||||||
},
|
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if cmp.visible() then
|
|
||||||
cmp.select_next_item()
|
|
||||||
elseif luasnip.expand_or_jumpable() then
|
|
||||||
luasnip.expand_or_jump()
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, { "i", "s" }),
|
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if cmp.visible() then
|
|
||||||
cmp.select_prev_item()
|
|
||||||
elseif luasnip.jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, { "i", "s" }),
|
|
||||||
},
|
|
||||||
sources = {
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
{ name = "luasnip" },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Set configuration for specific filetype.
|
|
||||||
-- cmp.setup.filetype("python", { sources = { { name = "nvim_lsp" } } })
|
|
||||||
-- cmp.setup.filetype("nix", { sources = { { name = "nvim_lsp" } } })
|
|
||||||
cmp.setup.cmdline("/", { mapping = cmp.mapping.preset.cmdline(), sources = { { name = "buffer" } } })
|
|
||||||
cmp.setup.cmdline(":", {
|
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
|
||||||
sources = { { name = "cmdline" }, { name = "path" } },
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
|
|
@ -1,39 +0,0 @@
|
||||||
local M = {}
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
|
|
||||||
require("neodev").setup()
|
|
||||||
|
|
||||||
M.on_attach = require "lsp.attach"
|
|
||||||
M.lsp_flags = require "lsp.flags"
|
|
||||||
M.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 = M.on_attach,
|
|
||||||
flags = M.lsp_flags,
|
|
||||||
capabilities = M.capabilities,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
require("null-ls").setup {
|
|
||||||
sources = require "lsp.null_ls_sources",
|
|
||||||
on_attach = M.on_attach,
|
|
||||||
flags = M.lsp_flags,
|
|
||||||
capabilities = M.capabilities,
|
|
||||||
}
|
|
||||||
|
|
||||||
return M
|
|
|
@ -1,5 +0,0 @@
|
||||||
local lsp_flags = {
|
|
||||||
-- This is the default in Nvim 0.7+
|
|
||||||
debounce_text_changes = 150,
|
|
||||||
}
|
|
||||||
return lsp_flags
|
|
|
@ -1,19 +0,0 @@
|
||||||
local null_ls = require "null-ls"
|
|
||||||
return {
|
|
||||||
null_ls.builtins.code_actions.gitsigns,
|
|
||||||
|
|
||||||
null_ls.builtins.formatting.alejandra,
|
|
||||||
null_ls.builtins.formatting.autoflake,
|
|
||||||
null_ls.builtins.formatting.beautysh,
|
|
||||||
null_ls.builtins.formatting.black,
|
|
||||||
null_ls.builtins.formatting.fixjson,
|
|
||||||
-- null_ls.builtins.formatting.fprettify,
|
|
||||||
null_ls.builtins.formatting.isort,
|
|
||||||
null_ls.builtins.formatting.mdformat,
|
|
||||||
-- null_ls.builtins.formatting.nixfmt,
|
|
||||||
-- null_ls.builtins.formatting.nixpkgs_fmt,
|
|
||||||
null_ls.builtins.formatting.shellharden,
|
|
||||||
null_ls.builtins.formatting.stylua,
|
|
||||||
|
|
||||||
null_ls.builtins.hover.dictionary,
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
return {
|
return {
|
||||||
"numToStr/Comment.nvim",
|
"numToStr/Comment.nvim",
|
||||||
keys = { "gcc", "gcb" },
|
keys = { "gcc", "gcb" },
|
||||||
event = { "BufReadPre" },
|
|
||||||
config = true,
|
config = true,
|
||||||
opts = { ignore = "^$" },
|
opts = { ignore = "^$" },
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,93 @@
|
||||||
|
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 {
|
return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
event = { "BufReadPre", "BufNewFile", "CmdlineEnter" },
|
event = { "BufReadPre", "BufNewFile" },
|
||||||
dependencies = {
|
dependencies = { "cmp-nvim-lsp", "folke/neodev.nvim", "jose-elias-alvarez/null-ls.nvim" },
|
||||||
{ "hrsh7th/cmp-nvim-lsp", dependencies = { "hrsh7th/nvim-cmp" } },
|
config = config,
|
||||||
{ "hrsh7th/cmp-buffer", dependencies = { "hrsh7th/nvim-cmp" } },
|
|
||||||
{ "hrsh7th/cmp-path", dependencies = { "hrsh7th/nvim-cmp" } },
|
|
||||||
{ "hrsh7th/cmp-cmdline", dependencies = { "hrsh7th/nvim-cmp" } },
|
|
||||||
{ "L3MON4D3/LuaSnip", dependencies = { "hrsh7th/nvim-cmp", "saadparwaiz1/cmp_luasnip" } },
|
|
||||||
{ "windwp/nvim-autopairs", dependencies = { "hrsh7th/nvim-cmp" } },
|
|
||||||
{ "folke/neodev.nvim", dependencies = { "hrsh7th/nvim-cmp" } },
|
|
||||||
{ "jose-elias-alvarez/null-ls.nvim", dependencies = { "davidmh/cspell.nvim" } },
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
require "lsp.config"
|
|
||||||
require "lsp.cmp"
|
|
||||||
end,
|
|
||||||
}
|
}
|
||||||
|
|
9
lua/plugins/luasnip.lua
Normal file
9
lua/plugins/luasnip.lua
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
return {
|
||||||
|
"L3MON4D3/LuaSnip",
|
||||||
|
lazy = true,
|
||||||
|
dependencies = {
|
||||||
|
"rafamadriz/friendly-snippets",
|
||||||
|
config = function() require("luasnip.loaders.from_vscode").lazy_load() end,
|
||||||
|
},
|
||||||
|
-- build = "make install_jsregexp",
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
return {
|
return {
|
||||||
"dccsillag/magma-nvim",
|
"dccsillag/magma-nvim",
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
event = { "FileType python" },
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,6 @@ return {
|
||||||
opts = {
|
opts = {
|
||||||
disable_commit_confirmation = true,
|
disable_commit_confirmation = true,
|
||||||
disable_builtin_notifications = true,
|
disable_builtin_notifications = true,
|
||||||
-- kind = "floating",
|
|
||||||
-- commit_popup = { kind = "floating" },
|
|
||||||
-- preview_buffer = { kind = "floating" },
|
|
||||||
-- popup = { kind = "floating" },
|
|
||||||
integrations = { diffview = true },
|
integrations = { diffview = true },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
return {
|
return {
|
||||||
"rcarriga/nvim-notify",
|
"rcarriga/nvim-notify",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
-- dependencies = { "catppuccin" },
|
|
||||||
config = true,
|
config = true,
|
||||||
opts = {
|
opts = {
|
||||||
-- background_colour = require("catppuccin.palettes").get_palette("macchiato").base,
|
|
||||||
fps = 60,
|
fps = 60,
|
||||||
render = "default", -- "minimal", "simple"
|
render = "default", -- "minimal", "simple"
|
||||||
},
|
},
|
||||||
|
|
66
lua/plugins/nvim_cmp.lua
Normal file
66
lua/plugins/nvim_cmp.lua
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
local config = function()
|
||||||
|
local cmp = require "cmp"
|
||||||
|
local luasnip = require "luasnip"
|
||||||
|
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
|
||||||
|
|
||||||
|
cmp.setup {
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body) -- For `luasnip` users.
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = cmp.mapping.preset.insert {
|
||||||
|
["<C-u>"] = cmp.mapping.scroll_docs(-4), -- Up
|
||||||
|
["<C-d>"] = cmp.mapping.scroll_docs(4), -- Down
|
||||||
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
|
["<CR>"] = cmp.mapping.confirm {
|
||||||
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
|
select = true,
|
||||||
|
},
|
||||||
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
},
|
||||||
|
sources = { { name = "nvim_lsp" }, { name = "luasnip" } },
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Set configuration for specific filetype.
|
||||||
|
cmp.setup.filetype("norg", { sources = { { name = "neorg" } } })
|
||||||
|
cmp.setup.cmdline({ "/", "?" }, { mapping = cmp.mapping.preset.cmdline(), sources = { { name = "buffer" } } })
|
||||||
|
cmp.setup.cmdline(
|
||||||
|
":",
|
||||||
|
{ mapping = cmp.mapping.preset.cmdline(), sources = { { name = "path" }, { name = "cmdline" } } }
|
||||||
|
)
|
||||||
|
|
||||||
|
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
event = { "InsertEnter", "CmdlineEnter" },
|
||||||
|
dependencies = {
|
||||||
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
|
"hrsh7th/cmp-buffer",
|
||||||
|
"hrsh7th/cmp-path",
|
||||||
|
"hrsh7th/cmp-cmdline",
|
||||||
|
"windwp/nvim-autopairs",
|
||||||
|
"saadparwaiz1/cmp_luasnip",
|
||||||
|
"L3MON4D3/LuaSnip",
|
||||||
|
},
|
||||||
|
config = config,
|
||||||
|
}
|
|
@ -1,18 +1,26 @@
|
||||||
return {
|
return {
|
||||||
"nvim-neorg/neorg",
|
"nvim-neorg/neorg",
|
||||||
build = ":Neorg sync-parsers",
|
build = ":Neorg sync-parsers",
|
||||||
dependencies = { { "nvim-lua/plenary.nvim" } },
|
event = { "FileType norg" },
|
||||||
|
cmd = "Neorg",
|
||||||
|
lazy = true,
|
||||||
|
dependencies = { "nvim-lua/plenary.nvim", "nvim-treesitter/nvim-treesitter" },
|
||||||
|
init = function()
|
||||||
|
vim.api.nvim_create_autocmd({ "BufNewFile", "BufReadPost" }, {
|
||||||
|
pattern = { "*.norg" },
|
||||||
|
command = "set filetype=norg",
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
|
pattern = { "*.norg" },
|
||||||
|
command = "Neorg update-metadata",
|
||||||
|
})
|
||||||
|
end,
|
||||||
opts = {
|
opts = {
|
||||||
load = {
|
load = {
|
||||||
["core.defaults"] = {}, -- Loads default behaviour
|
["core.defaults"] = {},
|
||||||
["core.concealer"] = {}, -- Adds pretty icons to your documents
|
["core.concealer"] = {},
|
||||||
["core.dirman"] = { -- Manages Neorg workspaces
|
["core.dirman"] = { config = { workspaces = { notes = "~/notes" } } },
|
||||||
config = {
|
["core.completion"] = { config = { engine = "nvim-cmp" } },
|
||||||
workspaces = {
|
|
||||||
notes = "~/notes",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue