diff --git a/src/context/contextFileSelected.ts b/src/context/contextFileSelected.ts index dec5aa1..a1fcd12 100644 --- a/src/context/contextFileSelected.ts +++ b/src/context/contextFileSelected.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import * as path from 'path'; +import * as fs from 'fs'; import { createTempSubdirectory, getLanguageIdByFileName } from '../util/commonUtil'; export async function handleFileSelected(fileSelected: string) { @@ -12,8 +13,7 @@ export async function handleFileSelected(fileSelected: string) { const tempFile = path.join(tempDir, fileName); // load content in fileSelected - const fileContent = await vscode.workspace.fs.readFile(vscode.Uri.file(fileSelected)); - + const fileContent = fs.readFileSync(fileSelected, 'utf-8'); // get the language from fileSelected const languageId = await getLanguageIdByFileName(fileSelected); diff --git a/src/extension.ts b/src/extension.ts index c9c61ae..e3ba0b9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -import { createChatDirectoryAndCopyInstructionsSync } from './init/chatConfig'; + import { registerOpenChatPanelCommand, registerAddContextCommand, @@ -16,9 +16,6 @@ function activate(context: vscode.ExtensionContext) { ExtensionContextHolder.context = context; logger.init(context); - // 创建 .chat 目录并复制 workflows - createChatDirectoryAndCopyInstructionsSync(context.extensionUri); - registerOpenChatPanelCommand(context); registerAddContextCommand(context); registerAskForCodeCommand(context); diff --git a/src/panel/chatPanel.ts b/src/panel/chatPanel.ts index 9b9213e..077644f 100644 --- a/src/panel/chatPanel.ts +++ b/src/panel/chatPanel.ts @@ -9,6 +9,7 @@ import WebviewManager from './webviewManager'; import messageHistory from '../util/messageHistory'; import CustomCommands from '../command/customCommand'; import CommandManager from '../command/commandManager'; +import { createChatDirectoryAndCopyInstructionsSync } from '../init/chatConfig'; export default class ChatPanel { private static _instance: ChatPanel | undefined; @@ -17,6 +18,9 @@ export default class ChatPanel { private _disposables: vscode.Disposable[] = []; public static createOrShow(extensionUri: vscode.Uri) { + // 创建 .chat 目录并复制 workflows + createChatDirectoryAndCopyInstructionsSync(extensionUri); + const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath; if (workspaceDir) { const workflowsDir = path.join(workspaceDir!, '.chat', 'workflows');