feat: Enhance file creation in codeBlockHandler

- Add detailed JSDoc comments for createAndOpenFile function
- Refactor createAndOpenFile to streamline document creation and opening
- Improve readability by adding in-line comments for clarity
This commit is contained in:
Rankin Zheng 2024-04-15 22:50:51 +08:00 committed by bobo.yang
parent 75df05c64d
commit e087bc9586

View File

@ -105,10 +105,18 @@ export async function replaceCodeBlockToFile(message: any, panel: vscode.Webview
await applyCodeFile(message.content, message.fileName); await applyCodeFile(message.content, message.fileName);
} }
/**
*
* @param message
* - language: 文件的语言
* - content: 文件的内容
*/
export async function createAndOpenFile(message: any) { export async function createAndOpenFile(message: any) {
const document =await vscode.workspace.openTextDocument({ // 根据提供的语言和内容创建一个新的文档对象
language:message.language, const document =await vscode.workspace.openTextDocument({
content: message.content language:message.language, // 设置新文档的语言
}); content: message.content // 设置新文档的内容
await vscode.window.showTextDocument(document); });
// 在编辑器中打开并显示这个新创建的文档
await vscode.window.showTextDocument(document);
} }