Replace assistant names in source
This commit is contained in:
parent
6a8393ed9d
commit
cc35fd3380
@ -1,5 +1,6 @@
|
||||
import * as vscode from "vscode";
|
||||
import { collapseFileExculdeSelectRange } from "./codecomplete/ast/collapseBlock";
|
||||
import { ASSISTANT_NAME_EN } from "../util/constants";
|
||||
|
||||
class DevChatQuickFixProvider implements vscode.CodeActionProvider {
|
||||
public static readonly providedCodeActionKinds = [
|
||||
@ -18,13 +19,13 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
|
||||
|
||||
const diagnostic = context.diagnostics[0];
|
||||
const quickFix = new vscode.CodeAction(
|
||||
"Ask DevChat",
|
||||
`Ask ${ASSISTANT_NAME_EN}`,
|
||||
vscode.CodeActionKind.QuickFix,
|
||||
);
|
||||
quickFix.isPreferred = false;
|
||||
|
||||
const fixUsingDevChat = new vscode.CodeAction(
|
||||
"Fix using DevChat",
|
||||
`Fix using ${ASSISTANT_NAME_EN}`,
|
||||
vscode.CodeActionKind.QuickFix,
|
||||
);
|
||||
fixUsingDevChat.isPreferred = true;
|
||||
@ -32,7 +33,7 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
|
||||
return new Promise(async (resolve) => {
|
||||
quickFix.command = {
|
||||
command: "DevChat.quickFixAskDevChat",
|
||||
title: "Ask DevChat",
|
||||
title: `Ask ${ASSISTANT_NAME_EN}`,
|
||||
arguments: [
|
||||
document,
|
||||
range,
|
||||
@ -42,7 +43,7 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
|
||||
|
||||
fixUsingDevChat.command = {
|
||||
command: "DevChat.quickFixUsingDevChat",
|
||||
title: "Fix using DevChat",
|
||||
title: `Fix using ${ASSISTANT_NAME_EN}`,
|
||||
arguments: [
|
||||
document,
|
||||
range,
|
||||
|
@ -35,6 +35,7 @@ import { InlineCompletionProvider, registerCodeCompleteCallbackCommand } from ".
|
||||
import { indexDir } from "./contributes/codecomplete/astIndex";
|
||||
import registerQuickFixProvider from "./contributes/quickFixProvider";
|
||||
import { stopLocalService } from './util/localService';
|
||||
import { updateNames } from "./util/constants";
|
||||
|
||||
|
||||
async function migrateConfig() {
|
||||
@ -129,6 +130,8 @@ export async function fixDevChatApiBase() {
|
||||
|
||||
async function activate(context: vscode.ExtensionContext) {
|
||||
ExtensionContextHolder.context = context;
|
||||
const assistantNames = context.extension.packageJSON.assistantNames
|
||||
updateNames(assistantNames.ASSISTANT_NAME_EN, assistantNames.ASSISTANT_NAME_ZH)
|
||||
|
||||
logger.init(LoggerChannelVscode.getInstance());
|
||||
UiUtilWrapper.init(new UiUtilVscode());
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { ASSISTANT_NAME_EN } from '../util/constants';
|
||||
import { UiUtilWrapper } from '../util/uiUtil';
|
||||
import { MessageHandler } from './messageHandler';
|
||||
import { isSending } from './sendMessage';
|
||||
@ -6,7 +7,7 @@ import { isSending } from './sendMessage';
|
||||
export async function chatWithDevChat(panel, message: string) {
|
||||
if (isSending()) {
|
||||
// already sending, show error
|
||||
UiUtilWrapper.showErrorMessage("DevChat: A command is already being sent, please try again later.");
|
||||
UiUtilWrapper.showErrorMessage(`${ASSISTANT_NAME_EN}: A command is already being sent, please try again later.`);
|
||||
return;
|
||||
}
|
||||
MessageHandler.sendMessage(panel!, { command: 'chatWithDevChat', 'message': message });
|
||||
|
@ -18,42 +18,6 @@ export interface LoadHistoryMessages {
|
||||
entries: Array<LogEntry>;
|
||||
}
|
||||
|
||||
function welcomeMessage(): LogEntry {
|
||||
// create default logEntry to show welcome message
|
||||
return {
|
||||
hash: 'message',
|
||||
parent: '',
|
||||
user: 'system',
|
||||
date: '',
|
||||
request: 'How do I use DevChat?',
|
||||
response: `
|
||||
Do you want to write some code or have a question about the project? Simply right-click on your chosen files or code snippets and add them to DevChat. Feel free to ask me anything or let me help you with coding.
|
||||
|
||||
Don't forget to check out the "+" button on the left of the input to add more context. To see a list of workflows you can run in the context, just type "/". Happy prompting!
|
||||
`,
|
||||
context: []
|
||||
} as LogEntry;
|
||||
}
|
||||
|
||||
function apiKeyMissedMessage(): LogEntry {
|
||||
// create default logEntry to show welcome message
|
||||
return {
|
||||
hash: 'message',
|
||||
parent: '',
|
||||
user: 'system',
|
||||
date: '',
|
||||
request: 'Is OPENAI_API_KEY (or DevChat Access Key) ready?',
|
||||
response: `
|
||||
OPENAI_API_KEY is missing from your environment or settings. Kindly input your OpenAI or DevChat key, and I'll ensure DevChat is all set for you.
|
||||
|
||||
<button value="get_devchat_key" href="https://web.devchat.ai" component="a">Register DevChat key</button>
|
||||
<button value="setting_devchat_key">Set DevChat key</button>
|
||||
<button value="setting_openai_key">Set OpenAI key</button>
|
||||
`,
|
||||
context: []
|
||||
} as LogEntry;
|
||||
}
|
||||
|
||||
async function loadTopicHistoryLogs(topicId: string | undefined): Promise<Array<LogEntry> | undefined> {
|
||||
if (!topicId) {
|
||||
return undefined;
|
||||
|
@ -1,8 +1,7 @@
|
||||
import * as vscode from "vscode";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { logger } from "../util/logger";
|
||||
import { log } from "console";
|
||||
import { ASSISTANT_NAME_ZH } from "../util/constants";
|
||||
import { ExtensionContextHolder } from "../util/extensionContext";
|
||||
|
||||
interface FunctionDefinition {
|
||||
name: string;
|
||||
@ -19,42 +18,10 @@ type CodeLensRegistration = {
|
||||
|
||||
export class CodeLensManager {
|
||||
private static instance: CodeLensManager;
|
||||
private registrations: CodeLensRegistration[] = [];
|
||||
private configFilePath: string;
|
||||
|
||||
private constructor() {
|
||||
this.configFilePath = path.join(
|
||||
process.env.HOME || process.env.USERPROFILE || ".",
|
||||
".chat/ideconfig.json"
|
||||
);
|
||||
this.loadConfig();
|
||||
}
|
||||
|
||||
public static getInstance(): CodeLensManager {
|
||||
if (!CodeLensManager.instance) {
|
||||
CodeLensManager.instance = new CodeLensManager();
|
||||
}
|
||||
return CodeLensManager.instance;
|
||||
}
|
||||
|
||||
private loadConfig(): void {
|
||||
if (!fs.existsSync(this.configFilePath)) {
|
||||
this.initializeConfig();
|
||||
} else {
|
||||
const data = fs.readFileSync(this.configFilePath, "utf-8");
|
||||
this.registrations = JSON.parse(data);
|
||||
|
||||
if (this.registrations.length === 0) {
|
||||
this.initializeConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private initializeConfig(): void {
|
||||
this.registrations = [
|
||||
private registrations: CodeLensRegistration[] = [
|
||||
{
|
||||
elementType: "function",
|
||||
objectName: "DevChat: unit tests",
|
||||
objectName: `${ExtensionContextHolder.context?.extension.packageJSON.assistantNames.ASSISTANT_NAME_ZH}: unit tests`,
|
||||
promptGenerator:
|
||||
"/unit_tests {__filename__}:::{__functionName__}:::{__functionStartLine__}:::{__functionEndLine__}:::{__containerStartLine__}:::{__containerEndLine__}",
|
||||
},
|
||||
@ -68,36 +35,17 @@ export class CodeLensManager {
|
||||
objectName: "docstring",
|
||||
promptGenerator: "/docstring",
|
||||
},
|
||||
// {
|
||||
// elementType: 'function',
|
||||
// objectName: 'generate unit tests',
|
||||
// promptGenerator: '/test generate unit tests for {__filename__} {__functionName__}'
|
||||
// },
|
||||
// {
|
||||
// elementType: 'inner_function',
|
||||
// objectName: 'generate comment',
|
||||
// promptGenerator: 'generate comment for \n ```code\n{__functionCode__}\n```\n'
|
||||
// },
|
||||
// {
|
||||
// elementType: 'function',
|
||||
// objectName: 'generate comment',
|
||||
// promptGenerator: 'generate comment for \n ```code\n{__functionCode__}\n```\n'
|
||||
// }
|
||||
];
|
||||
this.saveConfig();
|
||||
|
||||
private constructor() {}
|
||||
|
||||
public static getInstance(): CodeLensManager {
|
||||
if (!CodeLensManager.instance) {
|
||||
CodeLensManager.instance = new CodeLensManager();
|
||||
}
|
||||
return CodeLensManager.instance;
|
||||
}
|
||||
|
||||
private saveConfig(): void {
|
||||
const configDir = path.dirname(this.configFilePath);
|
||||
if (!fs.existsSync(configDir)) {
|
||||
fs.mkdirSync(configDir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(
|
||||
this.configFilePath,
|
||||
JSON.stringify(this.registrations, null, 2),
|
||||
"utf8"
|
||||
);
|
||||
}
|
||||
|
||||
public getRegistrations(): CodeLensRegistration[] {
|
||||
return this.registrations;
|
||||
|
@ -2,16 +2,15 @@ import * as vscode from 'vscode';
|
||||
|
||||
import { dependencyCheck } from './statusBarViewBase';
|
||||
import { ProgressBar } from '../util/progressBar';
|
||||
import { logger } from '../util/logger';
|
||||
import { DevChatConfig } from '../util/config';
|
||||
import { ASSISTANT_NAME_EN } from '../util/constants';
|
||||
|
||||
|
||||
export function createStatusBarItem(context: vscode.ExtensionContext): vscode.StatusBarItem {
|
||||
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
|
||||
|
||||
// Set the status bar item properties
|
||||
statusBarItem.text = `$(warning)DevChat`;
|
||||
statusBarItem.tooltip = 'DevChat is checking ..., please wait';
|
||||
statusBarItem.text = `$(warning)${ASSISTANT_NAME_EN}`;
|
||||
statusBarItem.tooltip = `${ASSISTANT_NAME_EN} is checking ..., please wait`;
|
||||
// when statsBarItem.command is '', then there is "command '' not found" error.
|
||||
statusBarItem.command = undefined;
|
||||
|
||||
@ -27,8 +26,8 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
||||
progressBar.update("Checking dependencies", 0);
|
||||
|
||||
const devchatStatus = await dependencyCheck();
|
||||
if (devchatStatus !== 'has statisfied the dependency' && devchatStatus !== 'DevChat has been installed') {
|
||||
statusBarItem.text = `$(warning)DevChat`;
|
||||
if (devchatStatus !== 'has statisfied the dependency' && devchatStatus !== `${ASSISTANT_NAME_EN} has been installed`) {
|
||||
statusBarItem.text = `$(warning)${ASSISTANT_NAME_EN}`;
|
||||
statusBarItem.tooltip = `${devchatStatus}`;
|
||||
|
||||
if (devchatStatus === 'Missing required dependency: Python3') {
|
||||
@ -42,7 +41,7 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
||||
return;
|
||||
}
|
||||
|
||||
statusBarItem.text = `$(pass)DevChat`;
|
||||
statusBarItem.text = `$(pass)${ASSISTANT_NAME_EN}`;
|
||||
statusBarItem.tooltip = `ready to chat`;
|
||||
statusBarItem.command = 'devcaht.onStatusBarClick';
|
||||
progressBar.update(`Checking dependencies: Success`, 0);
|
||||
@ -58,7 +57,7 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
||||
|
||||
clearInterval(timer);
|
||||
} catch (error) {
|
||||
statusBarItem.text = `$(warning)DevChat`;
|
||||
statusBarItem.text = `$(warning)${ASSISTANT_NAME_EN}`;
|
||||
statusBarItem.tooltip = `Error: ${error}`;
|
||||
statusBarItem.command = undefined;
|
||||
progressBar.endWithError(`Checking dependencies: Fail with exception.`);
|
||||
|
@ -1,14 +1,10 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { logger } from "../util/logger";
|
||||
|
||||
import { UiUtilWrapper } from "../util/uiUtil";
|
||||
import { ApiKeyManager } from '../util/apiKey';
|
||||
import { installDevchat } from '../util/python_installer/install_devchat';
|
||||
import { ASSISTANT_NAME_EN } from '../util/constants';
|
||||
|
||||
|
||||
let devchatStatus = '';
|
||||
let apiKeyStatus = '';
|
||||
|
||||
let preDevchatStatus = '';
|
||||
|
||||
@ -27,26 +23,31 @@ export async function dependencyCheck(): Promise<string> {
|
||||
|
||||
// define subfunction to check devchat dependency
|
||||
const getDevChatStatus = async (): Promise<string> => {
|
||||
const statuses = {
|
||||
installing: `installing ${ASSISTANT_NAME_EN}`,
|
||||
installed: `${ASSISTANT_NAME_EN} has been installed`,
|
||||
error: `An error occurred during the installation of ${ASSISTANT_NAME_EN}`
|
||||
}
|
||||
if (devchatStatus === '') {
|
||||
devchatStatus = 'installing devchat';
|
||||
devchatStatus = statuses.installing;
|
||||
const devchatCommandEnv = await installDevchat();
|
||||
if (devchatCommandEnv) {
|
||||
logger.channel()?.info(`Python: ${devchatCommandEnv}`);
|
||||
devchatStatus = 'DevChat has been installed';
|
||||
devchatStatus = statuses.installed;
|
||||
return devchatStatus;
|
||||
} else {
|
||||
logger.channel()?.info(`Python: undefined`);
|
||||
|
||||
devchatStatus = 'An error occurred during the installation of DevChat';
|
||||
devchatStatus = statuses.error;
|
||||
return devchatStatus;
|
||||
}
|
||||
} else if (devchatStatus === 'has statisfied the dependency') {
|
||||
return devchatStatus;
|
||||
} else if (devchatStatus === 'installing devchat') {
|
||||
} else if (devchatStatus === statuses.installing) {
|
||||
return devchatStatus;
|
||||
} else if (devchatStatus === 'DevChat has been installed') {
|
||||
} else if (devchatStatus === statuses.installed) {
|
||||
return devchatStatus;
|
||||
} else if (devchatStatus === 'An error occurred during the installation of DevChat') {
|
||||
} else if (devchatStatus === statuses.error) {
|
||||
return devchatStatus;
|
||||
}
|
||||
return "";
|
||||
@ -55,7 +56,7 @@ export async function dependencyCheck(): Promise<string> {
|
||||
const devchatPackageStatus = await getDevChatStatus();
|
||||
|
||||
if (devchatPackageStatus !== preDevchatStatus) {
|
||||
logger.channel()?.info(`devchat status: ${devchatPackageStatus}`);
|
||||
logger.channel()?.info(`${ASSISTANT_NAME_EN} status: ${devchatPackageStatus}`);
|
||||
preDevchatStatus = devchatPackageStatus;
|
||||
}
|
||||
|
||||
|
9
src/util/constants.ts
Normal file
9
src/util/constants.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { ExtensionContextHolder } from "./extensionContext";
|
||||
|
||||
export let ASSISTANT_NAME_EN = "DevChat";
|
||||
export let ASSISTANT_NAME_ZH = "DevChat";
|
||||
|
||||
export function updateNames(nameEN, nameZH) {
|
||||
ASSISTANT_NAME_EN = nameEN;
|
||||
ASSISTANT_NAME_ZH = nameZH;
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import { ASSISTANT_NAME_ZH } from "./constants";
|
||||
import { LogChannel } from "./logger";
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
@ -7,7 +8,7 @@ export class LoggerChannelVscode implements LogChannel {
|
||||
private static _instance: LoggerChannelVscode;
|
||||
|
||||
private constructor() {
|
||||
this._channel = vscode.window.createOutputChannel('DevChat', { log: true });
|
||||
this._channel = vscode.window.createOutputChannel(ASSISTANT_NAME_ZH, { log: true });
|
||||
}
|
||||
|
||||
public static getInstance(): LoggerChannelVscode {
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { ASSISTANT_NAME_ZH } from './constants';
|
||||
|
||||
export class ProgressBar {
|
||||
private message: string;
|
||||
@ -13,7 +14,7 @@ export class ProgressBar {
|
||||
init() {
|
||||
vscode.window.withProgress({
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: 'DevChat',
|
||||
title: ASSISTANT_NAME_ZH,
|
||||
cancellable: false
|
||||
}, (progress, token) => {
|
||||
return new Promise<void>((resolve) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user