Files
dotfiles/.config/nvim/after/plugin/lspconfig.lua

183 lines
6.3 KiB
Lua
Raw Normal View History

2024-04-20 23:39:31 +02:00
local opts = { noremap = true, silent = true }
2022-10-23 21:49:38 +02:00
vim.keymap.set('n', '<space>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)
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
2024-04-20 23:39:31 +02:00
local bufopts = { noremap = true, silent = true, buffer = bufnr }
2022-10-23 21:49:38 +02:00
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'gT', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
2024-04-20 23:39:31 +02:00
vim.keymap.set('n', '<space>f',
2024-09-30 15:16:37 +02:00
function() vim.lsp.buf.format { async = true, filter = function(c) return c.name ~= "ts_ls" end } end, bufopts)
2022-10-23 21:49:38 +02:00
end
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
2024-04-20 23:39:31 +02:00
require 'lspconfig'.clangd.setup {
2022-10-23 21:49:38 +02:00
on_attach = on_attach,
capabilities = capabilities,
}
2024-09-30 15:16:37 +02:00
require 'lspconfig'.ts_ls.setup {
2022-10-23 21:49:38 +02:00
on_attach = on_attach,
capabilities = capabilities,
}
2024-04-20 23:39:31 +02:00
require 'lspconfig'.pyright.setup {
2022-10-23 21:49:38 +02:00
on_attach = on_attach,
capabilities = capabilities,
}
2024-04-20 23:39:31 +02:00
require 'lspconfig'.eslint.setup {
on_attach = on_attach,
capabilities = capabilities,
settings = {
format = false
},
}
require 'lspconfig'.rust_analyzer.setup {
2022-10-23 21:49:38 +02:00
on_attach = on_attach,
capabilities = capabilities,
2023-02-04 13:39:28 +01:00
cmd = {
"rustup", "run", "stable", "rust-analyzer",
},
2022-10-23 21:49:38 +02:00
}
2024-04-20 23:39:31 +02:00
require 'lspconfig'.phpactor.setup {
2022-10-23 21:49:38 +02:00
on_attach = on_attach,
init_options = {
["language_server_phpstan.enabled"] = false,
["language_server_psalm.enabled"] = false,
}
}
2024-04-20 23:39:31 +02:00
require 'lspconfig'.asm_lsp.setup {
2024-01-12 20:55:44 +01:00
on_attach = on_attach,
capabilities = capabilities,
cmd = {
"/home/dobiadi/.cargo/bin/asm-lsp"
},
}
2024-04-20 23:39:31 +02:00
require 'lspconfig'.elixirls.setup {
2024-01-12 20:55:44 +01:00
on_attach = on_attach,
capabilities = capabilities,
cmd = {
"elixir-ls"
},
}
2024-01-23 14:40:50 +01:00
require'lspconfig'.terraformls.setup{
on_attach = on_attach,
capabilities = capabilities,
}
2024-04-20 23:39:31 +02:00
require 'lspconfig'.lua_ls.setup {
on_attach = on_attach,
capabilities = capabilities,
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then
return
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {}
}
}
vim.opt.completeopt = { "menu", "menuone", "noselect" }
2022-10-23 21:49:38 +02:00
-- Set up nvim-cmp.
2024-04-20 23:39:31 +02:00
local cmp = require 'cmp'
2022-10-23 21:49:38 +02:00
cmp.setup({
2023-02-04 13:51:16 +01:00
preselect = cmp.PreselectMode.None,
2022-10-23 21:49:38 +02:00
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
{ name = 'nvim_lsp_signature_help' },
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
vim.diagnostic.config({
2024-04-20 23:39:31 +02:00
float = {
source = "always",
},
2022-10-23 21:49:38 +02:00
})
require("null-ls").setup({
sources = {
2023-01-04 18:55:38 +01:00
-- JavaScript
2022-10-23 21:49:38 +02:00
require("null-ls").builtins.formatting.prettier,
2023-01-04 18:55:38 +01:00
-- Python
2024-04-20 23:39:31 +02:00
require("null-ls").builtins.formatting.black.with({ extra_args = { "--fast" } }),
2022-10-24 09:46:10 +02:00
require("null-ls").builtins.formatting.isort,
2024-04-20 23:39:31 +02:00
require("none-ls.diagnostics.flake8").with({ extra_args = { "--max-line-length", "88", "--ignore", "E203" } }),
2023-01-04 18:55:38 +01:00
-- PHP
2024-04-20 23:39:31 +02:00
require("null-ls").builtins.formatting.phpcbf.with({ extra_args = { "--standard=PSR12" } }),
require("null-ls").builtins.diagnostics.phpcs.with({ extra_args = { "--standard=PSR12" } }),
2024-01-12 20:55:44 +01:00
-- ASM
require("null-ls").builtins.formatting.asmfmt,
-- Elixir
require("null-ls").builtins.formatting.mix,
2022-10-23 21:49:38 +02:00
},
})