'use strict' ; import * as path from 'path' ; import { Uri , workspace } from 'vscode' ; import { PddlWorkspace , Plan } from 'pddl-workspace' ; import { PlanReportSettings } from '../planReport/PlanReportSettings' ; import { exists } from '../util/workspaceFs' ; import { PlanData , PlansData } from './model' ; import { CONF_PDDL , PLAN_REPORT_WIDTH } from '../configuration/configuration' ; export async function getDocumentText ( fileUri , defaultText ? ) { if ( await exists ( fileUri ) ) { return ( await workspace . fs . readFile ( fileUri ) ) . toString ( ) ; } else { return defaultText ; } } export async function getDomainVisualizationConfiguration ( plan ) { if ( ! plan . domain ) { return undefined ; } const visualizationConfigurationText = await getDocumentText ( PlanReportSettings . toVisualizationSettings ( plan . domain . fileUri ) ) ; if ( visualizationConfigurationText !== undefined ) { return PlanReportSettings . loadFromText ( visualizationConfigurationText ) ; } return undefined ; } export async function getDomainVisualizationConfigurationDataForPlan ( plan ) { const width = workspace . getConfiguration ( CONF_PDDL ) . get < number > ( PLAN_REPORT_WIDTH , 300 ) ; const domainVizConfiguration = plan . domain && await getDomainVisualizationConfiguration ( plan ) ; const planVisualizerRelativePath = domainVizConfiguration ?. getPlanVisualizerScript ( ) ; const planVisualizationScriptPath = plan . domain && planVisualizerRelativePath && path . join ( PddlWorkspace . getFolderPath ( plan . domain . fileUri ) , planVisualizerRelativePath ) ; const planVisualizationScript = planVisualizationScriptPath && await getDocumentText ( Uri . file ( planVisualizationScriptPath ) ) ; return { plan : plan , domainVisualizationConfiguration : domainVizConfiguration ?. settings , customDomainVisualizationScript : planVisualizationScript , width : width } ; } export async function getDomainVisualizationConfigurationDataForPlans ( plans ) { if ( plans . length > 0 ) { const data = await getDomainVisualizationConfigurationDataForPlan ( plans [ 0 ] ) ; return { plans : plans , width : data . width , domainVisualizationConfiguration : data . domainVisualizationConfiguration , customDomainVisualizationScript : data . customDomainVisualizationScript } ; } else { return { plans : plans , width : 0 } ; } }