feat(maven): go to declaration for POM properties and parent-managed dependencies (#1887)

* feat(maven): go to declaration for POM properties and parent-managed dependencies

Ctrl/Cmd-click (or Go to Declaration) on a `${property}` reference in a
pom.xml opens the `<properties>` entry that defines it - the POM's own,
else the first one along the parent chain (a child's definition wins; an
active profile's counts as the POM's own) - and a dependency / plugin
whose version a `<dependencyManagement>` / `<pluginManagement>` entry
provides opens that managing declaration. The chain follows
`<relativePath>` in the project and the local repository (Settings >
Maven's, else ~/.m2) for external parents, which open read-only as plain
files; `project.*` built-ins go to their coordinate elements. When
nothing resolves under the caret, nothing navigates: the usual 'Cannot
find declaration to go to' hint shows instead.

The backend answers a caret position (0-based line / UTF-16 column) with
the winner's file, range and kind (maven_goto_declaration), reusing the
build model's POM reader and parent resolver (ide_build::maven) instead
of a new parser. The frontend contribution (build-tools.pomNavigation)
claims only positions that can resolve - inside a `${...}` reference or
a <dependency> / <plugin> element - so the Cmd-hover underline stays out
of the rest of the file.

Refs #1735

* test(maven): normalize expected goto paths like the parent chain does

parent_chain resolves every path it returns through dunce::canonicalize,
but the goto_declaration tests compared those results against raw temp
paths, which differ on the CI runners: on macOS the temp dir sits behind
the /var -> /private/var symlink and on Windows under the RUNNER~1 8.3
short name with backslash separators, so the Rust (macos-latest) and
Rust (windows-latest) jobs failed in the new assertions while the
functionality itself was right.

Feed the expected paths through the same canonicalization call before
comparing, mirroring the production behavior on every platform; on a
plain Linux checkout the canonical form equals the raw path, so the
assertions stay equivalent there.

Refs #1735
Цей коміт міститься в:
Vadim Lazuk authored and GitHub committed 2026-11-07 07:33:17 +08:00
1 джерело 66ecf4c967
коміт 99fafffaac
8 files changed
+949 -3

No files matched your search

+16 -1
Переглянути файл
@@ -2,9 +2,10 @@
use crate::state::AppState;
use ide_build::compile::{BuildEvent, BuildKind, BuildResult};
use ide_build::maven::PomGoto;
use ide_build::pom_edit::ArtifactKey;
use ide_build::{BuildModel, BuildTool, SyncProgress};
use ide_core::{IdeResult, Location, RequestId};
use ide_core::{IdeResult, Location, Pos, RequestId};
#[allow(unused_imports)]
pub use ide_host::ops::build::*;
use tauri::ipc::Channel;
@@ -114,6 +115,20 @@ pub async fn maven_dependency_declaration(
ide_host::ops::build::maven_dependency_declaration(&state.host, window.label(), pom, dependency).await
}
/// The go-to-declaration target at `pos` of a Maven POM: the definition of the
/// `${property}` at the caret, or the `<dependencyManagement>` / `<pluginManagement>`
/// entry providing the dependency's / plugin's version, along the parent chain.
#[tauri::command]
#[specta::specta]
pub async fn maven_goto_declaration(
window: Window,
state: State<'_, AppState>,
pom: String,
pos: Pos,
) -> IdeResult<Option<PomGoto>> {
ide_host::ops::build::maven_goto_declaration(&state.host, window.label(), pom, pos).await
}
/// Adds an `<exclusion>` of `exclusion` to the declaration of the direct dependency
/// `dependency` of the Maven module `pom`, through the open document when there is one
/// (saved). Returns the declaration; nothing changes when it already excludes it.
+1
Переглянути файл
@@ -375,6 +375,7 @@ pub fn builder() -> tauri_specta::Builder<tauri::Wry> {
build::gradle_published_catalog,
build::maven_dependency_declaration,
build::maven_exclude_dependency,
build::maven_goto_declaration,
build::build_run,
java::java_resolve_launch,
java::java_debug_server,