add LSP config

This commit is contained in:
Oliver Ladner 2023-11-28 12:55:20 +01:00
commit 8cd3dd5b8e
4 changed files with 130 additions and 7 deletions

View file

@ -12,5 +12,4 @@ if not vim.loop.fs_stat(lazypath) then
end
vim.opt.rtp:prepend(lazypath)
--require("lazy").setup({ { import = "weeheavy.plugins" }, { import = "weeheavy.plugins.lsp" } })
require("lazy").setup({ { import = "weeheavy.plugins" } })
require("lazy").setup({ { import = "weeheavy.plugins" }, { import = "weeheavy.plugins.lsp" } })

View file

@ -0,0 +1,30 @@
-- Some things are from https://www.josean.com/posts/neovim-linting-and-formatting
return {
"stevearc/conform.nvim",
opts = {},
config = function()
local conform = require("conform")
conform.setup({
formatters_by_ft = {
javascript = { "prettier" },
typescript = { "prettier" },
javascriptreact = { "prettier" },
typescriptreact = { "prettier" },
svelte = { "prettier" },
css = { "prettier" },
html = { "prettier" },
json = { "prettier" },
yaml = { "prettier" },
markdown = { "prettier" },
graphql = { "prettier" },
lua = { "stylua" },
python = { "isort", "black" },
},
format_on_save = {
lsp_fallback = true,
async = false,
timeout_ms = 1000, -- default: 1000
},
})
end,
}

View file

@ -0,0 +1,93 @@
return {
{
'VonHeikemen/lsp-zero.nvim',
branch = 'v3.x',
lazy = true,
config = false,
init = function()
-- Disable automatic setup, we are doing it manually
vim.g.lsp_zero_extend_cmp = 0
vim.g.lsp_zero_extend_lspconfig = 0
end,
},
{
'williamboman/mason.nvim',
lazy = false,
config = true,
},
{
'hrsh7th/nvim-cmp',
event = 'InsertEnter',
dependencies = {
{'L3MON4D3/LuaSnip'},
},
config = function()
-- Here is where you configure the autocompletion settings.
local lsp_zero = require('lsp-zero')
lsp_zero.extend_cmp()
local cmp = require('cmp')
local cmp_action = lsp_zero.cmp_action()
local cmp_select = { behavior = cmp.SelectBehavior.Select }
cmp.setup({
formatting = lsp_zero.cmp_format(),
mapping = cmp.mapping.preset.insert({
['<C-Space>'] = cmp.mapping.complete(),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-l>'] = cmp.mapping.confirm({select = true}), -- accept LSP autocompletion
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-f>'] = cmp_action.luasnip_jump_forward(),
['<C-b>'] = cmp_action.luasnip_jump_backward(),
})
})
end
},
-- LSP
{
'neovim/nvim-lspconfig',
cmd = {'LspInfo', 'LspInstall', 'LspStart'},
event = {'BufReadPre', 'BufNewFile'},
dependencies = {
{'hrsh7th/cmp-nvim-lsp'},
{'williamboman/mason-lspconfig.nvim'},
},
config = function()
-- This is where all the LSP shenanigans will live
local lsp_zero = require('lsp-zero')
lsp_zero.extend_lspconfig()
-- Keybindings only active when a LS is active for the curr. file
lsp_zero.on_attach(function(client, bufnr)
-- see :help lsp-zero-keybindings
-- to learn the available actions
lsp_zero.default_keymaps({buffer = bufnr})
end)
require('mason').setup({
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
})
require('mason-lspconfig').setup({
ensure_installed = {},
handlers = {
lsp_zero.default_setup,
lua_ls = function()
-- (Optional) Configure lua language server for neovim
local lua_opts = lsp_zero.nvim_lua_ls()
require('lspconfig').lua_ls.setup(lua_opts)
end,
}
})
end
}
}