From e087bc95867813608e5aa67db1d17f5f49fd0a8c Mon Sep 17 00:00:00 2001 From: Rankin Zheng Date: Mon, 15 Apr 2024 22:50:51 +0800 Subject: [PATCH] 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 --- src/handler/codeBlockHandler.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/handler/codeBlockHandler.ts b/src/handler/codeBlockHandler.ts index 0cd1b7f..fcbb19e 100644 --- a/src/handler/codeBlockHandler.ts +++ b/src/handler/codeBlockHandler.ts @@ -105,10 +105,18 @@ export async function replaceCodeBlockToFile(message: any, panel: vscode.Webview await applyCodeFile(message.content, message.fileName); } +/** + * 创建并打开一个新文件 + * @param message 包含要创建文件的语言和内容的对象 + * - language: 文件的语言 + * - content: 文件的内容 + */ export async function createAndOpenFile(message: any) { - const document =await vscode.workspace.openTextDocument({ - language:message.language, - content: message.content - }); - await vscode.window.showTextDocument(document); + // 根据提供的语言和内容创建一个新的文档对象 + const document =await vscode.workspace.openTextDocument({ + language:message.language, // 设置新文档的语言 + content: message.content // 设置新文档的内容 + }); + // 在编辑器中打开并显示这个新创建的文档 + await vscode.window.showTextDocument(document); } \ No newline at end of file