import * as _ from "lodash" ; import * as vscode from "vscode" ; import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider" ; import { MavenProject } from "../explorer/model/MavenProject" ; import { ElementNode , getCurrentNode , XmlTagName } from "../utils/lexerUtils" ; class HoverProvider implements vscode . HoverProvider { public async provideHover ( document , position , _token ) { const currentNode = getCurrentNode ( document . getText ( ) , document . offsetAt ( position ) ) ; if ( currentNode === undefined || currentNode . contentStart === undefined || currentNode . contentEnd === undefined ) { return undefined ; } const targetRange = 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 groupIdHint = groupIdNode && groupIdNode . text ; const artifactIdHint = artifactIdNode && artifactIdNode . text ; if ( groupIdHint && artifactIdHint ) { const mavenProject = mavenExplorerProvider . getMavenProject ( document . uri . fsPath ) ; if ( ! mavenProject ) { return undefined ; } const effectiveVersion = mavenProject . getDependencyVersion ( groupIdHint , artifactIdHint ) ; if ( effectiveVersion ) { return new vscode . Hover ( [ `groupId = ${ groupIdHint }` , `artifactId = ${ artifactIdHint }` , `version = ${ effectiveVersion }` ] . join ( "\n\n" ) , targetRange ) ; } } } default : return undefined ; } } } export const hoverProvider = new HoverProvider ( ) ;