import * as path from 'path' ; import * as vscode from 'vscode' ; import { DependenciesTreeNode } from '../treeDataProviders/dependenciesTree/dependenciesTreeNode' ; import { GoUtils } from '../utils/goUtils' ; import { AbstractFocus , FocusType } from './abstractFocus' ; export class GoFocus extends AbstractFocus { constructor ( ) { super ( GoUtils . PKG_TYPE ) ; } @override  public async focusOnDependency ( dependenciesTreeNode , focusType ) { while ( dependenciesTreeNode . parent && dependenciesTreeNode . parent . parent && dependenciesTreeNode . parent . parent . parent ) { dependenciesTreeNode = dependenciesTreeNode . parent ; } let textEditor = await this . openGoMod ( dependenciesTreeNode ) ; if ( ! textEditor ) { return ; } if ( dependenciesTreeNode . isDependenciesTreeRoot ( ) ) { return ; } let pos = GoUtils . getDependencyPos ( textEditor . document , dependenciesTreeNode , focusType ) ; if ( ! pos ) { return ; } textEditor . selection = new vscode . Selection ( pos [ 0 ] , pos [ 1 ] ) ; textEditor . revealRange ( new vscode . Range ( pos [ 0 ] , pos [ 1 ] ) , vscode . TextEditorRevealType . InCenter ) ; } private async openGoMod ( dependenciesTreeNode ) { let parent = dependenciesTreeNode . parent ; if ( ! parent ) { return ; } let fsPath = dependenciesTreeNode . isDependenciesTreeRoot ( ) ? dependenciesTreeNode . generalInfo . path : parent . generalInfo . path ; let openPath = vscode . Uri . file ( path . join ( fsPath , 'go.mod' ) ) ; if ( ! openPath ) { return ; } let textDocument = await vscode . workspace . openTextDocument ( openPath ) ; return await vscode . window . showTextDocument ( textDocument ) ; } }