Add the following TODOs

This commit is contained in:
kagami 2024-07-08 22:20:37 +08:00
parent 7551a55ce6
commit f421bcae56
4 changed files with 23 additions and 19 deletions

View File

@ -31,6 +31,7 @@ async function getFullText(activeEditor: vscode.TextEditor): Promise<string> {
return document.getText(); return document.getText();
} }
// TODO: 这里还有用吗如果没用就把这里以及相关代码删除如果有用就用DevChatClient替换这里对DevChat的使用
async function getUndefinedSymbols(content: string): Promise<string[] | undefined> { async function getUndefinedSymbols(content: string): Promise<string[] | undefined> {
// run devchat prompt command // run devchat prompt command
const devChat = new DevChat(); const devChat = new DevChat();

View File

@ -1,3 +1,6 @@
// TODO: 确认所有DevChat()实例被替换后contextRefDefs.js里删除此文件
import * as dotenv from 'dotenv'; import * as dotenv from 'dotenv';
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';

View File

@ -107,6 +107,11 @@ export async function buildRoleContextsFromFiles(
return contexts; return contexts;
} }
// TODO: 在插件启动为每个vscode窗口启动一个devchat local service
// 1. 分配单独的端口号,该窗口的所有请求都通过该端口号发送 (22222仅为作为开发默认端口号不应用于生产)
// 2. 启动local service时要配置多个worker以便处理并发请求
// TODO: 在插件关闭时关闭其对应的devchat local service
export class DevChatClient { export class DevChatClient {
private baseURL: string; private baseURL: string;
@ -114,6 +119,10 @@ export class DevChatClient {
static readonly logRawDataSizeLimit = 10; //4 * 1024; static readonly logRawDataSizeLimit = 10; //4 * 1024;
// TODO: init devchat client with a port number
// TODO: the default 22222 is for dev only, should not be used in production
constructor(port: number = 22222) {
this.baseURL = `http://localhost:${port}`;
} }
async _get(path: string): Promise<AxiosResponse> { async _get(path: string): Promise<AxiosResponse> {
@ -217,33 +226,21 @@ export class DevChatClient {
chatRes.date = chunkData["date"]; chatRes.date = chunkData["date"];
} }
chatRes.finish_reason = chunkData["finish_reason"]; chatRes.finish_reason = chunkData["finish_reason"];
// TODO: tmp string literal 临时字面量
if (chatRes.finish_reason === "should_run_workflow") { if (chatRes.finish_reason === "should_run_workflow") {
chatRes.extra = chunkData["extra"]; chatRes.extra = chunkData["extra"];
logger logger
.channel() .channel()
?.debug( ?.debug("should run workflow via cli.");
"res on data: should_run_workflow. do nothing now."
);
logger
.channel()
?.debug(
`chatRes.extra: ${JSON.stringify(
chatRes.extra
)}`
);
return; return;
} }
chatRes.isError = chunkData["isError"]; chatRes.isError = chunkData["isError"];
chatRes.response += chunkData["content"]; chatRes.response += chunkData["content"];
logger.channel()?.debug(`${chunkData["content"]}`);
onData(chatRes); onData(chatRes);
}); });
response.data.on("end", () => { response.data.on("end", () => {
logger.channel()?.debug("\nStreaming ended");
resolve(chatRes); // Resolve the promise with chatRes when the stream ends resolve(chatRes); // Resolve the promise with chatRes when the stream ends
}); });
@ -372,7 +369,7 @@ export class DevChatClient {
} }
@timeThis @timeThis
async getTopics(limit:number, offset:number): Promise<any[]> { async getTopics(limit: number, offset: number): Promise<any[]> {
const data = { const data = {
limit: limit, limit: limit,
offset: offset, offset: offset,
@ -393,17 +390,19 @@ export class DevChatClient {
} }
@timeThis @timeThis
async deleteTopic(topicRootHash:string): Promise<void> { async deleteTopic(topicRootHash: string): Promise<void> {
const data = { const data = {
topic_hash: topicRootHash, topic_hash: topicRootHash,
workspace: UiUtilWrapper.workspaceFoldersFirstPath(), workspace: UiUtilWrapper.workspaceFoldersFirstPath(),
}; };
const response = await this._post("/topics/delete", data); const response = await this._post("/topics/delete", data);
logger logger
.channel() .channel()
?.debug(`deleteTopic response data: ${JSON.stringify(response.data)}`); ?.debug(
`deleteTopic response data: ${JSON.stringify(response.data)}`
);
return; return;
} }
@ -412,4 +411,4 @@ export class DevChatClient {
this.cancelMessage(); this.cancelMessage();
// add other requests here if needed // add other requests here if needed
} }
} }

View File

@ -6,7 +6,8 @@ import { CommandRun } from '../../src/util/commonUtil';
import { UiUtilWrapper } from '../../src/util/uiUtil'; import { UiUtilWrapper } from '../../src/util/uiUtil';
import { ApiKeyManager } from '../../src/util/apiKey'; import { ApiKeyManager } from '../../src/util/apiKey';
// TODO: 删除devchat.js时删除此测试文件
// TODO: 同时为 DevChatCLI & DevChatClient 添加测试
describe('DevChat', () => { describe('DevChat', () => {
let devChat: DevChat; let devChat: DevChat;
let spawnAsyncStub: sinon.SinonStub; let spawnAsyncStub: sinon.SinonStub;