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
This commit is contained in:
bobo.yang 2024-02-05 16:29:00 +08:00
parent 6b31dbe16d
commit dd01e78da4
8 changed files with 43 additions and 34 deletions

View File

@ -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';

View File

@ -1,6 +1,5 @@
import * as vscode from 'vscode';
import { DevChatViewProvider } from '../panel/devchatView';
import { TopicTreeDataProvider } from '../panel/topicView';
import { ExtensionContextHolder } from '../util/extensionContext';

View File

@ -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<Array<LogEntry> | 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);

View File

@ -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';

View File

@ -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<b
// delete the message by devchat
const bSuccess = await devChat.delete(message.hash);
assertValue(!bSuccess, "Failed to delete message from devchat");
TopicManager.getInstance().deleteMessageOnCurrentTopic(message.hash);
return true;
} catch (error: any) {
logger.channel()?.error(`Error: ${error.message}`);

View File

@ -1,8 +1,29 @@
import * as vscode from 'vscode';
import { TopicManager } from '../topic/topicManager';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
import { regInMessage, regOutMessage } from '../util/reg_messages';
import { MessageHandler } from './messageHandler';
import DevChat, { TopicEntry } from '../toolwrapper/devchat';
import { UiUtilWrapper } from '../util/uiUtil';
function isDeleteTopic(topicId: string) {
let workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
if (!workspaceDir) {
workspaceDir = os.homedir();
}
const deletedTopicsPath = path.join(workspaceDir!, '.chat', '.deletedTopics');
if (!fs.existsSync(deletedTopicsPath)) {
return false;
}
const deletedTopics = fs.readFileSync(deletedTopicsPath, 'utf-8').split('\n');
// check whether topicId in deletedTopics
return deletedTopics.includes(topicId);
}
// 注册获取当前topic列表的命令
regInMessage({ command: 'getTopics' });
@ -13,7 +34,7 @@ export async function getTopics(message: any, panel: vscode.WebviewPanel | vscod
let topicEntries: TopicEntry[] = [];
for (const topicEntry of topicEntriesAll) {
if (TopicManager.getInstance().isDeleteTopic(topicEntry.root_prompt.hash)) {
if (isDeleteTopic(topicEntry.root_prompt.hash)) {
continue;
}
// append topicEntry to topicEntries
@ -26,5 +47,21 @@ export async function getTopics(message: any, panel: vscode.WebviewPanel | vscod
// 注册删除topic的命令
regInMessage({ command: 'deleteTopic', topicId: '' });
export async function deleteTopic(message: any, panel: vscode.WebviewPanel | vscode.WebviewView): Promise<void> {
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'));
}

View File

@ -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';

View File

@ -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;