import * as _ from "lodash" ; import * as vscode from "vscode" ; import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider" ; import { MavenProject } from "../explorer/model/MavenProject" ; import { localPomPath } from "../utils/contextUtils" ; import { ElementNode , getCurrentNode , XmlTagName } from "../utils/lexerUtils" ; class DefinitionProvider implements vscode . DefinitionProvider { public provideDefinition ( document , position , _token ) { const documentText = document . getText ( ) ; const cursorOffset = document . offsetAt ( position ) ; const currentNode = getCurrentNode ( documentText , cursorOffset ) ; if ( currentNode === undefined || currentNode . contentStart === undefined || currentNode . contentEnd === undefined ) { return undefined ; } const selectionRange = new vscode . Range ( document . positionAt ( currentNode . contentStart ) , document . positionAt ( currentNode . contentEnd ) ) ; switch ( currentNode . tag ) { case XmlTagName . GroupId : case XmlTagName . ArtifactId : case XmlTagName . Version : { const siblingNodes = _ . get ( currentNode , "parent.children" , [ ] ) ; const artifactIdNode = siblingNodes . find ( elem => elem . tag === XmlTagName . ArtifactId ) ; const groupIdNode = siblingNodes . find ( elem => elem . tag === XmlTagName . GroupId ) ; const versionNode = siblingNodes . find ( elem => elem . tag === XmlTagName . Version ) ; const groupIdHint = groupIdNode && groupIdNode . text ; const artifactIdHint = artifactIdNode && artifactIdNode . text ; const versionHint = versionNode && versionNode . text ; if ( groupIdHint && artifactIdHint ) { const mavenProject = mavenExplorerProvider . getMavenProject ( document . uri . fsPath ) ; const version = mavenProject ?. getDependencyVersion ( groupIdHint , artifactIdHint ) || versionHint ; if ( version !== undefined && version . match ( /^\$\{.*\}$/ ) === null ) { const pomPath = localPomPath ( groupIdHint , artifactIdHint , version ) ; const definitionLink = { targetRange : new vscode . Range ( 0 , 0 , 0 , 0 ) , targetUri : vscode . Uri . file ( pomPath ) . with ( { scheme : "vscode-maven" , authority : "local-repository" } ) , originSelectionRange : selectionRange } ; return [ definitionLink ] ; } } } default : return undefined ; } } } export const definitionProvider = new DefinitionProvider ( ) ;