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:
parent
6b31dbe16d
commit
dd01e78da4
@ -5,8 +5,6 @@ import * as path from 'path';
|
|||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
import { sendFileSelectMessage, sendCodeSelectMessage } from './util';
|
import { sendFileSelectMessage, sendCodeSelectMessage } from './util';
|
||||||
import { ExtensionContextHolder } from '../util/extensionContext';
|
import { ExtensionContextHolder } from '../util/extensionContext';
|
||||||
import { TopicManager } from '../topic/topicManager';
|
|
||||||
import { TopicTreeDataProvider, TopicTreeItem } from '../panel/topicView';
|
|
||||||
import { FilePairManager } from '../util/diffFilePairs';
|
import { FilePairManager } from '../util/diffFilePairs';
|
||||||
import { ApiKeyManager } from '../util/apiKey';
|
import { ApiKeyManager } from '../util/apiKey';
|
||||||
import { UiUtilWrapper } from '../util/uiUtil';
|
import { UiUtilWrapper } from '../util/uiUtil';
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { DevChatViewProvider } from '../panel/devchatView';
|
import { DevChatViewProvider } from '../panel/devchatView';
|
||||||
import { TopicTreeDataProvider } from '../panel/topicView';
|
|
||||||
import { ExtensionContextHolder } from '../util/extensionContext';
|
import { ExtensionContextHolder } from '../util/extensionContext';
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
import { TopicManager } from '../topic/topicManager';
|
|
||||||
import DevChat, { LogEntry, LogOptions } from '../toolwrapper/devchat';
|
import DevChat, { LogEntry, LogOptions } from '../toolwrapper/devchat';
|
||||||
import messageHistory from '../util/messageHistory';
|
import messageHistory from '../util/messageHistory';
|
||||||
import { ApiKeyManager } from '../util/apiKey';
|
import { ApiKeyManager } from '../util/apiKey';
|
||||||
import { logger } from '../util/logger';
|
|
||||||
|
|
||||||
let isApiSet: boolean | undefined = undefined;
|
let isApiSet: boolean | undefined = undefined;
|
||||||
|
|
||||||
@ -80,18 +78,14 @@ export async function isWaitForApiKey() {
|
|||||||
|
|
||||||
export async function loadTopicHistoryLogs(topicId: string | undefined): Promise<Array<LogEntry> | undefined> {
|
export async function loadTopicHistoryLogs(topicId: string | undefined): Promise<Array<LogEntry> | undefined> {
|
||||||
if (!topicId) {
|
if (!topicId) {
|
||||||
return [];
|
return undefined;
|
||||||
}
|
|
||||||
const topic = TopicManager.getInstance().getTopic(topicId);
|
|
||||||
if (!topic || !topic.firstMessageHash) {
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const devChat = new DevChat();
|
const devChat = new DevChat();
|
||||||
const logOptions: LogOptions = {
|
const logOptions: LogOptions = {
|
||||||
skip: 0,
|
skip: 0,
|
||||||
maxCount: 10000,
|
maxCount: 10000,
|
||||||
topic: topic.firstMessageHash
|
topic: topicId
|
||||||
};
|
};
|
||||||
const logEntries = await devChat.log(logOptions);
|
const logEntries = await devChat.log(logOptions);
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@ import * as vscode from 'vscode';
|
|||||||
import { MessageHandler } from './messageHandler';
|
import { MessageHandler } from './messageHandler';
|
||||||
import { regInMessage, regOutMessage } from '../util/reg_messages';
|
import { regInMessage, regOutMessage } from '../util/reg_messages';
|
||||||
import { historyMessagesBase, LoadHistoryMessages, loadTopicHistoryFromCurrentMessageHistory, onApiKeyBase } from './historyMessagesBase';
|
import { historyMessagesBase, LoadHistoryMessages, loadTopicHistoryFromCurrentMessageHistory, onApiKeyBase } from './historyMessagesBase';
|
||||||
import messageHistory from '../util/messageHistory';
|
|
||||||
import { TopicManager } from '../topic/topicManager';
|
|
||||||
import { UiUtilWrapper } from '../util/uiUtil';
|
import { UiUtilWrapper } from '../util/uiUtil';
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import DevChat, { ChatOptions, ChatResponse } from '../toolwrapper/devchat';
|
import DevChat, { ChatOptions, ChatResponse } from '../toolwrapper/devchat';
|
||||||
import { logger } from '../util/logger';
|
import { logger } from '../util/logger';
|
||||||
import messageHistory from '../util/messageHistory';
|
import messageHistory from '../util/messageHistory';
|
||||||
import { TopicManager } from '../topic/topicManager';
|
|
||||||
import { assertValue } from '../util/check';
|
import { assertValue } from '../util/check';
|
||||||
|
|
||||||
|
|
||||||
@ -228,8 +227,6 @@ export async function deleteChatMessageBase(message:{'hash': string}): Promise<b
|
|||||||
// delete the message by devchat
|
// delete the message by devchat
|
||||||
const bSuccess = await devChat.delete(message.hash);
|
const bSuccess = await devChat.delete(message.hash);
|
||||||
assertValue(!bSuccess, "Failed to delete message from devchat");
|
assertValue(!bSuccess, "Failed to delete message from devchat");
|
||||||
|
|
||||||
TopicManager.getInstance().deleteMessageOnCurrentTopic(message.hash);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.channel()?.error(`Error: ${error.message}`);
|
logger.channel()?.error(`Error: ${error.message}`);
|
||||||
|
@ -1,8 +1,29 @@
|
|||||||
import * as vscode from 'vscode';
|
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 { regInMessage, regOutMessage } from '../util/reg_messages';
|
||||||
import { MessageHandler } from './messageHandler';
|
import { MessageHandler } from './messageHandler';
|
||||||
import DevChat, { TopicEntry } from '../toolwrapper/devchat';
|
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列表的命令
|
// 注册获取当前topic列表的命令
|
||||||
regInMessage({ command: 'getTopics' });
|
regInMessage({ command: 'getTopics' });
|
||||||
@ -13,7 +34,7 @@ export async function getTopics(message: any, panel: vscode.WebviewPanel | vscod
|
|||||||
|
|
||||||
let topicEntries: TopicEntry[] = [];
|
let topicEntries: TopicEntry[] = [];
|
||||||
for (const topicEntry of topicEntriesAll) {
|
for (const topicEntry of topicEntriesAll) {
|
||||||
if (TopicManager.getInstance().isDeleteTopic(topicEntry.root_prompt.hash)) {
|
if (isDeleteTopic(topicEntry.root_prompt.hash)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// append topicEntry to topicEntries
|
// append topicEntry to topicEntries
|
||||||
@ -26,5 +47,21 @@ export async function getTopics(message: any, panel: vscode.WebviewPanel | vscod
|
|||||||
// 注册删除topic的命令
|
// 注册删除topic的命令
|
||||||
regInMessage({ command: 'deleteTopic', topicId: '' });
|
regInMessage({ command: 'deleteTopic', topicId: '' });
|
||||||
export async function deleteTopic(message: any, panel: vscode.WebviewPanel | vscode.WebviewView): Promise<void> {
|
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'));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import '../handler/handlerRegister';
|
|||||||
import handleMessage from '../handler/messageHandler';
|
import handleMessage from '../handler/messageHandler';
|
||||||
import { createChatDirectoryAndCopyInstructionsSync } from '../init/chatConfig';
|
import { createChatDirectoryAndCopyInstructionsSync } from '../init/chatConfig';
|
||||||
import { ExtensionContextHolder } from '../util/extensionContext';
|
import { ExtensionContextHolder } from '../util/extensionContext';
|
||||||
import { TopicManager } from '../topic/topicManager';
|
|
||||||
import { UiUtilWrapper } from '../util/uiUtil';
|
import { UiUtilWrapper } from '../util/uiUtil';
|
||||||
import { ChatContextManager } from '../context/contextManager';
|
import { ChatContextManager } from '../context/contextManager';
|
||||||
|
|
||||||
|
@ -3,9 +3,7 @@ import * as path from 'path';
|
|||||||
import { logger } from "../util/logger";
|
import { logger } from "../util/logger";
|
||||||
|
|
||||||
import { UiUtilWrapper } from "../util/uiUtil";
|
import { UiUtilWrapper } from "../util/uiUtil";
|
||||||
import { TopicManager } from "../topic/topicManager";
|
|
||||||
import { ApiKeyManager } from '../util/apiKey';
|
import { ApiKeyManager } from '../util/apiKey';
|
||||||
import { CommandRun } from '../util/commonUtil';
|
|
||||||
import { installDevchat } from '../util/python_installer/install_devchat';
|
import { installDevchat } from '../util/python_installer/install_devchat';
|
||||||
|
|
||||||
|
|
||||||
@ -24,8 +22,6 @@ let apiKeyStatus = '';
|
|||||||
let preDevchatStatus = '';
|
let preDevchatStatus = '';
|
||||||
let preApiKeyStatus = '';
|
let preApiKeyStatus = '';
|
||||||
|
|
||||||
let hasLoadTopics: boolean = false;
|
|
||||||
|
|
||||||
export async function dependencyCheck(): Promise<[string, string]> {
|
export async function dependencyCheck(): Promise<[string, string]> {
|
||||||
// there are some different status of devchat:
|
// there are some different status of devchat:
|
||||||
// 0. not checked
|
// 0. not checked
|
||||||
@ -93,15 +89,6 @@ export async function dependencyCheck(): Promise<[string, string]> {
|
|||||||
const devchatPackageStatus = await getDevChatStatus();
|
const devchatPackageStatus = await getDevChatStatus();
|
||||||
const apiAccessKeyStatus = await getApiKeyStatus();
|
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) {
|
if (devchatPackageStatus !== preDevchatStatus) {
|
||||||
logger.channel()?.info(`devchat status: ${devchatPackageStatus}`);
|
logger.channel()?.info(`devchat status: ${devchatPackageStatus}`);
|
||||||
preDevchatStatus = devchatPackageStatus;
|
preDevchatStatus = devchatPackageStatus;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user