The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.
TypeScript code-editorcross-platformdapdatabase-clientdebuggerdesktop-appdeveloper-toolsgithttp-clientideintellijlsprusttauriterminal
fix(java): pass the configured Maven local repository to jdtls (#1813)
arookieofc954ad354a1ce
diff --git a/crates/ide-sdk/src/apply.rs b/crates/ide-sdk/src/apply.rsindex 4d7b5d7b4..45d439ac6 100644--- a/crates/ide-sdk/src/apply.rs+++ b/crates/ide-sdk/src/apply.rs@@ -798,6 +798,22 @@ pub fn configure_server(cfg: &mut LanguageServerConfig, root: &Path, server_rootjson!({ "settings": { "java": { "configuration": { "maven": { "userSettings": file } } } } }),);}+ // m2e resolves and downloads into `maven.repo.local`; without it the+ // embedded Maven falls back to ~/.m2 even when the IDE's own `mvn`+ // runs honor the configured local repository. A `-Dmaven.repo.local`+ // the user put in their own jdtls VM options wins.+ if let Some(repo) = maven_local_repository(root, s) {+ let arg = format!("-Dmaven.repo.local={}", repo.to_string_lossy());+ let taken = cfg.args.iter().enumerate().any(|(i, a)| {+ let value = a+ .strip_prefix("--jvm-arg=")+ .or_else(|| (i > 0 && cfg.args[i - 1] == "--jvm-arg").then_some(a.as_str()));+ value.is_some_and(|a| a.split('=').next() == Some("-Dmaven.repo.local"))+ });+ if !taken {+ cfg.args.push(format!("--jvm-arg={arg}"));+ }+ }}if let Some(lib) = tsdk(server_root, s).or_else(|| tsdk(root, s)) {diff --git a/crates/ide-sdk/src/tests.rs b/crates/ide-sdk/src/tests.rsindex 59c141144..0ed6fa8b4 100644--- a/crates/ide-sdk/src/tests.rs+++ b/crates/ide-sdk/src/tests.rs@@ -115,6 +115,26 @@ fn jdtls_vm_args() {assert_eq!(cfg.args, ["--jvm-arg=-Xmx2g", "--jvm-arg=-javaagent:/opt/lombok.jar"]);}+#[test]+fn jdtls_honors_the_configured_maven_local_repository() {+ let tmp = tempfile::tempdir().unwrap();+ let repo = tmp.path().join("m2-repo");+ let mut s = Settings::default();+ s.languages.java.maven.local_repository = repo.to_string_lossy().into_owned();+ let mut cfg = server("jdtls");+ configure_server(&mut cfg, tmp.path(), tmp.path(), &s);+ assert_eq!(cfg.args, [format!("--jvm-arg=-Dmaven.repo.local={}", repo.to_string_lossy())]);+ // A `-Dmaven.repo.local` the user put in their own jdtls VM options wins.+ s.languages.java.jdtls_vm_args = "-Xmx2g -Dmaven.repo.local=/user/repo".into();+ let mut cfg = server("jdtls");+ configure_server(&mut cfg, tmp.path(), tmp.path(), &s);+ assert_eq!(cfg.args, ["--jvm-arg=-Xmx2g", "--jvm-arg=-Dmaven.repo.local=/user/repo"]);+ // Unset: jdtls keeps m2e's own default (no arg at all).+ let mut cfg = server("jdtls");+ configure_server(&mut cfg, tmp.path(), tmp.path(), &Settings::default());+ assert!(cfg.args.iter().all(|a| !a.contains("maven.repo.local")));+}+#[test]fn rust_analyzer_check_command_and_toolchain() {if cfg!(windows) {