nvim/lua/setuplsp.lua

265 lines
6.8 KiB
Lua
Raw Normal View History

2024-04-18 14:22:10 -04:00
-- https://github.com/neovim/nvim-lspconfig/blob/master/dloc/server_configurations.md
2024-03-15 15:05:44 -04:00
require("neodev").setup({
2024-04-18 14:22:10 -04:00
-- add any options here, or leave empty to use the default settings
2024-03-15 15:05:44 -04:00
})
2024-03-12 01:28:22 -04:00
local capabilities = require("cmp_nvim_lsp").default_capabilities()
2024-05-19 16:49:15 -04:00
capabilities.textDocument.completion.completionItem.snippetSupport = true
2024-05-19 16:53:54 -04:00
2024-03-12 01:28:22 -04:00
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
2024-05-11 14:08:38 -04:00
2024-05-22 00:52:24 -04:00
-- jdtls
local function setupJDTLS()
local mason_registry = require("mason-registry")
-- Early termination if jdtls is not installed
if not mason_registry.is_installed("jdtls") then
print("jdtls is not installed via Mason.")
return
end
local function find_launcher_jar(jdtls_path)
local plugins_path = jdtls_path .. "/plugins"
local find_command = "find '"
.. plugins_path
.. "' -type f -name 'org.eclipse.equinox.launcher_*.jar' -print -quit"
local handle = io.popen(find_command)
if handle == nil then
return
end
local result = handle:read("*l") -- Read only the first line of output
handle:close()
return result -- directly return the path
end
local jdtls_path = mason_registry.get_package("jdtls"):get_install_path()
local path_to_launcher = find_launcher_jar(jdtls_path)
local path_to_lsp_server = jdtls_path .. "/config_linux"
local lombok_path = jdtls_path .. "/lombok.jar"
-- local bundles = {
-- vim.fn.glob(vim.fn.expand '~/.config/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-0.52.0.jar', true),
-- }
2024-05-22 11:04:07 -04:00
-- -- vim.list_extend(bundles, vim.split(vim.fn.glob(vim.fn.stdpath 'config' .. '/resources/vscode-java-test-main/server/*.jar', true), '\n'))
2024-05-22 00:52:24 -04:00
local function makeandgetpath()
2024-05-29 12:35:54 -04:00
local root = require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'});
if root == nil then
return ""
end
local path = root .. "/data"
2024-05-22 00:52:24 -04:00
os.execute("mkdir -p " .. path)
return path
end
local config = {
cmd = {
os.getenv("JAVA_HOME") .. "/bin/java",
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Dosgi.bundles.defaultStartLevel=4",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
"-Dlog.protocol=true",
"-Dlog.level=ALL",
-- '-javaagent:' .. lombok_path, -- Why?
"-Xmx1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
"-jar",
path_to_launcher,
"-configuration",
path_to_lsp_server,
"-data",
makeandgetpath(),
},
2024-05-25 21:55:16 -04:00
root_dir = require("jdtls.setup").find_root({ ".git", "mvnw", "gradlew" }),
2024-05-22 00:52:24 -04:00
-- Further configuration
settings = {
java = {},
},
flags = {
allow_incremental_sync = true,
},
init_options = {
-- bundles = bundles,
bundles = {},
},
}
2024-05-31 20:24:01 -04:00
return config
2024-05-22 00:52:24 -04:00
end
2024-08-06 15:20:59 -04:00
-- vim.api.nvim_create_autocmd("FileType", {
-- pattern = "java",
-- callback = function()
-- local jdtls = require("jdtls")
-- jdtls.start_or_attach(setupJDTLS())
-- -- require("jdtls").setup_dap()
-- vim.keymap.set({ "n", "i" }, "<A-F>", function()
-- require("jdtls").organize_imports()
-- vim.lsp.buf.format()
-- end, {})
-- end,
-- })
2024-05-22 00:52:24 -04:00
-- ENDjdtls
require("lspconfig").emmet_language_server.setup({
2024-08-06 15:20:59 -04:00
filetypes = {"css", "scss", "sass", "less", "html"}
2024-05-22 00:52:24 -04:00
capabilities = capabilities,
})
2024-05-19 16:53:54 -04:00
require("lspconfig").cssls.setup({
capabilities = capabilities,
})
require("lspconfig").nginx_language_server.setup({
capabilities = capabilities,
})
2024-05-11 14:08:38 -04:00
require("lspconfig").bashls.setup({
2024-05-19 16:53:54 -04:00
capabilities = capabilities,
2024-05-11 14:08:38 -04:00
})
2024-05-22 00:52:24 -04:00
require("lspconfig").html.setup({
capabilities = capabilities,
})
2024-05-03 18:47:42 -04:00
require("lspconfig").nil_ls.setup({
2024-05-19 16:53:54 -04:00
capabilities = capabilities,
2024-05-03 18:47:42 -04:00
})
2024-04-18 14:22:10 -04:00
require("lspconfig").jsonls.setup({
capabilities = capabilities,
})
2024-03-14 20:49:32 -04:00
require("lspconfig").yamlls.setup({
capabilities = capabilities,
settings = {
yaml = {
schemas = {
["/home/meyer/.config/nvim/clangdschema.json"] = "/.clangd",
},
},
},
})
require("lspconfig").clangd.setup({
capabilities = capabilities,
2024-03-15 15:05:44 -04:00
cmd = {
"clangd",
"--header-insertion=iwyu",
},
2024-03-14 20:49:32 -04:00
})
2024-03-21 15:49:14 -04:00
require("lspconfig").prismals.setup({
capabilities = capabilities,
})
require("lspconfig").asm_lsp.setup({
capabilities = capabilities,
})
2024-03-12 15:22:20 -04:00
require("lspconfig").pyright.setup({
capabilities = capabilities,
})
require("lspconfig").tsserver.setup({
capabilities = capabilities,
})
2024-03-12 01:28:22 -04:00
--
require("lspconfig").kotlin_language_server.setup({
capabilities = capabilities,
})
--Lua
require("lspconfig").lua_ls.setup({
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,
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
2024-04-18 14:22:10 -04:00
library = vim.api.nvim_get_runtime_file("", true),
2024-03-12 01:28:22 -04:00
},
})
end,
2024-03-15 15:05:44 -04:00
settings = {
Lua = {
completion = {
callSnippet = "Replace",
},
},
},
2024-03-12 01:28:22 -04:00
})
local luasnip = require("luasnip")
2024-03-12 15:22:20 -04:00
local pairs = require("nvim-autopairs.completion.cmp")
2024-03-12 01:28:22 -04:00
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
-- ['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
-- ['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
2024-03-12 15:22:20 -04:00
["<C-Space>"] = cmp.mapping.complete(),
2024-03-12 01:28:22 -04:00
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
2024-03-12 15:22:20 -04:00
{ name = "hrsh7th/cmp-nvim-lsp-signature-help" },
2024-03-12 01:28:22 -04:00
},
})
2024-03-12 15:22:20 -04:00
cmp.event:on("confirm_done", pairs.on_confirm_done())
2024-03-14 20:49:32 -04:00
require("setupclangdext")
2024-03-22 18:27:51 -04:00
require("null-ls").setup()
require("eslint").setup({
2024-04-18 14:22:10 -04:00
bin = "eslint_d", -- or `eslint`
code_actions = {
enable = true,
apply_on_save = {
enable = true,
types = { "directive", "problem", "suggestion", "layout" },
},
disable_rule_comment = {
enable = true,
location = "separate_line", -- or `same_line`
},
},
diagnostics = {
enable = true,
report_unused_disable_directives = false,
run_on = "type", -- or `save`
},
2024-03-22 18:27:51 -04:00
})