import * as vscode from "vscode" ; import { diagnosticProvider } from "../../DiagnosticProvider" ; import { parseRawDependencyDataHandler } from "../../handlers/parseRawDependencyDataHandler" ; import { getPathToExtensionRoot } from "../../utils/contextUtils" ; import { mavenExplorerProvider } from "../mavenExplorerProvider" ; import { Dependency } from "./Dependency" ; import { HintNode } from "./HintNode" ; import { ITreeItem } from "./ITreeItem" ; import { MavenProject } from "./MavenProject" ; import { Menu } from "./Menu" ; export class DependenciesMenu extends Menu implements ITreeItem { constructor ( project ) { super ( project ) ; this . name = "Dependencies" ; } public getContextValue ( ) { return "maven:dependenciesMenu" ; } public async getChildren ( ) { const treeNodes = await parseRawDependencyDataHandler ( this . project ) ; await diagnosticProvider . refreshDiagnostics ( vscode . Uri . file ( this . project . pomPath ) ) ; if ( treeNodes . length === 0 ) { const hintNodes = [ new HintNode ( "No dependencies" ) ] ; return Promise . resolve ( hintNodes ) ; } else { return Promise . resolve ( treeNodes ) ; } } public getTreeItem ( ) { const treeItem = new vscode . TreeItem ( this . name , vscode . TreeItemCollapsibleState . Collapsed ) ; const uri = vscode . Uri . file ( "" ) ; treeItem . resourceUri = uri . with ( { authority : this . project . pomPath } ) ; treeItem . tooltip = this . name ; const iconFile = "library-folder.svg" ; treeItem . iconPath = { light : getPathToExtensionRoot ( "resources" , "icons" , "light" , iconFile ) , dark : getPathToExtensionRoot ( "resources" , "icons" , "dark" , iconFile ) } ; return treeItem ; } public refresh ( ) { this . _savePom ( ) ; mavenExplorerProvider . refresh ( this ) ; } private _savePom ( ) { const pomUri = vscode . Uri . file ( this . project . pomPath ) ; const textEditors = vscode . window . visibleTextEditors ; const textEditor = textEditors . find ( editor => editor . document . uri . toString ( ) === pomUri . toString ( ) ) ; if ( textEditor !== undefined ) { textEditor . document . save ( ) ; } } }