in src/DiagnosticProvider.ts [77:100]
public async findConflictRange(filePath: string, gid: string, aid: string): Promise<vscode.Range> {
const pomDocument = await vscode.window.showTextDocument(vscode.Uri.file(filePath), {preserveFocus: true});
const projectNodes: ElementNode[] = getNodesByTag(pomDocument.document.getText(), XmlTagName.Project);
if (projectNodes === undefined || projectNodes.length !== 1) {
throw new UserError("Only support POM file with single <project> node.");
}
const projectNode: ElementNode = projectNodes[0];
const dependenciesNode: ElementNode | undefined = projectNode.children?.find(node => node.tag === XmlTagName.Dependencies);
const dependencyNode = dependenciesNode?.children?.find(node =>
node.children?.find(id => id.tag === XmlTagName.GroupId && id.text === gid) !== undefined &&
node.children?.find(id => id.tag === XmlTagName.ArtifactId && id.text === aid) !== undefined
);
if (dependencyNode === undefined) {
throw new UserError("Failed to find dependency.");
}
const aidItem: ElementNode | undefined = dependencyNode.children?.find(node => node.tag === XmlTagName.ArtifactId);
if (aidItem === undefined || aidItem.contentStart === undefined || aidItem.contentEnd === undefined) {
throw new UserError("Failed to find dependency.");
}
const currentDocument: vscode.TextDocument = await vscode.workspace.openTextDocument(filePath);
return new vscode.Range(currentDocument.positionAt(aidItem.contentStart), currentDocument.positionAt(aidItem.contentEnd));
}