import * as vscode from 'vscode' ; import { DependenciesTreeNode } from '../treeDataProviders/dependenciesTree/dependenciesTreeNode' ; import { TreesManager } from '../treeDataProviders/treesManager' ; import { PypiUtils } from '../utils/pypiUtils' ; import { AbstractHoverProvider } from './abstractHoverProvider' ; export class PypiHover extends AbstractHoverProvider { constructor ( treesManager ) { super ( PypiUtils . DOCUMENT_SELECTOR , treesManager ) ; } @override  public getNodeByLocation ( document , cursorPosition ) { let dependenciesTree = this . _treesManager . dependenciesTreeDataProvider . getDependenciesTreeNode ( 'pypi' ) ; if ( ! dependenciesTree ) { return ; } let requirementsContent = document . getText ( ) . toLowerCase ( ) ; for ( let child of dependenciesTree . children ) { if ( this . isNodeInRange ( child , document , requirementsContent , cursorPosition ) ) { return child ; } for ( let grandchild of child . children ) { if ( this . isNodeInRange ( grandchild , document , requirementsContent , cursorPosition ) ) { return grandchild ; } } } return undefined ; } param node param document param requirementsContent param cursorPosition private isNodeInRange ( node , document , requirementsContent , cursorPosition ) { let pos = PypiUtils . getDependencyPos ( document , requirementsContent , node ) ; if ( pos . length > 0 ) { let range = new vscode . Range ( pos [ 0 ] , pos [ 1 ] ) ; if ( range . contains ( cursorPosition ) ) { return true ; } } return false ; } }