feat(maven): setting to download dependency sources on import (#4182)

Settings › Build Tools › Maven › Automatically download sources maps to jdtls java.maven.downloadSources (previously always on in languages/java.toml). Off by default, as in IDEA's Maven › Importing: library classes open decompiled and the Download Sources banner fetches one library's sources on demand.

Closes #4097
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-18 16:34:44 +08:00
1 джерело c43a6169be
коміт aebd26bd7d
10 files changed
+58 -1

No files matched your search

+4
Переглянути файл
@@ -1504,6 +1504,10 @@ pub struct MavenSettings {
pub active_profiles: String,
/// Delegate IDE build/run actions to Maven: launches build with Maven (`javac`) instead of jdtls (ECJ).
pub delegate_build: bool,
/// Download `-sources.jar` of dependencies when the Java language server imports the
/// project (jdtls `java.maven.downloadSources`). Off: sources are fetched on demand
/// from a library class's Download Sources banner.
pub download_sources: bool,
}
impl MavenSettings {
+1
Переглянути файл
@@ -272,6 +272,7 @@ impl Host {
lombok.jar(),
);
ide_sdk::apply::configure_gradle_runtime(cfg, root, server_root, &effective);
ide_sdk::apply::configure_maven_sources(cfg, &effective);
ide_sdk::jdtls::launch_directly(cfg);
}
ide_sdk::apply::server_protocol_overrides(cfg, &effective);
+29
Переглянути файл
@@ -537,6 +537,16 @@ pub fn configure_gradle_runtime(cfg: &mut LanguageServerConfig, root: &Path, bui
merge(cfg.settings.get_or_insert_with(|| json!({})), json!({"java": {"import": {"gradle": gradle}}}));
}
/// Settings › Build Tools › Maven › Automatically download sources → jdtls
/// `java.maven.downloadSources`.
pub fn configure_maven_sources(cfg: &mut LanguageServerConfig, s: &Settings) {
if cfg.name != "jdtls" {
return;
}
let download = s.languages.java.maven.download_sources;
merge(cfg.settings.get_or_insert_with(|| json!({})), json!({"java": {"maven": {"downloadSources": download}}}));
}
/// Maven options from settings, placed before the goals: `-s <settings.xml>`,
/// `-t <toolchains.xml>`, `-Dmaven.repo.local=<dir>`, `-T <count>` and `-P <profiles>`.
pub fn maven_options(root: &Path, s: &Settings) -> Vec<String> {
@@ -2350,6 +2360,25 @@ mod maven_linkage_tests {
assert_eq!(default_maven_repository_in(home), Some(home.join(".m2/repository")));
}
#[test]
fn maven_sources_download_follows_the_setting() {
let mut settings = Settings::default();
let mut cfg = custom_server("jdtls", &LanguageServerSettings::default());
cfg.settings = Some(json!({"java": {"maven": {"downloadSources": true, "updateSnapshots": false}}}));
configure_maven_sources(&mut cfg, &settings);
assert_eq!(
cfg.settings,
Some(json!({"java": {"maven": {"downloadSources": false, "updateSnapshots": false}}}))
);
settings.languages.java.maven.download_sources = true;
configure_maven_sources(&mut cfg, &settings);
assert_eq!(cfg.settings.unwrap()["java"]["maven"]["downloadSources"], json!(true));
let mut other = custom_server("kotlin", &LanguageServerSettings::default());
configure_maven_sources(&mut other, &settings);
assert_eq!(other.settings, None);
}
#[test]
fn gradle_import_runs_the_gradle_the_ide_builds_with() {
let root = Path::new("/p");
+1 -1
Переглянути файл
@@ -47,7 +47,7 @@ moveRefactoringSupport = true
[language-servers.initialization-options.settings.java]
autobuild = { enabled = true }
contentProvider = { preferred = "fernflowerContentProvider" }
maven = { downloadSources = true, updateSnapshots = false }
maven = { downloadSources = false, updateSnapshots = false }
eclipse = { downloadSources = true }
references = { includeDecompiledSources = true }
# The editor's usage lenses count usages; the server's own lenses would search every
+6
Переглянути файл
@@ -8090,6 +8090,12 @@ export type MavenSettings = {
activeProfiles?: string,
/** Delegate IDE build/run actions to Maven: launches build with Maven (`javac`) instead of jdtls (ECJ). */
delegateBuild?: boolean,
/**
* Download `-sources.jar` of dependencies when the Java language server imports the
* project (jdtls `java.maven.downloadSources`). Off: sources are fetched on demand
* from a library class's Download Sources banner.
*/
downloadSources?: boolean,
};
/** Summary of one server discovered inside an external MCP configuration file. */
+2
Переглянути файл
@@ -60,6 +60,7 @@ describe("languages settings", () => {
threads: "2C",
activeProfiles: "",
delegateBuild: false,
downloadSources: false,
});
expect(validateSettings({}).languages).toEqual(DEFAULT_LANGUAGES);
expect(validateLanguages({ java: { maven: { threads: 4 } } }).java.maven.threads).toBe("");
@@ -71,6 +72,7 @@ describe("languages settings", () => {
expect(validateLanguages({ java: { maven: { runnerJre: 21 } } }).java.maven.runnerJre).toBe("");
expect(validateLanguages({ java: { maven: { delegateBuild: true } } }).java.maven.delegateBuild).toBe(true);
expect(validateLanguages({ java: { maven: { delegateBuild: "yes" } } }).java.maven.delegateBuild).toBe(false);
expect(validateLanguages({ java: { maven: { downloadSources: true } } }).java.maven.downloadSources).toBe(true);
const settings = validateSettings({ languages: { java: { maven: { runnerJre: " ./jdks/21 " } } } });
expect(validateSettings(settings).languages.java.maven.runnerJre).toBe("./jdks/21");
});
+7
Переглянути файл
@@ -554,6 +554,7 @@ export function GradlePage() {
export function MavenPage() {
const [delegateBuild, setDelegateBuild] = useSetting<boolean>("languages.java.maven.delegateBuild");
const [daemon, setDaemon] = useSetting<boolean>("languages.java.maven.daemon");
const [downloadSources, setDownloadSources] = useSetting<boolean>("languages.java.maven.downloadSources");
const [threads, setThreads] = useSetting<string>("languages.java.maven.threads");
const [activeProfiles, setActiveProfiles] = useSetting<string>("languages.java.maven.activeProfiles");
const id = useId();
@@ -566,6 +567,12 @@ export function MavenPage() {
onChange={setDelegateBuild}
hint="Run and Debug build Maven modules with Maven (the project's javac) instead of the Java language server. Editor problems still come from the language server."
/>
<Toggle
label="Automatically download sources"
checked={downloadSources}
onChange={setDownloadSources}
hint="The Java language server downloads the sources of all dependencies when it imports the project. When off, a library class opens decompiled and its Download Sources banner fetches the sources of that library only."
/>
<SdkRow
k="languages.java.maven.runnerJre"
label="JRE"
+4
Переглянути файл
@@ -231,6 +231,8 @@ export interface LanguagesValid {
activeProfiles: string;
/** Delegate IDE build/run actions to Maven (`javac`) instead of jdtls (ECJ). */
delegateBuild: boolean;
/** Download dependencies' `-sources.jar` when jdtls imports the project. */
downloadSources: boolean;
};
};
/** Preview font size in px; `null` follows the editor font size. */
@@ -314,6 +316,7 @@ export const DEFAULT_LANGUAGES: LanguagesValid = {
threads: "",
activeProfiles: "",
delegateBuild: false,
downloadSources: false,
},
},
markdown: { previewFontSize: null },
@@ -492,6 +495,7 @@ export function validateLanguages(raw: unknown): LanguagesValid {
threads: text(maven.threads, d.java.maven.threads),
activeProfiles: text(maven.activeProfiles, d.java.maven.activeProfiles),
delegateBuild: bool(maven.delegateBuild, d.java.maven.delegateBuild),
downloadSources: bool(maven.downloadSources, d.java.maven.downloadSources),
},
},
markdown: { previewFontSize: previewSize(markdown.previewFontSize) },
+2
Переглянути файл
@@ -1546,6 +1546,8 @@
"Examples": "Examples",
"Remove File": "Remove File",
"Delegate IDE build/run actions to Maven": "Delegate IDE build/run actions to Maven",
"Automatically download sources": "Automatically download sources",
"The Java language server downloads the sources of all dependencies when it imports the project. When off, a library class opens decompiled and its Download Sources banner fetches the sources of that library only.": "The Java language server downloads the sources of all dependencies when it imports the project. When off, a library class opens decompiled and its Download Sources banner fetches the sources of that library only.",
"Run and Debug build Maven modules with Maven (the project's javac) instead of the Java language server. Editor problems still come from the language server.": "Run and Debug build Maven modules with Maven (the project's javac) instead of the Java language server. Editor problems still come from the language server.",
"Export Keymap as JSON…": "Export Keymap as JSON…",
"Export Keymap": "Export Keymap",
+2
Переглянути файл
@@ -7945,6 +7945,8 @@
"Download Remote Files Into Folder": "将远程文件下载到文件夹",
"Download Remote Host files into a local folder (arg: { server, paths, target })": "将远程主机中的文件下载到本地文件夹(参数:{ server, paths, target })",
"Delegate IDE build/run actions to Maven": "将 IDE 构建/运行操作委托给 Maven",
"Automatically download sources": "自动下载源代码",
"The Java language server downloads the sources of all dependencies when it imports the project. When off, a library class opens decompiled and its Download Sources banner fetches the sources of that library only.": "Java 语言服务器导入项目时下载所有依赖的源代码。关闭时,库中的类以反编译形式打开,可在其“下载源代码”横幅中只下载该库的源代码。",
"Run and Debug build Maven modules with Maven (the project's javac) instead of the Java language server. Editor problems still come from the language server.": "运行和调试时用 Maven(项目的 javac)构建 Maven 模块,而不是用 Java 语言服务器。编辑器中的问题仍来自语言服务器。",
"Render Documentation Comments": "渲染文档注释",
"Render documentation comments": "渲染文档注释",