Skip to content

Commit cb11ec5

Browse files
author
Rankin Zheng
committed
Merge branch 'main' into auto_custom_workflow
2 parents 0f93c39 + 459d6e0 commit cb11ec5

File tree

16 files changed

+156
-156
lines changed

16 files changed

+156
-156
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EXTENSION_NAME=devchat
2+
PUBLISHER=merico
3+
ASSISTANT_NAME_EN=DevChat
4+
ASSISTANT_NAME_ZH=DevChat
5+
EXTENSION_ICON=/path/to/extension_icon.png
6+
SIDEBAR_ICON=/path/to/sidebar_icon.svg
7+
DIFF_APPLY_ICON=/path/to/diff_apply_icon.svg

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ actions_backup/
1515
.DS_Store
1616

1717
__pycache__/
18+
*.log

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"${workspaceFolder}/dist/**/*.js"
1717
],
1818
"preLaunchTask": "${defaultBuildTask}",
19+
"postDebugTask": "npm: postbuild",
1920
"env": {
2021
"COMPLETE_DEBUG": "true"
2122
}

.vscode/tasks.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
"npm: watch-tests"
3636
],
3737
"problemMatcher": []
38+
},
39+
{
40+
"type": "npm",
41+
"script": "postbuild",
42+
"problemMatcher": [],
43+
"label": "npm: postbuild",
44+
"detail": "npm run postbuild"
3845
}
3946
]
4047
}

