Split up lsp config
This commit is contained in:
parent
60e3dce6f3
commit
1a645ecd7d
@ -50,4 +50,7 @@ end
|
|||||||
|
|
||||||
vim.opt.rtp:prepend(lazypath)
|
vim.opt.rtp:prepend(lazypath)
|
||||||
|
|
||||||
require("lazy").setup("valeth.plugins")
|
require("lazy").setup({
|
||||||
|
{ import = "valeth.plugins" },
|
||||||
|
{ import = "valeth.plugins.lsp" },
|
||||||
|
})
|
||||||
|
@ -13,4 +13,6 @@ return {
|
|||||||
"numToStr/Comment.nvim",
|
"numToStr/Comment.nvim",
|
||||||
opts = {},
|
opts = {},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"nvim-lua/plenary.nvim",
|
||||||
}
|
}
|
||||||
|
@ -1,118 +0,0 @@
|
|||||||
local spec = {
|
|
||||||
"VonHeikemen/lsp-zero.nvim",
|
|
||||||
branch = "v2.x",
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.dependencies = {
|
|
||||||
"neovim/nvim-lspconfig",
|
|
||||||
-- completion
|
|
||||||
"hrsh7th/nvim-cmp",
|
|
||||||
"hrsh7th/cmp-nvim-lsp",
|
|
||||||
"hrsh7th/cmp-path",
|
|
||||||
"onsails/lspkind.nvim",
|
|
||||||
-- formatting
|
|
||||||
"mhartington/formatter.nvim",
|
|
||||||
-- snippets
|
|
||||||
"saadparwaiz1/cmp_luasnip",
|
|
||||||
"L3MON4D3/LuaSnip",
|
|
||||||
"rafamadriz/friendly-snippets",
|
|
||||||
-- lsp manager
|
|
||||||
"williamboman/mason.nvim",
|
|
||||||
"williamboman/mason-lspconfig.nvim",
|
|
||||||
-- code folding
|
|
||||||
"kevinhwang91/nvim-ufo",
|
|
||||||
"kevinhwang91/promise-async",
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.config = function()
|
|
||||||
local lsp_zero = require("lsp-zero").preset({})
|
|
||||||
local ufo = require("ufo")
|
|
||||||
local tsb = require("telescope.builtin")
|
|
||||||
|
|
||||||
lsp_zero.ensure_installed {
|
|
||||||
"lua_ls",
|
|
||||||
"rust_analyzer",
|
|
||||||
}
|
|
||||||
|
|
||||||
lsp_zero.on_attach(function(_, buffnr)
|
|
||||||
local opts = { buffer = buffnr, remap = false }
|
|
||||||
|
|
||||||
ufo.attach(buffnr)
|
|
||||||
|
|
||||||
vim.keymap.set("n", "gd", tsb.lsp_definitions, opts)
|
|
||||||
vim.keymap.set("n", "gr", tsb.lsp_references, opts)
|
|
||||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
|
||||||
vim.keymap.set("n", "<Leader>ca", vim.lsp.buf.code_action, opts)
|
|
||||||
vim.keymap.set("n", "<Leader>ci", vim.diagnostic.open_float, opts)
|
|
||||||
vim.keymap.set("n", "<Leader>re", vim.lsp.buf.rename, opts)
|
|
||||||
vim.keymap.set({ "n", "i" }, "<C-h>", vim.lsp.buf.signature_help, opts)
|
|
||||||
|
|
||||||
vim.keymap.set("n", "<Leader>fmt", function()
|
|
||||||
vim.lsp.buf.format({ async = false, timeout_ms = 5000 })
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
-- NOTE: Format on save does not support async formatting
|
|
||||||
lsp_zero.format_on_save({
|
|
||||||
servers = {
|
|
||||||
["rust_analyzer"] = { "rust" }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
local lsp_config = require("lspconfig")
|
|
||||||
|
|
||||||
lsp_config.lua_ls.setup(lsp_zero.nvim_lua_ls())
|
|
||||||
|
|
||||||
lsp_config.rust_analyzer.setup {
|
|
||||||
settings = {
|
|
||||||
["rust-analyzer"] = {
|
|
||||||
cargo = {
|
|
||||||
features = "all"
|
|
||||||
},
|
|
||||||
rustfmt = {
|
|
||||||
-- needs to use nightly channel to use unstable options
|
|
||||||
extraArgs = { "+nightly" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ufo.setup {
|
|
||||||
close_fold_kinds = {"comment", "imports"},
|
|
||||||
}
|
|
||||||
|
|
||||||
lsp_zero.setup()
|
|
||||||
|
|
||||||
local cmp = require("cmp")
|
|
||||||
local lspk = require("lspkind")
|
|
||||||
|
|
||||||
local cmp_select = { behavior = cmp.SelectBehavior.Select }
|
|
||||||
cmp.setup {
|
|
||||||
formatting = {
|
|
||||||
format = lspk.cmp_format({}),
|
|
||||||
},
|
|
||||||
mapping = {
|
|
||||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
|
||||||
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
|
|
||||||
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
|
|
||||||
["<C-Space>"] = cmp.mapping.complete(),
|
|
||||||
["<Tab>"] = nil,
|
|
||||||
["<S-Tab>"] = nil,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vim.diagnostic.config({
|
|
||||||
virtual_text = false,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Gimme pretty icons
|
|
||||||
lsp_zero.set_sign_icons({
|
|
||||||
error = '✘',
|
|
||||||
warn = '▲',
|
|
||||||
hint = '⚑',
|
|
||||||
info = '»'
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
return spec
|
|
40
lua/valeth/plugins/lsp/cmp.lua
Normal file
40
lua/valeth/plugins/lsp/cmp.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
local spec = {
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
event = "LspAttach",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.dependencies = {
|
||||||
|
"VonHeikemen/lsp-zero.nvim",
|
||||||
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
|
"hrsh7th/cmp-path",
|
||||||
|
"onsails/lspkind.nvim",
|
||||||
|
"saadparwaiz1/cmp_luasnip",
|
||||||
|
"L3MON4D3/LuaSnip",
|
||||||
|
"rafamadriz/friendly-snippets",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.config = function()
|
||||||
|
local cmp = require("cmp")
|
||||||
|
local lspk = require("lspkind")
|
||||||
|
|
||||||
|
local cmp_select = { behavior = cmp.SelectBehavior.Select }
|
||||||
|
|
||||||
|
cmp.setup {
|
||||||
|
formatting = {
|
||||||
|
format = lspk.cmp_format({
|
||||||
|
mode = "symbol_text",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
mapping = {
|
||||||
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||||
|
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
|
||||||
|
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
|
||||||
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
|
["<Tab>"] = nil,
|
||||||
|
["<S-Tab>"] = nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return spec
|
43
lua/valeth/plugins/lsp/init.lua
Normal file
43
lua/valeth/plugins/lsp/init.lua
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
-- TODO: figure out how to configure auto formatting and drop lsp-zero
|
||||||
|
local spec = {
|
||||||
|
"VonHeikemen/lsp-zero.nvim",
|
||||||
|
branch = "v2.x",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.dependencies = {
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
"mhartington/formatter.nvim",
|
||||||
|
"williamboman/mason.nvim",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.config = function()
|
||||||
|
local lsp_zero = require("lsp-zero").preset({})
|
||||||
|
|
||||||
|
-- NOTE: Format on save does not support async formatting
|
||||||
|
lsp_zero.format_on_save({
|
||||||
|
servers = {
|
||||||
|
["rust_analyzer"] = { "rust" }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
local lsp_config = require("lspconfig")
|
||||||
|
|
||||||
|
lsp_config.lua_ls.setup(lsp_zero.nvim_lua_ls())
|
||||||
|
|
||||||
|
lsp_zero.setup()
|
||||||
|
|
||||||
|
vim.diagnostic.config({
|
||||||
|
virtual_text = false,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Gimme pretty icons
|
||||||
|
lsp_zero.set_sign_icons({
|
||||||
|
error = '✘',
|
||||||
|
warn = '▲',
|
||||||
|
hint = '⚑',
|
||||||
|
info = '»'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
return spec
|
49
lua/valeth/plugins/lsp/lspconfig.lua
Normal file
49
lua/valeth/plugins/lsp/lspconfig.lua
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
local spec = {
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.dependencies = {
|
||||||
|
"nvim-telescope/telescope.nvim",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.config = function()
|
||||||
|
local lsp_config = require("lspconfig")
|
||||||
|
local tsb = require("telescope.builtin")
|
||||||
|
local autocmd = vim.api.nvim_create_autocmd
|
||||||
|
local autogroup = vim.api.nvim_create_augroup
|
||||||
|
|
||||||
|
autocmd("LspAttach", {
|
||||||
|
group = autogroup("LspAttachConfig", {}),
|
||||||
|
callback = function(event)
|
||||||
|
local opts = { buffer = event.buf, remap = false }
|
||||||
|
|
||||||
|
vim.keymap.set("n", "gd", tsb.lsp_definitions, opts)
|
||||||
|
vim.keymap.set("n", "gr", tsb.lsp_references, opts)
|
||||||
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||||
|
vim.keymap.set("n", "<Leader>ca", vim.lsp.buf.code_action, opts)
|
||||||
|
vim.keymap.set("n", "<Leader>ci", vim.diagnostic.open_float, opts)
|
||||||
|
vim.keymap.set("n", "<Leader>re", vim.lsp.buf.rename, opts)
|
||||||
|
vim.keymap.set({ "n", "i" }, "<C-h>", vim.lsp.buf.signature_help, opts)
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<Leader>fmt", function()
|
||||||
|
vim.lsp.buf.format({ async = false, timeout_ms = 5000 })
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
lsp_config.rust_analyzer.setup {
|
||||||
|
settings = {
|
||||||
|
["rust-analyzer"] = {
|
||||||
|
cargo = {
|
||||||
|
features = "all"
|
||||||
|
},
|
||||||
|
rustfmt = {
|
||||||
|
-- needs to use nightly channel to use unstable options
|
||||||
|
extraArgs = { "+nightly" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return spec
|
32
lua/valeth/plugins/lsp/mason.lua
Normal file
32
lua/valeth/plugins/lsp/mason.lua
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
local spec = {
|
||||||
|
"williamboman/mason.nvim",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.dependencies = {
|
||||||
|
"williamboman/mason-lspconfig.nvim",
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.config = function()
|
||||||
|
local mason = require("mason")
|
||||||
|
local mason_lspconfig = require("mason-lspconfig")
|
||||||
|
|
||||||
|
mason.setup({
|
||||||
|
ui = {
|
||||||
|
icons = {
|
||||||
|
package_installed = "✓",
|
||||||
|
package_pending = "➜",
|
||||||
|
package_uninstalled = "✗"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
mason_lspconfig.setup({
|
||||||
|
ensure_installed = {
|
||||||
|
"lua_ls",
|
||||||
|
"rust_analyzer",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
return spec
|
27
lua/valeth/plugins/lsp/ufo.lua
Normal file
27
lua/valeth/plugins/lsp/ufo.lua
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
local spec = {
|
||||||
|
"kevinhwang91/nvim-ufo",
|
||||||
|
event = "LspAttach",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.dependencies = {
|
||||||
|
"kevinhwang91/promise-async",
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.config = function()
|
||||||
|
local ufo = require("ufo")
|
||||||
|
local autocmd = vim.api.nvim_create_autocmd
|
||||||
|
local autogroup = vim.api.nvim_create_augroup
|
||||||
|
|
||||||
|
autocmd("LspAttach", {
|
||||||
|
group = autogroup("LspUfo", {}),
|
||||||
|
callback = function(event)
|
||||||
|
ufo.attach(event.buf)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
ufo.setup {
|
||||||
|
close_fold_kinds = {"comment", "imports"},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return spec
|
Loading…
Reference in New Issue
Block a user