Skip to content

Commit

Permalink
improve navigation of parent POM (#959)
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Zhang <[email protected]>
  • Loading branch information
Eskibear authored Mar 27, 2023
1 parent cd9a934 commit 3dd53db
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/definition/definitionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ class DefinitionProvider implements vscode.DefinitionProvider {
if (parentNode.name === XmlTagName.Dependency || parentNode.name === XmlTagName.Plugin) { // plugin/dependency -> artifacts
return getDependencyDefinitionLink(parentNode, document, position);
} else if (parentNode.name === XmlTagName.Parent) { // parent -> artifact
const relativePathNode: Element | undefined = parentNode.childNodes.find(ch => isTag(ch) && ch.name === XmlTagName.RelativePath) as Element | undefined;
if (relativePathNode && !relativePathNode.firstChild) {
// <relativePath/> to explicitly lookup parent from repository
return getDependencyDefinitionLink(parentNode, document, position);
} else {
return getParentDefinitionLink(parentNode, document, position);
}
return getParentDefinitionLink(parentNode, document, position);
} else {
return undefined;
}
Expand All @@ -60,7 +54,7 @@ class DefinitionProvider implements vscode.DefinitionProvider {

export const definitionProvider: DefinitionProvider = new DefinitionProvider();

function getParentDefinitionLink(parentNode: Element, document: vscode.TextDocument, position: vscode.Position) {
function getParentDefinitionLinkFromRelativePath(parentNode: Element, document: vscode.TextDocument, position: vscode.Position) {
const mavenProject: MavenProject | undefined = MavenProjectManager.get(document.uri.fsPath);
if (mavenProject) {
const parentPomPath = mavenProject.parentPomPath;
Expand Down Expand Up @@ -146,4 +140,19 @@ function getModuleDefinitionLink(moduleNode: Element, document: vscode.TextDocum
originSelectionRange: selectionRange
};
return [definitionLink];
}

/**
* Definition of artifact specified in <parent> node.
* 0. By default, the search order is relativePath > local repository > remote repository.
* 1. if <relativePath> is explicitly empty, it's forbidden to search in relative path.
*/
function getParentDefinitionLink(parentNode: Element, document: vscode.TextDocument, position: vscode.Position) {
const relativePathNode: Element | undefined = parentNode.childNodes.find(ch => isTag(ch) && ch.name === XmlTagName.RelativePath) as Element | undefined;
if (relativePathNode && !relativePathNode.firstChild) { // <relativePath/> to explicitly lookup parent from repository
return getDependencyDefinitionLink(parentNode, document, position);
} else {
return getParentDefinitionLinkFromRelativePath(parentNode, document, position)
?? getDependencyDefinitionLink(parentNode, document, position); // fallback to search local repository if not found in relative path.
}
}

0 comments on commit 3dd53db

Please sign in to comment.