package.json

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"name": "devchat",
3-
"displayName": "DevChat",
3+
"displayName": "${ASSISTANT_NAME_ZH}",
44
"description": "Write prompts, not code",
55
"version": "0.1.74",
66
"icon": "assets/devchat.png",
7-
"publisher": "merico",
7+
"publisher": "${PUBLISHER}",
88
"engines": {
99
"vscode": "^1.75.0"
1010
},
11+
"assistantNames": {
12+
"ASSISTANT_NAME_EN": "${ASSISTANT_NAME_EN}",
13+
"ASSISTANT_NAME_ZH": "${ASSISTANT_NAME_ZH}"
14+
},
1115
"repository": {
1216
"type": "git",
1317
"url": "https://github.com/devchat-ai/devchat-vscode.git"
@@ -72,7 +76,7 @@
7276
"activitybar": [
7377
{
7478
"id": "devchat-sidebar",
75-
"title": "DevChat",
79+
"title": "${ASSISTANT_NAME_ZH}",
7680
"icon": "assets/devchat_icon.svg"
7781
}
7882
]
@@ -82,7 +86,7 @@
8286
{
8387
"type": "webview",
8488
"id": "devchat-view",
85-
"name": "DevChat"
89+
"name": "${ASSISTANT_NAME_ZH}"
8690
}
8791
]
8892
},
@@ -103,27 +107,27 @@
103107
},
104108
{
105109
"command": "devchat.addContext",
106-
"title": "Devchat:Add to DevChat"
110+
"title": "${ASSISTANT_NAME_EN}:Add to ${ASSISTANT_NAME_EN}"
107111
},
108112
{
109113
"command": "devchat.askForCode",
110-
"title": "Devchat:Add to DevChat"
114+
"title": "${ASSISTANT_NAME_EN}:Add to ${ASSISTANT_NAME_EN}"
111115
},
112116
{
113117
"command": "devchat.askForFile",
114-
"title": "Devchat:Add to DevChat"
118+
"title": "${ASSISTANT_NAME_EN}:Add to ${ASSISTANT_NAME_EN}"
115119
},
116120
{
117121
"command": "devchat.addConext_chinese",
118-
"title": "Devchat:添加到DevChat"
122+
"title": "${ASSISTANT_NAME_ZH}:添加到${ASSISTANT_NAME_ZH}"
119123
},
120124
{
121125
"command": "devchat.askForCode_chinese",
122-
"title": "Devchat:添加到DevChat"
126+
"title": "${ASSISTANT_NAME_ZH}:添加到${ASSISTANT_NAME_ZH}"
123127
},
124128
{
125129
"command": "devchat.askForFile_chinese",
126-
"title": "Devchat:添加到DevChat"
130+
"title": "${ASSISTANT_NAME_ZH}:添加到${ASSISTANT_NAME_ZH}"
127131
},
128132
{
129133
"command": "DevChat.InstallCommands",
@@ -137,32 +141,32 @@
137141
},
138142
{
139143
"command": "DevChat.Chat",
140-
"title": "Chat with DevChat",
144+
"title": "Chat with ${ASSISTANT_NAME_EN}",
141145
"category": "DevChat"
142146
},
143147
{
144148
"command": "devchat.explain",
145-
"title": "Devchat:Generate Explain"
149+
"title": "${ASSISTANT_NAME_EN}:Generate Explain"
146150
},
147151
{
148152
"command": "devchat.explain_chinese",
149-
"title": "Devchat:代码解释"
153+
"title": "${ASSISTANT_NAME_ZH}:代码解释"
150154
},
151155
{
152156
"command": "devchat.comments",
153-
"title": "Devchat:Generate Comments"
157+
"title": "${ASSISTANT_NAME_EN}:Generate Comments"
154158
},
155159
{
156160
"command": "devchat.comments_chinese",
157-
"title": "Devchat:生成注释"
161+
"title": "${ASSISTANT_NAME_ZH}:生成注释"
158162
},
159163
{
160164
"command": "devchat.fix",
161-
"title": "Devchat:Fix this"
165+
"title": "${ASSISTANT_NAME_EN}:Fix this"
162166
},
163167
{
164168
"command": "devchat.fix_chinese",
165-
"title": "Devchat:修复此"
169+
"title": "${ASSISTANT_NAME_ZH}:修复此"
166170
},
167171
{
168172
"command": "DevChat.codecomplete_callback",
@@ -171,12 +175,12 @@
171175
},
172176
{
173177
"command": "DevChat.quickFixAskDevChat",
174-
"title": "Ask DevChat",
178+
"title": "Ask ${ASSISTANT_NAME_EN}",
175179
"category": "DevChat"
176180
},
177181
{
178182
"command": "DevChat.quickFixUsingDevChat",
179-
"title": "Ask DevChat",
183+
"title": "Ask ${ASSISTANT_NAME_EN}",
180184
"category": "DevChat"
181185
}
182186
],
@@ -340,20 +344,21 @@
340344
}
341345
},
342346
"scripts": {
343-
"build:gui": "cd ./gui && yarn && yarn vscode",
344347
"vscode:uninstall": "node ./dist/uninstall",
345-
"vscode:prepublish": "npm run package",
346-
"compile": "webpack",
347-
"watch": "webpack --watch",
348-
"package": "webpack --mode production --devtool hidden-source-map",
349-
"compile-tests": "tsc -p . --outDir out",
350-
"watch-tests": "tsc -p . -w --outDir out",
351-
"pretest": "npm run compile-tests && npm run compile && npm run lint",
348+
"vscode:prepublish": "node prebuild.js && webpack --mode production --devtool hidden-source-map",
349+
"prebuild": "node prebuild.js",
350+
"postbuild": "git checkout -- assets package.json",
351+
"build:gui": "cd ./gui && yarn && yarn vscode",
352+
"build": "webpack --config webpack.config.js && npm run build:gui",
353+
"postpackage": "git checkout -- assets package.json",
354+
"package": "vsce package",
355+
"dev": "webpack serve --config webpack.config.js --open",
356+
"watch": "npm run prebuild && webpack --watch",
352357
"lint": "eslint src --ext ts",
353358
"test": "mocha",
354-
"build": "webpack --config webpack.config.js && cd ./gui && yarn && yarn vscode",
355-
"dev": "webpack serve --config webpack.config.js --open",
356-
"idea": "webpack --config webpack.idea.config.js && mv dist/main.js dist/main.html ../devchat-intellij/src/main/resources/static && echo '🎆done'"
359+
"pretest": "npm run compile-tests && npm run compile && npm run lint",
360+
"compile-tests": "tsc -p . --outDir out",
361+
"watch-tests": "npm run prebuild && tsc -p . -w --outDir out"
357362
},
358363
"devDependencies": {
359364
"@babel/core": "^7.21.8",

prebuild.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require('dotenv').config()
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
6+
function copyIcon(src, dst) {
7+
if (!src) {
8+
console.warn(`Icon path for ${dst} is not defined in your environment variables`)
9+
return
10+
}
11+
console.log(`Replacing icon ${dst} by ${src}`)
12+
if (!fs.existsSync(src)) {
13+
console.warn(`Icon file ${src} does not exist.`)
14+
return
15+
}
16+
17+
const destPath = path.join(__dirname, 'assets', dst)
18+
19+
try {
20+
fs.copyFileSync(src, destPath)
21+
fs.chmodSync(destPath, 0o644)
22+
} catch(e) {
23+
console.warn(`Failed to copy logo ${e}`)
24+
}
25+
}
26+
27+
function updatePackageJson() {
28+
const placeholders = {
29+
EXTENSION_NAME: process.env.EXTENSION_NAME || "devchat",
30+
PUBLISHER: process.env.PUBLISHER || "merico",
31+
ASSISTANT_NAME_EN: process.env.ASSISTANT_NAME_EN || "DevChat",
32+
ASSISTANT_NAME_ZH: process.env.ASSISTANT_NAME_ZH || "DevChat"
33+
}
34+
console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`)
35+
36+
let packageJson = fs.readFileSync('package.json', 'utf8');
37+
38+
// Replace placeholders
39+
Object.entries(placeholders).forEach(([key, value]) => {
40+
const regex = new RegExp(`\\$\\{${key}\\}`, 'g');
41+
packageJson = packageJson.replace(regex, value);
42+
});
43+
44+
fs.writeFileSync('package.json', packageJson);
45+
}
46+
47+
copyIcon(process.env.EXTENSION_ICON, 'devchat.png')
48+
copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg')
49+
copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg')
50+
51+
updatePackageJson()

src/contributes/quickFixProvider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { collapseFileExculdeSelectRange } from "./codecomplete/ast/collapseBlock";
3+
import { ASSISTANT_NAME_EN } from "../util/constants";
34

45
class DevChatQuickFixProvider implements vscode.CodeActionProvider {
56
public static readonly providedCodeActionKinds = [
@@ -18,21 +19,21 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
1819

1920
const diagnostic = context.diagnostics[0];
2021
const quickFix = new vscode.CodeAction(
21-
"Ask DevChat",
22+
`Ask ${ASSISTANT_NAME_EN}`,
2223
vscode.CodeActionKind.QuickFix,
2324
);
2425
quickFix.isPreferred = false;
2526

2627
const fixUsingDevChat = new vscode.CodeAction(
27-
"Fix using DevChat",
28+
`Fix using ${ASSISTANT_NAME_EN}`,
2829
vscode.CodeActionKind.QuickFix,
2930
);
3031
fixUsingDevChat.isPreferred = true;
3132

3233
return new Promise(async (resolve) => {
3334
quickFix.command = {
3435
command: "DevChat.quickFixAskDevChat",
35-
title: "Ask DevChat",
36+
title: `Ask ${ASSISTANT_NAME_EN}`,
3637
arguments: [
3738
document,
3839
range,
@@ -42,7 +43,7 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
4243

4344
fixUsingDevChat.command = {
4445
command: "DevChat.quickFixUsingDevChat",
45-
title: "Fix using DevChat",
46+
title: `Fix using ${ASSISTANT_NAME_EN}`,
4647
arguments: [
4748
document,
4849
range,

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { InlineCompletionProvider, registerCodeCompleteCallbackCommand } from ".
3535
import { indexDir } from "./contributes/codecomplete/astIndex";
3636
import registerQuickFixProvider from "./contributes/quickFixProvider";
3737
import { stopLocalService } from './util/localService';
38+
import { updateNames } from "./util/constants";
3839

3940

4041
async function migrateConfig() {
@@ -129,6 +130,8 @@ export async function fixDevChatApiBase() {
129130

130131
async function activate(context: vscode.ExtensionContext) {
131132
ExtensionContextHolder.context = context;
133+
const assistantNames = context.extension.packageJSON.assistantNames
134+
updateNames(assistantNames.ASSISTANT_NAME_EN, assistantNames.ASSISTANT_NAME_ZH)
132135

133136
logger.init(LoggerChannelVscode.getInstance());
134137
UiUtilWrapper.init(new UiUtilVscode());

src/handler/chatHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ASSISTANT_NAME_EN } from '../util/constants';
12
import { UiUtilWrapper } from '../util/uiUtil';
23
import { MessageHandler } from './messageHandler';
34
import { isSending } from './sendMessage';
@@ -6,7 +7,7 @@ import { isSending } from './sendMessage';
67
export async function chatWithDevChat(panel, message: string) {
78
if (isSending()) {
89
// already sending, show error
9-
UiUtilWrapper.showErrorMessage("DevChat: A command is already being sent, please try again later.");
10+
UiUtilWrapper.showErrorMessage(`${ASSISTANT_NAME_EN}: A command is already being sent, please try again later.`);
1011
return;
1112
}
1213
MessageHandler.sendMessage(panel!, { command: 'chatWithDevChat', 'message': message });

src/handler/historyMessagesBase.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,6 @@ export interface LoadHistoryMessages {
1818
entries: Array<LogEntry>;
1919
}
2020

21-
function welcomeMessage(): LogEntry {
22-
// create default logEntry to show welcome message
23-
return {
24-
hash: 'message',
25-
parent: '',
26-
user: 'system',
27-
date: '',
28-
request: 'How do I use DevChat?',
29-
response: `
30-
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.
31-
32-
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!
33-
`,
34-
context: []
35-
} as LogEntry;
36-
}
37-
38-
function apiKeyMissedMessage(): LogEntry {
39-
// create default logEntry to show welcome message
40-
return {
41-
hash: 'message',
42-
parent: '',
43-
user: 'system',
44-
date: '',
45-
request: 'Is OPENAI_API_KEY (or DevChat Access Key) ready?',
46-
response: `
47-
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.
48-
49-
<button value="get_devchat_key" href="https://web.devchat.ai" component="a">Register DevChat key</button>
50-
<button value="setting_devchat_key">Set DevChat key</button>
51-
<button value="setting_openai_key">Set OpenAI key</button>
52-
`,
53-
context: []
54-
} as LogEntry;
55-
}
56-
5721
async function loadTopicHistoryLogs(topicId: string | undefined): Promise<Array<LogEntry> | undefined> {
5822
if (!topicId) {
5923
return undefined;

0 commit comments

Comments
 (0)