From dd01e78da402565df491f9dac1a41f17bbee1f2d Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 5 Feb 2024 16:29:00 +0800 Subject: [PATCH] refactor: Remove legacy TopicView components - Deleted obsolete TopicManager & TopicTreeDataProvider classes - Cleaned up Topic related logic across several modules - Replaced TopicManager usage with new methods after webview migration --- src/contributes/commands.ts | 2 -- src/contributes/views.ts | 1 - src/handler/historyMessagesBase.ts | 12 ++------ src/handler/historyMessagesHandler.ts | 2 -- src/handler/sendMessageBase.ts | 3 -- src/handler/topicHandler.ts | 43 +++++++++++++++++++++++++-- src/panel/devchatView.ts | 1 - src/panel/statusBarViewBase.ts | 13 -------- 8 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index 99e051f..74a4170 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -5,8 +5,6 @@ import * as path from 'path'; import * as util from 'util'; import { sendFileSelectMessage, sendCodeSelectMessage } from './util'; import { ExtensionContextHolder } from '../util/extensionContext'; -import { TopicManager } from '../topic/topicManager'; -import { TopicTreeDataProvider, TopicTreeItem } from '../panel/topicView'; import { FilePairManager } from '../util/diffFilePairs'; import { ApiKeyManager } from '../util/apiKey'; import { UiUtilWrapper } from '../util/uiUtil'; diff --git a/src/contributes/views.ts b/src/contributes/views.ts index 11956ce..a5fb38c 100644 --- a/src/contributes/views.ts +++ b/src/contributes/views.ts @@ -1,6 +1,5 @@ import * as vscode from 'vscode'; import { DevChatViewProvider } from '../panel/devchatView'; -import { TopicTreeDataProvider } from '../panel/topicView'; import { ExtensionContextHolder } from '../util/extensionContext'; diff --git a/src/handler/historyMessagesBase.ts b/src/handler/historyMessagesBase.ts index 542e339..4daddf3 100644 --- a/src/handler/historyMessagesBase.ts +++ b/src/handler/historyMessagesBase.ts @@ -1,10 +1,8 @@ -import { TopicManager } from '../topic/topicManager'; import DevChat, { LogEntry, LogOptions } from '../toolwrapper/devchat'; import messageHistory from '../util/messageHistory'; import { ApiKeyManager } from '../util/apiKey'; -import { logger } from '../util/logger'; let isApiSet: boolean | undefined = undefined; @@ -80,18 +78,14 @@ export async function isWaitForApiKey() { export async function loadTopicHistoryLogs(topicId: string | undefined): Promise | undefined> { if (!topicId) { - return []; + return undefined; } - const topic = TopicManager.getInstance().getTopic(topicId); - if (!topic || !topic.firstMessageHash) { - return []; - } - + const devChat = new DevChat(); const logOptions: LogOptions = { skip: 0, maxCount: 10000, - topic: topic.firstMessageHash + topic: topicId }; const logEntries = await devChat.log(logOptions); diff --git a/src/handler/historyMessagesHandler.ts b/src/handler/historyMessagesHandler.ts index 4c8967a..0443c3d 100644 --- a/src/handler/historyMessagesHandler.ts +++ b/src/handler/historyMessagesHandler.ts @@ -2,8 +2,6 @@ import * as vscode from 'vscode'; import { MessageHandler } from './messageHandler'; import { regInMessage, regOutMessage } from '../util/reg_messages'; import { historyMessagesBase, LoadHistoryMessages, loadTopicHistoryFromCurrentMessageHistory, onApiKeyBase } from './historyMessagesBase'; -import messageHistory from '../util/messageHistory'; -import { TopicManager } from '../topic/topicManager'; import { UiUtilWrapper } from '../util/uiUtil'; diff --git a/src/handler/sendMessageBase.ts b/src/handler/sendMessageBase.ts index 83a9337..c51479c 100644 --- a/src/handler/sendMessageBase.ts +++ b/src/handler/sendMessageBase.ts @@ -1,7 +1,6 @@ import DevChat, { ChatOptions, ChatResponse } from '../toolwrapper/devchat'; import { logger } from '../util/logger'; import messageHistory from '../util/messageHistory'; -import { TopicManager } from '../topic/topicManager'; import { assertValue } from '../util/check'; @@ -228,8 +227,6 @@ export async function deleteChatMessageBase(message:{'hash': string}): Promise { - TopicManager.getInstance().deleteTopic(message.topicId); + const topicId = message.topicId; + let workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath(); + if (!workspaceDir) { + workspaceDir = os.homedir(); + } + const deletedTopicsPath = path.join(workspaceDir!, '.chat', '.deletedTopics'); + + // read ${WORKSPACE_ROOT}/.chat/.deletedTopics as String[] + // add topicId to String[] + // write String[] to ${WORKSPACE_ROOT}/.chat/.deletedTopics + let deletedTopics: string[] = []; + + if (fs.existsSync(deletedTopicsPath)) { + deletedTopics = fs.readFileSync(deletedTopicsPath, 'utf-8').split('\n'); + } + deletedTopics.push(topicId); + fs.writeFileSync(deletedTopicsPath, deletedTopics.join('\n')); } diff --git a/src/panel/devchatView.ts b/src/panel/devchatView.ts index b50c18b..c3bb1c2 100644 --- a/src/panel/devchatView.ts +++ b/src/panel/devchatView.ts @@ -6,7 +6,6 @@ import '../handler/handlerRegister'; import handleMessage from '../handler/messageHandler'; import { createChatDirectoryAndCopyInstructionsSync } from '../init/chatConfig'; import { ExtensionContextHolder } from '../util/extensionContext'; -import { TopicManager } from '../topic/topicManager'; import { UiUtilWrapper } from '../util/uiUtil'; import { ChatContextManager } from '../context/contextManager'; diff --git a/src/panel/statusBarViewBase.ts b/src/panel/statusBarViewBase.ts index a3b5ea8..752059b 100644 --- a/src/panel/statusBarViewBase.ts +++ b/src/panel/statusBarViewBase.ts @@ -3,9 +3,7 @@ import * as path from 'path'; import { logger } from "../util/logger"; import { UiUtilWrapper } from "../util/uiUtil"; -import { TopicManager } from "../topic/topicManager"; import { ApiKeyManager } from '../util/apiKey'; -import { CommandRun } from '../util/commonUtil'; import { installDevchat } from '../util/python_installer/install_devchat'; @@ -24,8 +22,6 @@ let apiKeyStatus = ''; let preDevchatStatus = ''; let preApiKeyStatus = ''; -let hasLoadTopics: boolean = false; - export async function dependencyCheck(): Promise<[string, string]> { // there are some different status of devchat: // 0. not checked @@ -93,15 +89,6 @@ export async function dependencyCheck(): Promise<[string, string]> { const devchatPackageStatus = await getDevChatStatus(); const apiAccessKeyStatus = await getApiKeyStatus(); - if (devchatPackageStatus === 'has statisfied the dependency' || devchatPackageStatus === 'DevChat has been installed') { - if (apiAccessKeyStatus === 'has valid access key') { - if (!hasLoadTopics) { - TopicManager.getInstance().loadTopics(); - } - hasLoadTopics = true; - } - } - if (devchatPackageStatus !== preDevchatStatus) { logger.channel()?.info(`devchat status: ${devchatPackageStatus}`); preDevchatStatus = devchatPackageStatus;