import { resolve } from "path" ; import * as fse from "fs-extra" ; import { selectWorkspaceFolder } from "../shared/selectWorkspaceFolder" ; import { Uri , ViewColumn , window } from "vscode" ; import { ListItem } from "../service" ; import { filterInvalidPath } from "../shared" ; export async function openQuestion ( ele ) { const { name , type , content , day_id } = ele ; const workspaceFolder = await selectWorkspaceFolder ( ) ; if ( ! workspaceFolder ) { return ; } const codeTemplate = getCodeTemplate ( type , content ) ; const finalPath = await showProblem ( resolve ( workspaceFolder , day_id + "." + filterInvalidPath ( name ) + "." + type ) , codeTemplate || "" ) ; await window . showTextDocument ( Uri . file ( finalPath ) , { preview : false , viewColumn : ViewColumn . One , } ) ; return ; } async function showProblem ( filePath , codeTemplate ) { if ( ! ( await fse . pathExists ( filePath ) ) ) { await fse . createFile ( filePath ) ; await fse . writeFile ( filePath , codeTemplate ) ; } return filePath ; } function getCodeTemplate ( type , content ) { if ( type === "md" ) { return `# Problem: ${ content }

*[interview]: start

*[interview]: end
` ; } else { return `// Problem: ${ content }
// @interview start

// @interview end
` ; } }