-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non project files caused setup_dap_main_class_configs to fail #603
base: master
Are you sure you want to change the base?
Non project files caused setup_dap_main_class_configs to fail #603
Conversation
vscode.java.resolveMainClass returns ResolutionItems without projectName for non project classes. Thus, calls to vscode.java.resolveJavaExecutable resulted in "Index 1 out of bounds for length 1". This cascaded into vscode.java.resolveClasspath failing with "Failed to resolve classpath: Referenced classpath provider does not exist: org.eclipse.m2e.launchconfig.classpathProvider".
8e7dc82
to
311d535
Compare
Can you share an example project that triggers this? I'm not sure this is the correct way to deal with this |
Any 2 projects will do, but here is the full context. Consider the following vim.opt.runtimepath:append(vim.fs.normalize("~/.config/nvim/pack/bundle/start/nvim-dap"))
vim.opt.runtimepath:append(vim.fs.normalize("~/.config/nvim/pack/bundle/start/nvim-jdtls"))
local function get_config()
local java_debug_jar_pattern = vim.fs.joinpath(vim.fn.stdpath("data"),
"java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
local vscode_java_test_jar_pattern = vim.fs.joinpath(vim.fn.stdpath("data"), "vscode-java-test/server/*.jar")
return {
cmd = {
vim.fs.normalize("~/.local/lib/jdt-language-server/default/bin/jdtls"),
"-configuration", vim.fs.normalize("~/.cache/jdtls/config"),
"-data", vim.fs.normalize("~/.cache/jdtls/workspace"),
},
init_options = {
bundles = (function()
local bundles = {}
local java_debug_jars = vim.fn.glob(java_debug_jar_pattern, 1, 1)
if vim.tbl_count(java_debug_jars) == 1 then
table.insert(bundles, java_debug_jars[1])
end
local vscode_java_test_jars = vim.tbl_filter(function(jar)
-- https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/2761#issuecomment-1638311201.
-- vscode-java-test's com.microsoft.java.test.runner-jar-with-dependencies.jar
-- shouldn't be passed into the bundles setting.
return not vim.endswith(jar, "com.microsoft.java.test.runner-jar-with-dependencies.jar")
end, vim.fn.glob(vscode_java_test_jar_pattern, 1, 1))
vim.list_extend(bundles, vscode_java_test_jars)
if not vim.tbl_isempty(bundles) then
return bundles
end
end)(),
},
root_dir = require("jdtls.setup").find_root({".git", "mvnw", "gradlew"}),
}
end
local config = get_config()
vim.api.nvim_create_autocmd("FileType", {
pattern = "java",
callback = function()
require("jdtls").start_or_attach(config)
end,
}) Create file Note: Start Neovim with the
In Neovim, open a Java file outside the root directory:
Then run
/var/tmp/jdtls-tests/pom.xml<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>local</groupId>
<artifactId>jdtls-tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>21</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
</project> /var/tmp/CompletionFailsBeforeDeclaration.javaimport java.util.List;
public class CompletionFailsBeforeDeclaration {
public static void main(String[] args) {
Object unknown = List.of(1, 2);
if (unknown instanceof List things) {
// things.is
Object nothing = null;
// things.isEmpty()
}
}
} /var/tmp/jdtls-tests/src/main/java/FinalExceptions.javapublic class FinalExceptions {
public static void main(String[] args) {
final Object token = new Object();
try {
token.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
token.wait();
} catch (IllegalMonitorStateException | InterruptedException e) {
e.printStackTrace();
}
}
} |
vscode.java.resolveMainClass
returns ResolutionItems withoutprojectName
for non project classes. Thus, calls tovscode.java.resolveJavaExecutable
resulted in "Index 1 out of bounds for length 1". This cascaded intovscode.java.resolveClasspath
failing with "Failed to resolve classpath: Referenced classpath provider does not exist: org.eclipse.m2e.launchconfig.classpathProvider".