feat: Add function to open code in new file

- Implemented createAndOpenFile to open a document with the provided content
- Registered createAndOpenFile handler for 'code_new_file' messages
- Enhanced codeBlockHandler and handlerRegister with new functionality
This commit is contained in:
Rankin Zheng 2024-04-15 22:50:15 +08:00 committed by bobo.yang
parent 08b38417be
commit 6679c355ae
2 changed files with 11 additions and 0 deletions

View File

@ -104,3 +104,11 @@ regInMessage({command: 'code_file_apply', content: '', fileName: ''});
export async function replaceCodeBlockToFile(message: any, panel: vscode.WebviewPanel | vscode.WebviewView): Promise<void> {
await applyCodeFile(message.content, message.fileName);
}
export async function createAndOpenFile(message: any) {
const document =await vscode.workspace.openTextDocument({
language:message.language,
content: message.content
});
await vscode.window.showTextDocument(document);
}

View File

@ -9,6 +9,7 @@ import { sendMessage, stopDevChat, regeneration, deleteChatMessage, userInput }
import { applyCodeWithDiff } from './diffHandler';
import { addConext } from './contextHandler';
import { getContextDetail } from './contextHandler';
import {createAndOpenFile} from './codeBlockHandler';
import { listAllMessages } from './listMessages';
import { doVscodeCommand } from './vscodeCommandHandler';
import { featureToggle, getFeatureToggles } from './featureToggleHandler';
@ -27,6 +28,8 @@ messageHandler.registerHandler('code_apply', insertCodeBlockToFile);
// Apply the code block replied by AI to the currently active view, replacing the current file content
// Response: none
messageHandler.registerHandler('code_file_apply', replaceCodeBlockToFile);
// Apply the code block to a new file
messageHandler.registerHandler('code_new_file', createAndOpenFile);
// Perform commit operation
// Response: none
messageHandler.registerHandler('doCommit', doCommit);