Merge pull request #596 from devchat-ai/chore/optimize-log-implementation
chore: Update submodules and optimize code completion
This commit is contained in:
commit
d60291e476
2
gui
2
gui
@ -1 +1 @@
|
|||||||
Subproject commit c011224587af65658d5637d5016f6b60024054a4
|
Subproject commit 66c9115f69ad90eea993cee16dcf93e280673201
|
@ -11,6 +11,7 @@ import { outputAst } from './astTest';
|
|||||||
import { getEndOfLine } from './ast/language';
|
import { getEndOfLine } from './ast/language';
|
||||||
import { RecentEditsManager } from './recentEdits';
|
import { RecentEditsManager } from './recentEdits';
|
||||||
import { GitDiffWatcher } from './gitDiffWatcher';
|
import { GitDiffWatcher } from './gitDiffWatcher';
|
||||||
|
import { MessageHandler } from '../../handler/messageHandler';
|
||||||
|
|
||||||
export function registerCodeCompleteCallbackCommand(context: vscode.ExtensionContext) {
|
export function registerCodeCompleteCallbackCommand(context: vscode.ExtensionContext) {
|
||||||
let disposable = vscode.commands.registerCommand(
|
let disposable = vscode.commands.registerCommand(
|
||||||
@ -44,6 +45,7 @@ function isSubsequence(sub: string, source: string): boolean {
|
|||||||
|
|
||||||
interface LogEventRequest {
|
interface LogEventRequest {
|
||||||
completion_id: string;
|
completion_id: string;
|
||||||
|
is_manual_trigger: boolean;
|
||||||
type: string; // "view", "select"
|
type: string; // "view", "select"
|
||||||
lines: number;
|
lines: number;
|
||||||
length: number; // length of code completed
|
length: number; // length of code completed
|
||||||
@ -77,26 +79,11 @@ export class InlineCompletionProvider implements vscode.InlineCompletionItemProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
async logEventToServer(event: LogEventRequest) {
|
async logEventToServer(event: LogEventRequest) {
|
||||||
const devchatToken = this.devchatConfig.get("providers.devchat.api_key");
|
MessageHandler.sendMessage2({command: "logEvent", id: event.completion_id, language: event.language, name: event.type, value: {...event}});
|
||||||
const devchatEndpoint = this.devchatConfig.get("providers.devchat.api_base");
|
}
|
||||||
const apiUrl = `${devchatEndpoint}/complete_events`;
|
|
||||||
const requestOptions: RequestInit = {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Authorization": `Bearer ${devchatToken}`,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(event),
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
async logMessageToServer(id: string, language: string, model: string, result: string) {
|
||||||
const response = await fetch(apiUrl, requestOptions);
|
MessageHandler.sendMessage2({command: "logMessage", id: id, language, commandName: "code_completion", content: result, model});
|
||||||
if (!response.ok) {
|
|
||||||
logger.channel()?.info("log event to server failed:", response.status);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error posting event to the server:', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether need to send code complete event
|
// check whether need to send code complete event
|
||||||
@ -219,6 +206,7 @@ export class InlineCompletionProvider implements vscode.InlineCompletionItemProv
|
|||||||
if (!this.isManualTrigger && this.devchatConfig.get("complete_enable") !== true) {
|
if (!this.isManualTrigger && this.devchatConfig.get("complete_enable") !== true) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
const isManualTrigger = this.isManualTrigger;
|
||||||
|
|
||||||
// const filepath = document.uri.fsPath;
|
// const filepath = document.uri.fsPath;
|
||||||
// const fileContent = document.getText();
|
// const fileContent = document.getText();
|
||||||
@ -269,12 +257,20 @@ export class InlineCompletionProvider implements vscode.InlineCompletionItemProv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logMessageToServer(
|
||||||
|
response.result.id,
|
||||||
|
path.extname(document.uri.fsPath).toLowerCase().slice(1),
|
||||||
|
DevChatConfig.getInstance().get("complete_model") ?? "unknow",
|
||||||
|
response.result.code
|
||||||
|
);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// 代码补全建议是否已经被用户看到,这个需要更加准确的方式来识别。
|
// 代码补全建议是否已经被用户看到,这个需要更加准确的方式来识别。
|
||||||
logger.channel()?.trace("code complete show.");
|
logger.channel()?.trace("code complete show.");
|
||||||
this.logEventToServer(
|
this.logEventToServer(
|
||||||
{
|
{
|
||||||
completion_id: response.result.id,
|
completion_id: response.result.id,
|
||||||
|
is_manual_trigger: isManualTrigger,
|
||||||
type: "view",
|
type: "view",
|
||||||
lines: response.result.code.split('\n').length,
|
lines: response.result.code.split('\n').length,
|
||||||
length: response.result.code.length,
|
length: response.result.code.length,
|
||||||
@ -302,6 +298,7 @@ export class InlineCompletionProvider implements vscode.InlineCompletionItemProv
|
|||||||
this.logEventToServer(
|
this.logEventToServer(
|
||||||
{
|
{
|
||||||
completion_id: response!.result.id,
|
completion_id: response!.result.id,
|
||||||
|
is_manual_trigger: isManualTrigger,
|
||||||
type: "select",
|
type: "select",
|
||||||
lines: response!.result.code.split('\n').length,
|
lines: response!.result.code.split('\n').length,
|
||||||
length: response!.result.code.length,
|
length: response!.result.code.length,
|
||||||
|
@ -29,6 +29,10 @@ async function copyDirectory(src: string, dest: string): Promise<void> {
|
|||||||
const srcPath = path.join(src, entry.name);
|
const srcPath = path.join(src, entry.name);
|
||||||
const destPath = path.join(dest, entry.name);
|
const destPath = path.join(dest, entry.name);
|
||||||
|
|
||||||
|
if (entry.name === ".git") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
await copyDirectory(srcPath, destPath);
|
await copyDirectory(srcPath, destPath);
|
||||||
} else {
|
} else {
|
||||||
@ -185,6 +189,12 @@ export function regApplyDiffResultCommand(context: vscode.ExtensionContext) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getExtensionVersion(): string {
|
||||||
|
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
|
return packageJson.version;
|
||||||
|
}
|
||||||
|
|
||||||
export function registerInstallCommandsCommand(
|
export function registerInstallCommandsCommand(
|
||||||
context: vscode.ExtensionContext
|
context: vscode.ExtensionContext
|
||||||
) {
|
) {
|
||||||
@ -195,17 +205,22 @@ export function registerInstallCommandsCommand(
|
|||||||
const homePath = process.env.HOME || process.env.USERPROFILE || "";
|
const homePath = process.env.HOME || process.env.USERPROFILE || "";
|
||||||
const sysDirPath = path.join(homePath, ".chat", "scripts");
|
const sysDirPath = path.join(homePath, ".chat", "scripts");
|
||||||
const sysMericoDirPath = path.join(homePath, ".chat", "scripts", "merico");
|
const sysMericoDirPath = path.join(homePath, ".chat", "scripts", "merico");
|
||||||
|
const devchatConfig = DevChatConfig.getInstance();
|
||||||
const pluginDirPath = path.join(
|
const pluginDirPath = path.join(
|
||||||
UiUtilWrapper.extensionPath(),
|
UiUtilWrapper.extensionPath(),
|
||||||
"workflowsCommands"
|
"workflowsCommands"
|
||||||
); // Adjust this path as needed
|
); // Adjust this path as needed
|
||||||
|
|
||||||
const dcClient = new DevChatClient();
|
const dcClient = new DevChatClient();
|
||||||
|
const updatePublicWorkflow = devchatConfig.get("update_public_workflow", true);
|
||||||
|
const currentVersion = UiUtilWrapper.extensionPath();
|
||||||
|
const previousVersion = devchatConfig.get("last_devchat_version", "");
|
||||||
|
|
||||||
if (!fs.existsSync(sysMericoDirPath)) {
|
if (!fs.existsSync(sysMericoDirPath) || (updatePublicWorkflow === false && currentVersion !== previousVersion)) {
|
||||||
logger.channel()?.debug("Creating directory: " + sysMericoDirPath);
|
logger.channel()?.debug("Creating directory: " + sysMericoDirPath);
|
||||||
await copyDirectory(pluginDirPath, sysDirPath);
|
await copyDirectory(pluginDirPath, sysDirPath);
|
||||||
}
|
}
|
||||||
|
devchatConfig.set("last_devchat_version", currentVersion);
|
||||||
|
|
||||||
// Check if ~/.chat/scripts directory exists
|
// Check if ~/.chat/scripts directory exists
|
||||||
if (!fs.existsSync(sysMericoDirPath)) {
|
if (!fs.existsSync(sysMericoDirPath)) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
import { logger } from '../util/logger';
|
import { logger } from '../util/logger';
|
||||||
|
import { ExtensionContextHolder } from '../util/extensionContext';
|
||||||
|
|
||||||
|
|
||||||
export class MessageHandler {
|
export class MessageHandler {
|
||||||
@ -60,6 +61,19 @@ export class MessageHandler {
|
|||||||
|
|
||||||
panel.webview.postMessage(message);
|
panel.webview.postMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static sendMessage2(message : any, log: boolean = true): void {
|
||||||
|
if (log) {
|
||||||
|
logger.channel()?.trace(`Message to GUI: "${JSON.stringify(message)}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const panel = ExtensionContextHolder.provider?.view()!;
|
||||||
|
if (!panel) {
|
||||||
|
logger.channel()?.warn(`No panel found to send message: "${JSON.stringify(message)}"`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
panel.webview.postMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const messageHandler = new MessageHandler();
|
export const messageHandler = new MessageHandler();
|
||||||
|
2
tools
2
tools
@ -1 +1 @@
|
|||||||
Subproject commit b6bccf6a463c4437398499aa7ff17552e49ecf56
|
Subproject commit 893076582d7e491917451469045ef65bc6e50f4f
|
@ -1 +1 @@
|
|||||||
Subproject commit 4a3b29c15ebc0a18cb20dabc60e753a727fa7c80
|
Subproject commit ed9898d038e09732bbcaba0ef655efc1f89ef9a8
|
Loading…
x
Reference in New Issue
Block a user