import * as fs from 'fs' ; import * as path from 'path' ; import { Position , Uri , ViewColumn , WorkspaceEdit , window , workspace } from 'vscode' ; export function showUntitledWindow ( fileName , content , fallbackPath ) { const filePath = path . join ( workspace . rootPath || fallbackPath , fileName ) ; const uri = Uri . parse ( `untitled:${ filePath }` ) ; try { fs . accessSync ( filePath , fs . constants . F_OK ) ; fs . unlinkSync ( filePath ) ; } catch ( err ) { ; } return workspace . openTextDocument ( uri ) . then ( ( textDocument ) => { const edit = new WorkspaceEdit ( ) ; edit . insert ( < Uri > uri , new Position ( 0 , 0 ) , content ) ; return Promise . all ( [ < any > textDocument , workspace . applyEdit ( edit ) ] ) ; } ) . then ( ( [ textDocument ] ) => { return window . showTextDocument ( < any > textDocument , ViewColumn . One , false ) ; } ) ; }