refactor: Simplify topic interaction in UI
- Remove topic-related views, commands, and handlers from the codebase - Refactor code to align with the new unified topic interaction method - Streamline UI by eliminating unnecessary elements and consolidating views
This commit is contained in:
parent
5b11ba4a13
commit
81c0e8be73
73
package.json
73
package.json
@ -548,39 +548,10 @@
|
||||
"type": "webview",
|
||||
"id": "devchat-view",
|
||||
"name": "DevChat"
|
||||
},
|
||||
{
|
||||
"type": "tree",
|
||||
"id": "devchat-topicview",
|
||||
"name": "DevChat-Topic"
|
||||
}
|
||||
]
|
||||
},
|
||||
"commands": [
|
||||
{
|
||||
"command": "devchat-topicview.reloadTopic",
|
||||
"title": "Reload Topics",
|
||||
"icon": "$(refresh)"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.selectTopic",
|
||||
"title": "Select Topic",
|
||||
"icon": "$(add)"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.addTopic",
|
||||
"title": "Add Topic",
|
||||
"icon": "$(add)"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.deleteSelectedTopic",
|
||||
"title": "Delete Selected Topic",
|
||||
"icon": "$(trash)"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.deleteTopic",
|
||||
"title": "Delete topic"
|
||||
},
|
||||
{
|
||||
"command": "devchat.applyDiffResult",
|
||||
"title": "Apply Diff",
|
||||
@ -655,30 +626,6 @@
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
"view/item/context": [
|
||||
{
|
||||
"command": "devchat-topicview.deleteTopic",
|
||||
"when": "view == devchat-topicview",
|
||||
"group": "1_modification"
|
||||
}
|
||||
],
|
||||
"view/title": [
|
||||
{
|
||||
"command": "devchat-topicview.addTopic",
|
||||
"when": "view == devchat-topicview",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.deleteSelectedTopic",
|
||||
"when": "view == devchat-topicview",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.reloadTopic",
|
||||
"when": "view == devchat-topicview",
|
||||
"group": "navigation"
|
||||
}
|
||||
],
|
||||
"editor/title": [
|
||||
{
|
||||
"command": "devchat.applyDiffResult",
|
||||
@ -687,26 +634,6 @@
|
||||
}
|
||||
],
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "devchat-topicview.reloadTopic",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.selectTopic",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.addTopic",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.deleteSelectedTopic",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "devchat-topicview.deleteTopic",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "devchat.applyDiffResult",
|
||||
"when": "false"
|
||||
|
@ -162,67 +162,6 @@ export function registerStatusBarItemClickCommand(context: vscode.ExtensionConte
|
||||
);
|
||||
}
|
||||
|
||||
const topicDeleteCallback = async (item: TopicTreeItem) => {
|
||||
const confirm = 'Delete';
|
||||
const label = typeof item.label === 'string' ? item.label : item.label!.label;
|
||||
const truncatedLabel = label.substring(0, 20) + (label.length > 20 ? '...' : '');
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
`Are you sure you want to delete the topic "${truncatedLabel}"?`,
|
||||
{ modal: true },
|
||||
confirm
|
||||
);
|
||||
|
||||
if (result === confirm) {
|
||||
TopicManager.getInstance().deleteTopic(item.id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export function regTopicDeleteCommand(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('devchat-topicview.deleteTopic', topicDeleteCallback)
|
||||
);
|
||||
}
|
||||
|
||||
export function regAddTopicCommand(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('devchat-topicview.addTopic', () => {
|
||||
const topic = TopicManager.getInstance().createTopic();
|
||||
TopicManager.getInstance().setCurrentTopic(topic.topicId);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function regDeleteSelectTopicCommand(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('devchat-topicview.deleteSelectedTopic', () => {
|
||||
const selectedItem = TopicTreeDataProvider.getInstance().selectedItem;
|
||||
if (selectedItem) {
|
||||
topicDeleteCallback(selectedItem);
|
||||
} else {
|
||||
vscode.window.showErrorMessage('No item selected');
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function regSelectTopicCommand(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('devchat-topicview.selectTopic', (item: TopicTreeItem) => {
|
||||
TopicTreeDataProvider.getInstance().setSelectedItem(item);
|
||||
TopicManager.getInstance().setCurrentTopic(item.id);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function regReloadTopicCommand(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('devchat-topicview.reloadTopic', async () => {
|
||||
TopicManager.getInstance().loadTopics();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function regPythonPathCommand(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('devchat.PythonPath', async () => {
|
||||
|
@ -12,10 +12,3 @@ export function regDevChatView(context: vscode.ExtensionContext) {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function regTopicView(context: vscode.ExtensionContext) {
|
||||
const yourTreeView = vscode.window.createTreeView('devchat-topicview', {
|
||||
treeDataProvider: TopicTreeDataProvider.getInstance(),
|
||||
});
|
||||
context.subscriptions.push(yourTreeView);
|
||||
}
|
@ -6,11 +6,6 @@ import {
|
||||
registerAskForCodeCommand,
|
||||
registerAskForFileCommand,
|
||||
registerAccessKeySettingCommand,
|
||||
regTopicDeleteCommand,
|
||||
regAddTopicCommand,
|
||||
regDeleteSelectTopicCommand,
|
||||
regSelectTopicCommand,
|
||||
regReloadTopicCommand,
|
||||
regApplyDiffResultCommand,
|
||||
registerStatusBarItemClickCommand,
|
||||
regPythonPathCommand,
|
||||
@ -21,7 +16,7 @@ import {
|
||||
registerHandleUri,
|
||||
} from './contributes/commands';
|
||||
import { regLanguageContext } from './contributes/context';
|
||||
import { regDevChatView, regTopicView } from './contributes/views';
|
||||
import { regDevChatView } from './contributes/views';
|
||||
|
||||
import { ExtensionContextHolder } from './util/extensionContext';
|
||||
import { logger } from './util/logger';
|
||||
@ -294,7 +289,6 @@ async function activate(context: vscode.ExtensionContext) {
|
||||
regLanguageContext();
|
||||
|
||||
regDevChatView(context);
|
||||
regTopicView(context);
|
||||
|
||||
registerAccessKeySettingCommand(context);
|
||||
registerOpenChatPanelCommand(context);
|
||||
@ -309,11 +303,6 @@ async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
createStatusBarItem(context);
|
||||
|
||||
regTopicDeleteCommand(context);
|
||||
regAddTopicCommand(context);
|
||||
regDeleteSelectTopicCommand(context);
|
||||
regSelectTopicCommand(context);
|
||||
regReloadTopicCommand(context);
|
||||
regApplyDiffResultCommand(context);
|
||||
|
||||
regPythonPathCommand(context);
|
||||
|
@ -5,57 +5,6 @@ import { TopicManager } from '../topic/topicManager';
|
||||
import { assertValue } from '../util/check';
|
||||
|
||||
|
||||
/**
|
||||
* Class to handle topic updates.
|
||||
*/
|
||||
export class TopicUpdateHandler {
|
||||
/**
|
||||
* Flag to indicate if the topic is being updated from the webview.
|
||||
*/
|
||||
private static isTopicUpdatingFromWebview: boolean = false;
|
||||
|
||||
/**
|
||||
* Checks if the topic change was triggered by the webview.
|
||||
*
|
||||
* @returns {boolean} - Returns true if the topic change was triggered by the webview, false otherwise.
|
||||
*/
|
||||
public static isTopicChangeTriggeredByWebview(): boolean {
|
||||
return TopicUpdateHandler.isTopicUpdatingFromWebview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the topic change after a chat.
|
||||
*
|
||||
* @param {string | undefined} parentHash - The hash of the parent message, if any.
|
||||
* @param {any} message - The message object.
|
||||
* @param {ChatResponse} chatResponse - The chat response object.
|
||||
* @returns {Promise<void>} - A Promise that resolves when the topic change has been processed.
|
||||
*/
|
||||
public static async processTopicChangeAfterChat(parentHash:string | undefined, message: any, chatResponse: ChatResponse): Promise<void> {
|
||||
TopicUpdateHandler.isTopicUpdatingFromWebview = true;
|
||||
try {
|
||||
if (!chatResponse.isError) {
|
||||
let topicId = TopicManager.getInstance().currentTopicId;
|
||||
if (!topicId) {
|
||||
// create new topic
|
||||
const topic = TopicManager.getInstance().createTopic();
|
||||
topicId = topic.topicId;
|
||||
}
|
||||
|
||||
TopicManager.getInstance().updateTopic(
|
||||
topicId!,
|
||||
chatResponse['prompt-hash'],
|
||||
parseDateStringToTimestamp(chatResponse.date),
|
||||
message.text,
|
||||
chatResponse.response
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
TopicUpdateHandler.isTopicUpdatingFromWebview = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to handle user interaction stop events.
|
||||
*/
|
||||
@ -232,7 +181,6 @@ export async function sendMessageBase(message: any, handlePartialData: (data: {
|
||||
assertValue(UserStopHandler.isUserInteractionStopped(), "User Stopped");
|
||||
|
||||
await addMessageToHistory(message, chatResponse, message.parent_hash);
|
||||
await TopicUpdateHandler.processTopicChangeAfterChat(message.parent_hash, message, chatResponse);
|
||||
|
||||
return {
|
||||
command: 'receiveMessage',
|
||||
|
@ -9,7 +9,6 @@ import { ExtensionContextHolder } from '../util/extensionContext';
|
||||
import { TopicManager } from '../topic/topicManager';
|
||||
import { UiUtilWrapper } from '../util/uiUtil';
|
||||
import { ChatContextManager } from '../context/contextManager';
|
||||
import { TopicUpdateHandler } from '../handler/sendMessageBase';
|
||||
|
||||
|
||||
export class DevChatViewProvider implements vscode.WebviewViewProvider {
|
||||
@ -64,13 +63,6 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
|
||||
null,
|
||||
this._context.subscriptions
|
||||
);
|
||||
|
||||
TopicManager.getInstance().addOnCurrentTopicIdChangeListener((topicId) => {
|
||||
if (topicId && TopicUpdateHandler.isTopicChangeTriggeredByWebview()) {
|
||||
return;
|
||||
}
|
||||
this.reloadWebview();
|
||||
});
|
||||
}
|
||||
|
||||
private onDidChangeWorkspaceFolders(event: vscode.WorkspaceFoldersChangeEvent): void {
|
||||
|
@ -2,7 +2,7 @@ import { expect } from 'chai';
|
||||
import { describe, it } from 'mocha';
|
||||
import sinon from 'sinon';
|
||||
import * as path from 'path';
|
||||
import { parseMessage, parseMessageAndSetOptions, TopicUpdateHandler, processChatResponse, sendMessageBase, stopDevChatBase } from '../../src/handler/sendMessageBase';
|
||||
import { parseMessage, parseMessageAndSetOptions, processChatResponse, sendMessageBase, stopDevChatBase } from '../../src/handler/sendMessageBase';
|
||||
import { ChatResponse } from '../../src/toolwrapper/devchat';
|
||||
import { UiUtilWrapper } from '../../src/util/uiUtil';
|
||||
|
||||
@ -56,27 +56,6 @@ describe('sendMessageBase', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('TopicUpdateHandler.processTopicChangeAfterChat', () => {
|
||||
it('should handle topic correctly', async () => {
|
||||
const parentHash = 'somehash';
|
||||
const message = {
|
||||
text: 'Hello, world!'
|
||||
};
|
||||
const chatResponse: ChatResponse = {
|
||||
"finish_reason": "",
|
||||
response: 'Hello, user!',
|
||||
isError: false,
|
||||
user: 'user',
|
||||
date: '2022-01-01T00:00:00.000Z',
|
||||
'prompt-hash': 'responsehash'
|
||||
};
|
||||
|
||||
await TopicUpdateHandler.processTopicChangeAfterChat(parentHash, message, chatResponse);
|
||||
// Check if the topic was updated correctly
|
||||
});
|
||||
});
|
||||
|
||||
describe('processChatResponse', () => {
|
||||
it('should handle response text correctly when isError is false', async () => {
|
||||
const partialDataText = 'Partial data';
|
||||
|
Loading…
x
Reference in New Issue
Block a user