import * as vscode from "vscode" ; import { BaseNode } from "../basenode" ; import { ProjectInfo , Subproject , Tests , Targets } from "../../meson/types" ; import { extensionRelative , hash } from "../../utils" ; import { TargetDirectoryNode , TargetNode } from "./targets" ; import { getMesonBenchmarks , getMesonTargets , getMesonTests } from "../../meson/introspection" ; import { TestNode } from "./tests" ; export class ProjectNode extends BaseNode { constructor ( private readonly project , private readonly buildDir ) { super ( project . descriptive_name + " " + project . version ) ; } getTreeItem ( ) { const item = super . getTreeItem ( ) as vscode . TreeItem ; item . iconPath = extensionRelative ( "res/meson_32.svg" ) ; item . collapsibleState = vscode . TreeItemCollapsibleState . Expanded ; return item ; } async getChildren ( ) { return [ new SubprojectsRootNode ( this . project . subprojects , this . buildDir ) , new TargetDirectoryNode ( "." , ( await getMesonTargets ( this . buildDir ) ) . filter ( t => ! t . subproject ) ) , new TestRootNode ( await getMesonTests ( this . buildDir ) , false ) , new TestRootNode ( await getMesonBenchmarks ( this . buildDir ) , true ) ] ; } } export class SubprojectsRootNode extends BaseNode { constructor ( private readonly subprojects , private readonly buildDir ) { super ( hash ( subprojects . map ( s => `${ s . descriptive_name } ${ s . version }` ) . join ( ";" ) ) ) ; } getTreeItem ( ) { const item = super . getTreeItem ( ) as vscode . TreeItem ; item . label = "Subprojects" ; item . iconPath = extensionRelative ( "res/icon-subprojects.svg" ) ; item . collapsibleState = vscode . TreeItemCollapsibleState . Collapsed ; return item ; } getChildren ( ) { return this . subprojects . map ( s => new SubprojectNode ( s , this . buildDir ) ) ; } } export class TestRootNode extends BaseNode { constructor ( private readonly tests , private readonly isBenchmark ) { super ( hash ( tests . map ( t => t . suite + t . name ) . join ( ";" ) + `${ isBenchmark ? "-benchmarks" : "-tests" }` ) ) ; } getTreeItem ( ) { const item = super . getTreeItem ( ) as vscode . TreeItem ; item . label = this . isBenchmark ? "Benchmarks" : "Tests" ; item . iconPath = extensionRelative ( "res/meson_32.svg" ) ; item . collapsibleState = vscode . TreeItemCollapsibleState . Collapsed ; return item ; } getChildren ( ) { return this . tests . map ( t => new TestNode ( t , this . isBenchmark ) ) ; } } export class SubprojectNode extends BaseNode { constructor ( private readonly subproject , private readonly buildDir ) { super ( subproject . descriptive_name + " " + subproject . version ) ; } getTreeItem ( ) { const item = super . getTreeItem ( ) as vscode . TreeItem ; item . iconPath = extensionRelative ( "res/icon-subproject.svg" ) ; item . collapsibleState = vscode . TreeItemCollapsibleState . Expanded ; return item ; } async getChildren ( ) { const targets = await getMesonTargets ( this . buildDir ) ; return targets . filter ( t => t . subproject === this . subproject . name ) . map ( t => new TargetNode ( t ) ) ; } }