'use strict' ; import { Uri , window , workspace , Range , ViewColumn } from 'vscode' ; import { utils } from 'pddl-workspace' ; export async function exportToAndShow ( text , uri ) { const fileExists = await utils . afs . exists ( uri . fsPath ) ; if ( ! fileExists ) { uri = uri . with ( { scheme : 'untitled' } ) ; } const newDocument = await workspace . openTextDocument ( uri ) ; const editor = await window . showTextDocument ( newDocument , { viewColumn : ViewColumn . Active , preserveFocus : true } ) ; const fullRange = newDocument . validateRange ( new Range ( 0 , 0 , newDocument . lineCount , 0 ) ) ; if ( await editor . edit ( edit => edit . replace ( fullRange , text ) ) ) { return newDocument . save ( ) ; } else { throw new Error ( "Cannot insert text to document: " + newDocument . fileName ) ; } }