diff --git a/crates/ide-build/src/maven/completion.rs b/crates/ide-build/src/maven/completion.rs index db33911a21..c0e8b351f4 100644 --- a/crates/ide-build/src/maven/completion.rs +++ b/crates/ide-build/src/maven/completion.rs @@ -393,11 +393,13 @@ fn scan_versions(dir: &Path, typed: &str, budget: &mut u32) -> Vec Option { - let segments: Vec<&str> = coordinates.iter().flat_map(|c| c.split('.')).collect(); + let (group, artifact) = coordinates.split_first()?; + let segments: Vec<&str> = group.split('.').chain(artifact.iter().copied()).collect(); segments.iter().all(|s| segment(s)).then(|| segments.iter().fold(repo.to_path_buf(), |p, s| p.join(s))) } @@ -460,6 +462,7 @@ mod tests { "org/example/lib/2.0-beta-1/lib-2.0-beta-1.jar", "org/example/lib/2.0/lib-2.0.pom", "net/nu/netty/4.1.100/netty-4.1.100.jar", + "org/eclipse/platform/org.eclipse.core.runtime/3.31.0/org.eclipse.core.runtime-3.31.0.jar", // Failed downloads (a version typed while editing): tracking files only, not installed. "org/example/lib/2/lib-2.jar.lastUpdated", "org/example/lib/3.0/lib-3.0.pom.lastUpdated", @@ -570,9 +573,10 @@ mod tests { }; // Only directories holding artifacts are group ids: `net` and `org` // alone never receive an install, their deeper levels do. - assert_eq!(options(""), ["net.nu", "org.apache.maven", "org.apache.maven.plugins", "org.example"]); - assert_eq!(options("org"), ["org.apache.maven", "org.apache.maven.plugins", "org.example"]); - assert_eq!(options("org."), ["org.apache.maven", "org.apache.maven.plugins", "org.example"]); + let org = ["org.apache.maven", "org.apache.maven.plugins", "org.eclipse.platform", "org.example"]; + assert_eq!(options(""), [&["net.nu"][..], &org].concat()); + assert_eq!(options("org"), org); + assert_eq!(options("org."), org); assert_eq!(options("org.spr"), Vec::::new()); assert_eq!(options("net."), ["net.nu"]); } @@ -623,6 +627,19 @@ mod tests { }; assert_eq!(options(""), ["2.0", "2.0-beta-1", "1.10", "1.9.1", "1.0"]); assert_eq!(options("1."), ["1.10", "1.9.1", "1.0"]); + // An artifact id with dots is one directory. + let dotted = local_options( + &repo, + &PomCompletionTarget { + from: 0, + to: 0, + typed: "".into(), + kind: PomCompletionKind::Version, + group: Some("org.eclipse.platform".into()), + artifact: Some("org.eclipse.core.runtime".into()), + }, + ); + assert_eq!(dotted.into_iter().map(|o| o.label).collect::>(), ["3.31.0"]); } #[test] diff --git a/crates/ide-workspace/src/dependencies/maven.rs b/crates/ide-workspace/src/dependencies/maven.rs index 55e7baea8f..e4d4b9806d 100644 --- a/crates/ide-workspace/src/dependencies/maven.rs +++ b/crates/ide-workspace/src/dependencies/maven.rs @@ -61,8 +61,9 @@ pub fn artifacts_url(group: &str, prefix: &str) -> Option { /// The published version metadata of one artifact on Central. pub fn metadata_url(group: &str, artifact: &str) -> Option { - (part(group, 200) && part(artifact, 100)).then(|| { - let path = group.split('.').chain(artifact.split('.')).collect::>().join("/"); + // The group's dots are directories; an artifact id is one directory, dots and all. + (part(group, 200) && part(artifact, 100) && artifact != "." && artifact != "..").then(|| { + let path = group.split('.').chain([artifact]).collect::>().join("/"); format!("https://repo1.maven.org/maven2/{path}/maven-metadata.xml") }) } @@ -146,6 +147,11 @@ mod tests { metadata_url("org.apache.maven", "maven-core").as_deref(), Some("https://repo1.maven.org/maven2/org/apache/maven/maven-core/maven-metadata.xml") ); + assert_eq!( + metadata_url("org.eclipse.platform", "org.eclipse.core.runtime").as_deref(), + Some("https://repo1.maven.org/maven2/org/eclipse/platform/org.eclipse.core.runtime/maven-metadata.xml") + ); + assert_eq!(metadata_url("org.example", ".."), None); } #[test]