NeoVim Version
NVIM v0.11.0-dev-298+gd82efeccc
Build type: RelWithDebInfo
LuaJIT 2.1.1716656478
Describe the bug
Java file watcher does not work as the jdtls is marked as an invalid lsp.
This just happens in nvim 0.10.0+
To Reproduce
Please provide a minimal init.lua to reproduce which can be run as the following:
nvim --clean -u minimal.lua
You can edit the following example file to include your adapters and other required setup.
vim.opt.runtimepath:remove(vim.fn.expand("~/.config/nvim"))
vim.opt.packpath:remove(vim.fn.expand("~/.local/share/nvim/site"))
local lazypath = "/tmp/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "java"},
highlight = { enable = true },
indent = { enable = true },
})
end
},
{
"neovim/nvim-lspconfig",
opts = {
-- make sure mason installs the server
servers = {
jdtls = {},
},
},
},
{
"mfussenegger/nvim-jdtls",
dependencies = { "folke/which-key.nvim" },
ft = java_filetypes,
opts = function()
return {
-- How to find the root dir for a given filename. The default comes from
-- lspconfig which provides a function specifically for java projects.
root_dir = require("lspconfig.server_configurations.jdtls").default_config.root_dir,
-- How to find the project name for a given root dir.
project_name = function(root_dir)
return root_dir and vim.fs.basename(root_dir)
end,
-- Where are the config and workspace dirs for a project?
jdtls_config_dir = function(project_name)
return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/config"
end,
jdtls_workspace_dir = function(project_name)
return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/workspace"
end,
-- How to run jdtls. This can be overridden to a full java command-line
-- if the Python wrapper script doesn't suffice.
cmd = { vim.fn.exepath("jdtls") },
full_cmd = function(opts)
local fname = vim.api.nvim_buf_get_name(0)
local root_dir = opts.root_dir(fname)
local project_name = opts.project_name(root_dir)
local cmd = vim.deepcopy(opts.cmd)
if project_name then
vim.list_extend(cmd, {
"-configuration",
opts.jdtls_config_dir(project_name),
"-data",
opts.jdtls_workspace_dir(project_name),
})
end
return cmd
end,
-- These depend on nvim-dap, but can additionally be disabled by setting false here.
dap = { hotcodereplace = "auto", config_overrides = {} },
dap_main = {},
test = true,
settings = {
java = {
inlayHints = {
parameterNames = {
enabled = "all",
},
},
},
},
}
end,
config = function(_, opts)
local function attach_jdtls()
-- Existing server will be reused if the root_dir matches.
require("jdtls").start_or_attach(config)
end
-- Attach the jdtls for each java buffer. HOWEVER, this plugin loads
-- depending on filetype, so this autocmd doesn't run for the first file.
-- For that, we call directly below.
vim.api.nvim_create_autocmd("FileType", {
pattern = java_filetypes,
callback = attach_jdtls,
})
end
end,
})
-- Avoid race condition by calling attach the first time, since the autocmd won't fire.
attach_jdtls()
end,
}
{
"nvim-neotest/neotest",
dependencies = {
"antoinemadec/FixCursorHold.nvim",
"nvim-neotest/neotest-plenary",
"nvim-neotest/nvim-nio",
-- Install adapters here
"rcasia/neotest-java"
},
require("neotest").setup({
-- Add adapters to the list
adapters = { "neotest-java" },
})
end,
}
})
Steps to reproduce the behavior:
Go to a java test file
Wait for the nvim-jdtls to load
Toggle the test watcher. In this case <leader>tw
See error: No valid LSP client found for watching. Ensure that at least one test file is open and has an LSP client attached.
Please provide example test files to reproduce.
Expected behavior
Neotest file watcher should start
NeoVim Version NVIM v0.11.0-dev-298+gd82efeccc Build type: RelWithDebInfo LuaJIT 2.1.1716656478
Describe the bug Java file watcher does not work as the jdtls is marked as an invalid lsp. This just happens in nvim 0.10.0+
To Reproduce Please provide a minimal
init.lua
to reproduce which can be run as the following:You can edit the following example file to include your adapters and other required setup.
Steps to reproduce the behavior:
<leader>tw
Please provide example test files to reproduce.
Expected behavior Neotest file watcher should start
Logs
Logs
INFO | 2024-06-23T00:54:58Z+0200 | /home/rico/REPOS/neotest/lua/neotest/config/init.lua:454 | Configuration complete DEBUG | 2024-06-23T00:54:58Z+0200 | /home/rico/REPOS/neotest/lua/neotest/config/init.lua:455 | User config { adapters = { { build_spec =