185 lines
6.3 KiB
Lua
185 lines
6.3 KiB
Lua
local opts = { noremap = true, silent = true }
|
|
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
|
|
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
|
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)
|
|
vim.keymap.set('n', '<space>f',
|
|
function() vim.lsp.buf.format { async = true, filter = function(c) return c.name ~= "ts_ls" end } end, bufopts)
|
|
end
|
|
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
|
|
|
require 'lspconfig'.clangd.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
require 'lspconfig'.ts_ls.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
require 'lspconfig'.pyright.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
require 'lspconfig'.eslint.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
settings = {
|
|
format = false
|
|
},
|
|
}
|
|
require 'lspconfig'.rust_analyzer.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
cmd = {
|
|
"rustup", "run", "stable", "rust-analyzer",
|
|
},
|
|
}
|
|
require 'lspconfig'.phpactor.setup {
|
|
on_attach = on_attach,
|
|
init_options = {
|
|
["language_server_phpstan.enabled"] = false,
|
|
["language_server_psalm.enabled"] = false,
|
|
}
|
|
}
|
|
require 'lspconfig'.asm_lsp.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
cmd = {
|
|
"/home/dobiadi/.cargo/bin/asm-lsp"
|
|
},
|
|
}
|
|
require 'lspconfig'.elixirls.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
cmd = {
|
|
"elixir-ls"
|
|
},
|
|
}
|
|
require'lspconfig'.terraformls.setup{
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
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" }
|
|
|
|
-- Set up nvim-cmp.
|
|
local cmp = require 'cmp'
|
|
|
|
cmp.setup({
|
|
preselect = cmp.PreselectMode.None,
|
|
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({
|
|
float = {
|
|
source = "always",
|
|
},
|
|
})
|
|
|
|
require("null-ls").setup({
|
|
sources = {
|
|
-- Packer
|
|
require("null-ls").builtins.formatting.hclfmt,
|
|
-- JavaScript
|
|
require("null-ls").builtins.formatting.prettier,
|
|
-- Python
|
|
require("null-ls").builtins.formatting.black.with({ extra_args = { "--fast" } }),
|
|
require("null-ls").builtins.formatting.isort,
|
|
require("none-ls.diagnostics.flake8").with({ extra_args = { "--max-line-length", "88", "--ignore", "E203" } }),
|
|
-- PHP
|
|
require("null-ls").builtins.formatting.phpcbf.with({ extra_args = { "--standard=PSR12" } }),
|
|
require("null-ls").builtins.diagnostics.phpcs.with({ extra_args = { "--standard=PSR12" } }),
|
|
-- ASM
|
|
require("null-ls").builtins.formatting.asmfmt,
|
|
-- Elixir
|
|
require("null-ls").builtins.formatting.mix,
|
|
},
|
|
})
|