nvimConfig/after/plugin/lsp.lua

97 lines
2.9 KiB
Lua

require("mason").setup()
local cmp = require('cmp')
local cmp_select = {behavior = cmp.SelectBehavior.Select}
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<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 }),
['<C-Space>'] = cmp.mapping.complete(),
}),
sources = cmp.config.sources(
{
{ name = 'nvim_lsp' },
{ name = 'luasnip' }
},
{
{ name = 'buffer' },
{ name = 'path' },
{ name = 'cmdline' }
}),
completion = {
completeopt = 'menu,menuone,noinsert',
},
})
require('lspconfig').lua_ls.setup {
on_init = function(client)
if client.workspace_folders then
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
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 and will cause issues when working on your own configuration (see https://github.com/neovim/nvim-lspconfig/issues/3189)
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {}
}
}
require('lspconfig').clangd.setup{
capabilities = require('cmp_nvim_lsp').default_capabilities(),
cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--completion-style=detailed",
"--all-scopes-completion",
}
}
require('lspconfig').pyright.setup{}
require('lspconfig').html.setup{}
require('lspconfig').angularls.setup{}
require('lspconfig').ts_ls.setup({
cmd = { "/usr/lib/node_modules/typescript-language-server/lib/cli.mjs", "--stdio" },
filetypes = { "javascript", "typescript", "javascriptreact", "typescriptreact" },
init_options = {
-- Required for plugins (even if unused)
plugins = {},
},
-- Ensure tsserver uses project-specific tsconfig.json
on_attach = function(client, bufnr)
client.server_capabilities.documentFormattingProvider = false -- Optional
end
})
vim.lsp.enable("java-language-server")
vim.lsp.config("java-language-server", {
cmd = {"java-language-server"}
})