mirror of
https://github.com/szymon-jozef/superior_dotfiles.git
synced 2026-09-07 12:10:38 +02:00
Add .config/nvim/init.lua
Add .config/nvim/lazy-lock.json Add .config/nvim/lua/config/lazy.lua Add .config/nvim/lua/config/remaps.lua Add .config/nvim/lua/config/set.lua Add .config/nvim/lua/plugins/colorscheme.lua Add .config/nvim/lua/plugins/git.lua Add .config/nvim/lua/plugins/harpoon.lua Add .config/nvim/lua/plugins/lsp.lua Add .config/nvim/lua/plugins/telescope.lua Add .config/nvim/lua/plugins/whichkey.lua Add .config/nvim/spell/pl.cp1250.spl Add .config/nvim/spell/pl.iso-8859-2.spl Add .config/nvim/spell/pl.utf-8.spl
This commit is contained in:
115
private_dot_config/nvim/lua/plugins/lsp.lua
Normal file
115
private_dot_config/nvim/lua/plugins/lsp.lua
Normal file
@@ -0,0 +1,115 @@
|
||||
return {
|
||||
'neovim/nvim-lspconfig',
|
||||
lazy = false,
|
||||
dependencies = {
|
||||
{
|
||||
"mason-org/mason.nvim",
|
||||
opts = {
|
||||
modifiable = true
|
||||
}
|
||||
},
|
||||
{
|
||||
"mason-org/mason-lspconfig.nvim",
|
||||
opts = {},
|
||||
},
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
'hrsh7th/cmp-buffer',
|
||||
'hrsh7th/cmp-path',
|
||||
'hrsh7th/cmp-cmdline',
|
||||
'hrsh7th/nvim-cmp',
|
||||
'saadparwaiz1/cmp_luasnip',
|
||||
{ "L3MON4D3/LuaSnip", build = "make install_jsregexp" },
|
||||
},
|
||||
config = function()
|
||||
local cmp_lsp = require("cmp_nvim_lsp")
|
||||
local cmp = require("cmp")
|
||||
local cmp_select = { behavior = cmp.SelectBehavior.Select }
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
||||
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
||||
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
},
|
||||
{
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
})
|
||||
local capabilities = vim.tbl_deep_extend(
|
||||
"force",
|
||||
{},
|
||||
vim.lsp.protocol.make_client_capabilities(),
|
||||
cmp_lsp.default_capabilities()
|
||||
)
|
||||
vim.diagnostic.config({
|
||||
virtual_text = {
|
||||
prefix = "●",
|
||||
spacing = 2,
|
||||
source = "if_many",
|
||||
},
|
||||
signs = true,
|
||||
underline = true,
|
||||
update_in_insert = false
|
||||
})
|
||||
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"lua_ls",
|
||||
"clangd",
|
||||
"rust_analyzer"
|
||||
},
|
||||
handlers = {
|
||||
function(server_name)
|
||||
require("lspconfig")[server_name].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end
|
||||
},
|
||||
automatic_enable = true,
|
||||
})
|
||||
|
||||
local buffer_autoformat = function(bufnr)
|
||||
local group = 'lsp_autoformat'
|
||||
vim.api.nvim_create_augroup(group, { clear = false })
|
||||
vim.api.nvim_clear_autocmds({ group = group, buffer = bufnr })
|
||||
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
buffer = bufnr,
|
||||
group = group,
|
||||
desc = "Lsp format on save",
|
||||
callback = function()
|
||||
vim.lsp.buf.format({ async = false, timeout_ms = 10000 })
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
callback = function(event)
|
||||
local id = vim.tbl_get(event, 'data', 'client_id')
|
||||
local client = id and vim.lsp.get_client_by_id(id)
|
||||
|
||||
if client == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if client.supports_method('textDocument/formatting') then
|
||||
buffer_autoformat(event.buf)
|
||||
end
|
||||
end
|
||||
})
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user