kitchen sink now don't support any version lower than 0.11.0 for lsp

- dap now works for java and c
This commit is contained in:
2025-05-08 18:18:34 -05:00
parent 7c3289fded
commit 7430ebed8e
19 changed files with 492 additions and 686 deletions

158
after/ftplugin/java.lua Normal file
View File

@ -0,0 +1,158 @@
local misc = require("core.misc")
local map, auto = misc.map, misc.auto
local jdtls = require("jdtls")
local jdtls_install = vim.fs.joinpath(vim.fn.stdpath('data'),
"/mason/packages/jdtls")
local java_dap_install = vim.fs.joinpath(vim.fn.stdpath('data'),
"/mason/packages/java-debug-adapter")
-- make sure to check if things with 💀 need updating
local config = {
cmd = {
"/usr/lib/jvm/openjdk21/bin/java", -- 💀
"-jar", vim.fn.glob(jdtls_install.."/plugins/org.eclipse.equinox.launcher_*.jar"), -- 💀
"-configuration", jdtls_install.."/config_linux",
"-data", vim.fn.stdpath("cache").."/nvim-jdtls",
"--add-modules=ALL-SYSTEM",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
"-Dlog.level=ALL",
"-Dlog.protocol=true",
"-Dosgi.bundles.defaultStartLevel=4",
"-Xmx1G",
},
root_dir = vim.fs.dirname(vim.fs.find({
"gradlew",
".git",
"mvnw",
"settings.gradle", -- Gradle (multi-project)
"settings.gradle.kts", -- Gradle (multi-project)
"build.xml", -- Ant
"pom.xml" -- Maven
}, { upward = true })[1]),
on_attach = function(_, bufnr)
jdtls.setup.add_commands()
-- add some jdtls specific mappings
local opts = { buffer = bufnr }
map("n", "cri", jdtls.organize_imports, opts)
map("n", "crv", jdtls.extract_variable, opts)
map("n", "crc", jdtls.extract_constant, opts)
map("x", "crv", function() jdtls.extract_variable(true) end, opts)
map("x", "crc", function() jdtls.extract_constant(true) end, opts)
map("x", "crm", function() jdtls.extract_method(true) end, opts)
pcall(vim.lsp.codelens.refresh)
auto("BufWritePost", {
buffer = bufnr,
desc = "refresh codelens",
callback = function()
pcall(vim.lsp.codelens.refresh)
end
})
-- setup nvim-dap
require("dap").adapters.java = nil -- remove any old java adapters
jdtls.setup_dap({ hotcodereplace = "auto" })
require("jdtls.dap").setup_dap_main_class_configs()
end,
-- don"t print out status messages
handlers = {
["language/status"] = function() end
},
init_options = {
bundles = {
vim.fs.joinpath(java_dap_install,
vim.fn.glob("/extension/server/com.microsoft.java.debug.plugin-*.jar",
true)
)
}
}
}
-- generate the path to the java file(s)
---@type string|nil
local cache_path = vim.fs.joinpath(vim.fn.stdpath("cache"), "/JavaVersion.class")
---@type string|nil
local src_path = vim.fs.joinpath(vim.fn.stdpath("config"), "/extras/JavaVersion.java")
-- if either path is invalid
if not cache_path or not src_path then
return
end
--- build a cache of the JavaVersion code
local function build_cache()
-- check if we have javac
vim.system({ "javac" }, {}, function(out)
if out.code == 127 then
cache_path = nil
return
end
-- compile our code
vim.system({ "javac", src_path, "-d", vim.fn.stdpath("cache") }, {}, function(out)
if out.code ~= 0 then
cache_path = nil
end
end)
end)
end
-- check if we have a compiled version of JavaVersion
local f, _ = io.open(cache_path, "r")
if not f then -- if we don"t have a cache
build_cache()
else
io.close(f)
end
local function version_check()
-- check the java version
local out = vim.system({
config.cmd[1], -- use the same java executable that the lsp will be using
(cache_path and "JavaVersion") or src_path
}, { cwd = vim.fn.stdpath("cache"), text = true }):wait()
-- parse the version information aquired
local v = vim.version.parse(out.stdout)
-- if there's an error, no version info, or the java version is
-- less than 21 stop the lsp from starting
if out.code ~= 0 then
vim.notify(string.format(
"java version check failed: exit code %s", out.code),
vim.log.levels.ERROR, { title = misc.appid })
vim.notify(string.format(
"%s", vim.inspect(out.stdout)),
vim.log.levels.ERROR, { title = misc.appid })
return false
elseif not v then
vim.notify("no java version info found", vim.log.levels.ERROR,
{ title = misc.appid })
return false
elseif v.major < 21 then
vim.notify(string.format(
"java version %s < 21.0.0 Cannot run jdtls, bailing out",
v[1] .. "." .. v[2] .. "." .. v[3]),
vim.log.levels.ERROR, { title = misc.appid })
return false
end
return true
end
-- start the jdtls with dap!
if not version_check() then
return
end
jdtls.start_or_attach(config)

View File

@ -1,28 +0,0 @@
local misc = require('core.misc')
-- make sure norg parsers are installed before opening a norg file, currently
-- there are two parsers: norg, and norg_meta
local found = {}
found[0] = 0 -- used to store the number of elements in the table
-- check for the parsers
misc.loopf(vim.fn.stdpath("data").."/site/pack/deps/opt/nvim-treesitter/parser",
function(file)
if string.find(file, "norg") then
found[file] = true
found[0] = found[0] + 1
end
end, "so")
-- if the parsers don't exist download them
if found[0] < 2 and
(not found["norg.so"] or not found["norg_meta.so"]) then
vim.cmd("Neorg sync-parsers")
end
-- set colorcolumn in norg buffers
vim.opt_local.colorcolumn = { 80 }
-- make text wrap at the colorcolumn automatically
vim.api.nvim_set_option_value("textwidth",
tonumber(vim.api.nvim_get_option_value("colorcolumn", {})), { buf = 0 })

View File

@ -0,0 +1,9 @@
local map = require("core.misc").map
return {
on_attach = function(_, bufnr)
-- add some basedpyright specific mappings
local opts = { buffer = bufnr }
map("n", "cri", "<cmd>PyrightOrganizeImports<CR>", opts)
end,
}

27
after/lsp/clangd.lua Normal file
View File

@ -0,0 +1,27 @@
local map = require("core.misc").map
return {
on_attach = function(_, bufnr)
-- add some clangd specific mappings
local opts = { buffer = bufnr }
map("n", "<leader>o", "<cmd>ClangdSwitchSourceHeader<CR>", opts)
end,
cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--header-insertion=iwyu",
"--completion-style=detailed",
"--function-arg-placeholders",
"--fallback-style=llvm"
},
init_options = {
usePlaceholders = true,
clangdFileStatus = true,
fallback_flags = {
"-xc" -- makes clangd think we"re using c instead of c++
}
}
}

24
after/lsp/lua_ls.lua Normal file
View File

@ -0,0 +1,24 @@
return {
settings = {
Lua = {
diagnostics = {
globals = { "vim", "mp" }
},
runtime = {
version = "LuaJIT"
},
format = {
enable = false
},
workspace = {
checkThirdParty = true,
library = {
vim.env.VIMRUNTIME
}
}
}
},
root_markers = { ".luarc.json", ".luarc.jsonc", ".luacheckrc", ".stylua.toml",
"stylua.toml", "selene.toml", "selene.yml", "README.md" }
}