From 3bbc5305bae91928152eb76ef41c4b822edb3c56 Mon Sep 17 00:00:00 2001 From: andiwang1993 Date: Sun, 29 Jan 2023 16:26:50 +0800 Subject: [PATCH] 1.1.2 --- .gitignore | 3 +- CHANGELOG.md | 22 +++ README.md | 15 ++- package.json | 31 +++-- src/extension.ts | 4 +- src/localconfig.ts | 2 +- src/mode/generationWithInteractiveMode.ts | 8 +- src/mode/generationWithPrompMode.ts | 11 +- src/param/configures.ts | 1 - src/param/constparams.ts | 2 +- src/provider/inlineCompletionProvider.ts | 127 +++++++++++++++++- .../inlineCompletionProviderWithCommand.ts | 6 + src/provider/translationWebviewProvider.ts | 2 - src/utils/chooseCandidate.ts | 1 - src/utils/codeGenByTemplate.ts | 2 - src/utils/commentCode.ts | 4 - src/utils/getCodeCompletions.ts | 9 +- src/utils/getCodeTranslation.ts | 4 +- src/utils/getDocumentLanguage.ts | 2 - src/utils/navUri.ts | 1 + src/utils/statisticFunc.ts | 47 ++++--- webview-ui/copy.svg | 8 +- webview-ui/insert.svg | 14 +- webview-ui/main.js | 2 +- webview-ui/styles.css | 63 +++++---- 25 files changed, 293 insertions(+), 98 deletions(-) diff --git a/.gitignore b/.gitignore index 8b6aa2f..ca140b1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ dist node_modules .vscode-test/ *.vsix -*.js.map \ No newline at end of file +*.js.map +src/localconfig.ts \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 40bb458..22e6c55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ # Change Log +v1.1.2 (2023-01-17) + +- Fix some known issues + +v1.1.1 (2023-01-10) + +- Fix some known bugs + +- Improve the quality of suggestions + +- Change the keybinding of command a new line from ``Alt/option+N`` to ``Alt/option+\`` + +v1.1.0 (2023-01-03) + +- Fix some known bugs + +- Add translation component to activity bar + +- Add new option Only Key Control, to get suggestions only in need (command: ``Alt/option + N`` to get suggestions in this mode) + +- Add conditions to key ``Tab``, if there is some suggestions, press ``Tab`` to accept the current suggestion, otherwise, press to indent + v1.0.9 (2022-12-12) - Fix some known bugs diff --git a/README.md b/README.md index 3bf8010..9a04288 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ ![CodeGeeX license](https://img.shields.io/github/license/THUDM/CodeGeeX?colorA=0B9FE0&colorB=brightgreen) ![CodeGeeX vscode extension version](https://img.shields.io/visual-studio-marketplace/v/aminer.codegeex?colorA=0B9FE0&colorB=brightgreen) ![CodeGeeX download](https://img.shields.io/visual-studio-marketplace/d/aminer.codegeex?colorA=0B9FE0&colorB=brightgreen) -![CodeGeeX API calls per week](https://img.shields.io/badge/dynamic/json?label=API%20calls&query=%24.result.count&suffix=%2Fweek&url=http%3A%2F%2Ftianqi.aminer.cn%2Fapi%2Fv1%2Fapi%2Fcodegeex%2Fdashboard%3Ftime_type%3Dweeks&colorA=0B9FE0&colorB=brightgreen) ![CodeGeeX vscode extension rating](https://img.shields.io/visual-studio-marketplace/stars/aminer.codegeex?colorA=0B9FE0&colorB=brightgreen) ![CodeGeeX vscode extension last update](https://img.shields.io/visual-studio-marketplace/last-updated/aminer.codegeex?colorA=0B9FE0&colorB=brightgreen) [![CodeGeeX github stars](https://img.shields.io/github/stars/THUDM/CodeGeeX?style=social)](https://github.com/THUDM/CodeGeeX) @@ -14,7 +13,17 @@ CodeGeeX is an AI-based coding assistant, which can suggest code in the current In addition, with the large-scale model, CodeGeeX can translate codes to other programming languages, and provides customizable features (**Prompt Mode**) to help you configure your own programming assistant. Happy coding! -Please kindly let us know if you encounter any problem or have any suggestion, via [codegeex@aminer.cn](mailto:codegeex@aminer.cn). Or you can also fill out the survey(https://wj.qq.com/s2/11260705/6cd6/)/问卷(https://wj.qq.com/s2/11259178/fd49/) to tell us about all your feelings for our extension. +Please kindly let us know if you encounter any problem or have any suggestion, via [codegeex@aminer.cn](mailto:codegeex@aminer.cn). Or you can join our [Slack](https://join.slack.com/t/codegeexworkspace/shared_invite/zt-1m76zecsi-~JW59Jmvx09lX4Pqv9oE_w) or [Telegram](https://t.me/+IipIayJ32B1jOTg1) or [WeChat/微信群](https://wj.qq.com/s2/11274205/a15b/) to give us your feedback or get support. Furthermore, welcome to fill out the [survey](https://wj.qq.com/s2/11260705/6cd6/)/[问卷](https://wj.qq.com/s2/11259178/fd49/) to tell us about all your feelings for our extension. + +### Quick menu: + +**[Basic Usage](#basic-usage)**
+**[Privacy](#privacy)**
+**[Guidance](#guidance)**
+ ***[Stealth Mode](#stealth-mode)***
+ ***[Interactive Mode](#interactive-mode)***
+ ***[Translation Mode](#translation-mode)***
+ ***[Prompt Mode](#prompt-mode)***
## Basic Usage Make sure vscode version is >= 1.68.0. Install the extension and enable it globally. There are three modes of usage: @@ -31,7 +40,7 @@ We highly respect the privacy of your code. The code is only used as the input o ## Guidance Please see the details and examples for how to use the three modes in CodeGeeX: ### Stealth mode -In this mode, CodeGeeX will start generating codes when you stop writing (the icon at the bottom of VSCode starts spinning). When the generated code is shown in gray, just press ``Tab`` to insert the generated codes. You can also press ``Alt/Option+[`` or ``]`` to change between candidates. If you are not satisfied with the current suggestions, you can also press ``Alt/Option+N`` to get new suggestions. Change the number of candidates in the extension settings ``Candidate Num`` (more candidates will slow down the generation speed). **Note**: The generation always starts at the current position of your cursor, thus if you modify the code before the generation is finished, it will probably cause bugs. We keep working on making the generation faster. +In this mode, CodeGeeX will start generating codes when you stop writing (the icon at the bottom of VSCode starts spinning). When the generated code is shown in gray, just press ``Tab`` to insert the generated codes. You can also press ``Alt/Option+[`` or ``]`` to change between candidates. If you are not satisfied with the current suggestions, you can also press ``Alt/Option+\`` to get new suggestions. Change the number of candidates in the extension settings ``Candidate Num`` (more candidates will slow down the generation speed). **Note**: The generation always starts at the current position of your cursor, thus if you modify the code before the generation is finished, it will probably cause bugs. We keep working on making the generation faster. ![image](https://lfs.aminer.cn/misc/wangshan/pretrain/codegeex/bubble_sort_go.gif) diff --git a/package.json b/package.json index fabbe25..80f8518 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,14 @@ "publisher": "AMiner", "name": "codegeex", "displayName": "CodeGeeX", - "description": "We introduce CodeGeeX, a large-scale multilingual code generative model with 13 billion parameters, pretrained on a large code corpus of more than 20 programming languages.", - "homepage": "https://models.aminer.cn/codegeex", + "description": "CodeGeeX is an AI-based coding assistant, which can suggest code in the current or following lines. It is powered by a large-scale multilingual code generation model with 13 billion parameters, pretrained on a large code corpus of more than 20 programming languages.", + "homepage": "https://codegeex.ai", "repository": { "type": "git", "url": "https://github.com/THUDM/CodeGeeX" }, "icon": "codegeex_logo.png", - "version": "1.1.0", + "version": "1.1.2", "engines": { "vscode": "^1.68.0" }, @@ -19,6 +19,19 @@ "Machine Learning", "Other" ], + "keywords": [ + "python", + "go", + "java", + "javascript", + "c++", + "c#", + "php", + "typescript", + "ai", + "autocomplete", + "inline completion" + ], "activationEvents": [ "*" ], @@ -106,12 +119,12 @@ "type": "object", "additionalProperties": "string", "default": {}, - "description": "DisabledFor is a list of specific languages that will be disabled temporarily for the extension, you can set manully language* as the key and then set the value true to disable a language or false to re-enable it in workspace settings (this will need to restart vscode) or do this by clicking icon in the status bar.\n*language should be a valid vscode language id, like python, shellscript, csharp, objective-cpp and etc. You can click the language option in status bar to find the list and language ids are in the parentheses." + "markdownDescription": "DisabledFor is a list of specific languages that will be disabled temporarily for the extension, you can set manully language* as the key and then set the value true to disable a language or false to re-enable it settings (this will need to restart vscode) or do this by clicking icon in the status bar.
* *language should be a valid vscode language id, like python, shellscript, csharp, objective-cpp and etc.* You can click the language option in status bar to find the list and language ids are in the parentheses." }, "Codegeex.EnableExtension": { "type": "boolean", "default": true, - "description": "This will decide if you enable the stealth mode of the extension." + "description": "Check this if you want to enable stealth mode of the extension." }, "Codegeex.GenerationPreference": { "type": "string", @@ -125,7 +138,7 @@ "Codegeex.OnlyKeyControl": { "type": "boolean", "default": null, - "description": "This will decide if you want to get suggestions only in need by pressing alt/option+n" + "description": "Check this if you want to get suggestions only in need by pressing alt/option+\\ in stealth mode." }, "Codegeex.PromptTemplates(Experimental)": { "type": "object", @@ -143,7 +156,7 @@ "Codegeex.Survey": { "type": "boolean", "default": null, - "markdownDescription": "This is decided by if you have chosen to make a survey. If you want to make the survey again, you can click the link:
[EN]:https://wj.qq.com/s2/11260705/6cd6/
[CN]:https://wj.qq.com/s2/11259178/fd49/" + "markdownDescription": "This is decided by if you have chosen to make a survey. If you want to make the survey again, you can click the link: [survey](https://wj.qq.com/s2/11260705/6cd6/)/[问卷](https://wj.qq.com/s2/11259178/fd49/)" }, "Codegeex.Translation": { "type": "string", @@ -152,7 +165,7 @@ "comment" ], "default": "comment", - "description": "When inserting code translated, you want to ___ original code" + "description": "When inserting code translated, you want to ___ original code when you use the translation mode." } } } @@ -171,7 +184,7 @@ }, { "command": "codegeex.new-completions", - "key": "Alt+N", + "key": "Alt+\\", "when": "editorFocus && !editorReadonly" }, { diff --git a/src/extension.ts b/src/extension.ts index 22afce0..b846916 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -169,13 +169,12 @@ export async function activate(context: vscode.ExtensionContext) { if (onlyKeyControl) { context.globalState.update("DisableInlineCompletion", true); } else { + context.globalState.update("DisableInlineCompletion", false); context.subscriptions.push( - //vscode.commands.registerCommand('codegeex.inline-completions',()=> vscode.languages.registerInlineCompletionItemProvider( { pattern: "**" }, inlineProvider ) - //) ); } @@ -204,6 +203,7 @@ export async function activate(context: vscode.ExtensionContext) { "EnableExtension" ); if (editor) { + changeIconColor( //@ts-ignore enableExtension, diff --git a/src/localconfig.ts b/src/localconfig.ts index 5db909b..88a0292 100644 --- a/src/localconfig.ts +++ b/src/localconfig.ts @@ -5,6 +5,6 @@ export const apiSecret = ""; //write your statistic hert here or disable it export const statApiHerf = ""; -export const enableStats = true; +//export const enableStats = true; export const surveyUrlCN = ""; export const surveyUrlEN = ""; diff --git a/src/mode/generationWithInteractiveMode.ts b/src/mode/generationWithInteractiveMode.ts index 65b0d9e..358ec12 100644 --- a/src/mode/generationWithInteractiveMode.ts +++ b/src/mode/generationWithInteractiveMode.ts @@ -22,12 +22,18 @@ export default async function generationWithInteractiveMode( cursorPosition.character ); let code_block = document.getText(selection); + if ( + cursorPosition.character === 0 && + code_block[code_block.length - 1] !== "\n" + ) { + code_block += "\n"; + } code_block = code_block .replaceAll("#", hash) .replaceAll("+", addSignal) .replaceAll("&", andSignal); updateStatusBarItem(myStatusBarItem, g_isLoading, true, ""); - await codegeexCodeGen(code_block.trim()) + await codegeexCodeGen(code_block) .then(() => updateStatusBarItem(myStatusBarItem, g_isLoading, false, "Done") ) diff --git a/src/mode/generationWithPrompMode.ts b/src/mode/generationWithPrompMode.ts index c28eaf4..1e02fd1 100644 --- a/src/mode/generationWithPrompMode.ts +++ b/src/mode/generationWithPrompMode.ts @@ -20,12 +20,15 @@ export async function generateWithPromptMode( let custom_prompts = {}; for (let key of keys) { if (key != "explanation") { - items.push({ label: key, description: "" }); - // @ts-ignore - custom_prompts[key] = await readTemplate(templates[key]); + try { + // @ts-ignore + custom_prompts[key] = await readTemplate(templates[key]); + items.push({ label: key, description: "" }); + } catch (err) { + console.log(err); + } } } - console.log(custom_prompts); vscode.window.showQuickPick(items).then((selection) => { if (!selection) { diff --git a/src/param/configures.ts b/src/param/configures.ts index 3caabba..a22e42e 100644 --- a/src/param/configures.ts +++ b/src/param/configures.ts @@ -38,7 +38,6 @@ export const translationInsertMode = configuration.get("Translation"); export const enableExtension = configuration.get("EnableExtension", true); export const acceptedsurvey = configuration.get("Survey", null); export const completionDelay = configuration.get("CompletionDelay", 0.5); -export const choseModel = configuration.get("Codex.Model"); export const templates = configuration.get("PromptTemplates(Experimental)", {}); export const onlyKeyControl = configuration.get("OnlyKeyControl"); export const controls = { diff --git a/src/param/constparams.ts b/src/param/constparams.ts index d9ee16d..c230d4a 100644 --- a/src/param/constparams.ts +++ b/src/param/constparams.ts @@ -4,7 +4,7 @@ import { localeCN } from "../locales/localeCN"; import { localeEN } from "../locales/localeEN"; export const extensionId = "aminer.codegeex"; -export const extensionVersion = "1.1.0"; +export const extensionVersion = "1.1.2"; export const myScheme = "codegeex"; //api to do the statistics of data diff --git a/src/provider/inlineCompletionProvider.ts b/src/provider/inlineCompletionProvider.ts index f07e5e4..2dd0c57 100644 --- a/src/provider/inlineCompletionProvider.ts +++ b/src/provider/inlineCompletionProvider.ts @@ -18,6 +18,89 @@ let delay: number = completionDelay * 1000; // let timeExecute: number = 2500; // let last5ExecuteTime = [2500,2500,2500,2500,2500]; +function middleOfLineWontComplete(editor: any, document: any) { + const cursorPosition = editor.selection.active; + let currentLine = document?.lineAt(cursorPosition.line); + let lineEndPosition = currentLine?.range.end; + let selectionTrailingString: vscode.Selection; + + selectionTrailingString = new vscode.Selection( + cursorPosition.line, + cursorPosition.character, + cursorPosition.line, + lineEndPosition.character + 1 + ); + let trailingString = document.getText(selectionTrailingString); + var re = /^[\]\{\}\); \n\r\t\'\"]*$/; + if (re.test(trailingString)) { + return false; + } else { + return true; + } +} + +function isAtTheMiddleOfLine(editor: any, document: any) { + const cursorPosition = editor.selection.active; + let currentLine = document?.lineAt(cursorPosition.line); + let lineEndPosition = currentLine?.range.end; + let selectionTrailingString: vscode.Selection; + + selectionTrailingString = new vscode.Selection( + cursorPosition.line, + cursorPosition.character, + cursorPosition.line, + lineEndPosition.character + 1 + ); + let trailingString = document.getText(selectionTrailingString); + let trimmed = trailingString.trim(); + return trimmed.length !== 0; +} + +function removeTrailingCharsByReplacement( + completion: string, + replacement: string +) { + for (let ch of replacement) { + if (!isBracketBalanced(completion, ch)) { + completion = replaceLast(completion, ch, ""); + } + } + return completion; +} + +function replaceLast(str: string, toReplace: string, replacement: string) { + let pos = str.lastIndexOf(toReplace); + if (pos > -1) { + return ( + str.substring(0, pos) + + replacement + + str.substring(pos + toReplace.length) + ); + } else { + return str; + } +} + +function isBracketBalanced(str: string, character: string) { + let count = 0; + for (let ch of str) { + if (ch === character) { + count++; + } + if ( + (character === "{" && ch === "}") || + (character === "[" && ch === "]") || + (character === "(" && ch === ")") || + (character === "}" && ch === "{") || + (character === "]" && ch === "[") || + (character === ")" && ch === "(") + ) { + count--; + } + } + return count === 0; +} + interface MyInlineCompletionItem extends vscode.InlineCompletionItem { trackingId: number; } @@ -73,6 +156,12 @@ export default function inlineCompletionProvider( cursorPosition.character ); let textBeforeCursor = document.getText(selection); + if ( + cursorPosition.character === 0 && + textBeforeCursor[textBeforeCursor.length - 1] !== "\n" + ) { + textBeforeCursor += "\n"; + } if (vscode.window.activeNotebookEditor) { const cells = vscode.window.activeNotebookEditor.notebook.getCells(); @@ -98,9 +187,10 @@ export default function inlineCompletionProvider( cursorPosition.line, cursorPosition.character + 1 ); - let nextChar = document.getText(selectionNextChar); - const checkString = "]}) \n\t'\""; - if (!checkString.includes(nextChar)) { + // let nextChar = document.getText(selectionNextChar); + // const checkString = "]}) \n\t'\""; + // if (!checkString.includes(nextChar)) { + if (middleOfLineWontComplete(editor, document)) { console.log("不进行补充"); updateStatusBarItem(myStatusBarItem, g_isLoading, false, ""); return; @@ -268,7 +358,38 @@ export default function inlineCompletionProvider( let items = new Array(); let cursorPosition = editor.selection.active; for (let i = 0; i < rs.completions.length; i++) { + let completion = rs.completions[i]; + if (isAtTheMiddleOfLine(editor, document)) { + const cursorPosition = editor.selection.active; + let currentLine = document?.lineAt(cursorPosition.line); + let lineEndPosition = currentLine?.range.end; + let selectionTrailingString: vscode.Selection; + + selectionTrailingString = new vscode.Selection( + cursorPosition.line, + cursorPosition.character, + cursorPosition.line, + lineEndPosition.character + 1 + ); + let trailingString = document.getText( + selectionTrailingString + ); + completion = removeTrailingCharsByReplacement( + completion, + trailingString + ); + if ( + completion.trimEnd().slice(-1) === "{" || + completion.trimEnd().slice(-1) === ";" || + completion.trimEnd().slice(-1) === ":" + ) { + completion = completion + .trimEnd() + .substring(0, completion.length - 1); + } + } items.push({ + // insertText: completion, insertText: rs.completions[i], // range: new vscode.Range(endPosition.translate(0, rs.completions.length), endPosition), range: new vscode.Range( diff --git a/src/provider/inlineCompletionProviderWithCommand.ts b/src/provider/inlineCompletionProviderWithCommand.ts index 9ab7807..9530f3c 100644 --- a/src/provider/inlineCompletionProviderWithCommand.ts +++ b/src/provider/inlineCompletionProviderWithCommand.ts @@ -76,6 +76,12 @@ export default function inlineCompletionProviderWithCommand( cursorPosition.character ); let textBeforeCursor = document.getText(selection); + if ( + cursorPosition.character === 0 && + textBeforeCursor[textBeforeCursor.length - 1] !== "\n" + ) { + textBeforeCursor += "\n"; + } if (vscode.window.activeNotebookEditor) { const cells = vscode.window.activeNotebookEditor.notebook.getCells(); diff --git a/src/provider/translationWebviewProvider.ts b/src/provider/translationWebviewProvider.ts index ad17a92..db2391b 100644 --- a/src/provider/translationWebviewProvider.ts +++ b/src/provider/translationWebviewProvider.ts @@ -50,7 +50,6 @@ export default class translationWebviewProvider implements WebviewViewProvider { "webview-ui", "main.js", ]); - console.log(mainUri); const stylesUri = getUri(webview, extensionUri, [ "webview-ui", "styles.css", @@ -241,7 +240,6 @@ Here is the code translated from the input console.log(err); commandid = ""; } - console.log(result.translation[0]); webviewView.webview.postMessage({ command: "code.translate", payload: result.translation[0], diff --git a/src/utils/chooseCandidate.ts b/src/utils/chooseCandidate.ts index 8375300..bc5ec02 100644 --- a/src/utils/chooseCandidate.ts +++ b/src/utils/chooseCandidate.ts @@ -30,7 +30,6 @@ export default function chooseCandidate( lang, "line" ).replaceAll(comment, commentSignal.line || "#"); - console.log(commentedText); editBuilder.replace(s, commentedText + "\n" + fn); } else { editBuilder.replace(s, fn); diff --git a/src/utils/codeGenByTemplate.ts b/src/utils/codeGenByTemplate.ts index 31b52d4..b175116 100644 --- a/src/utils/codeGenByTemplate.ts +++ b/src/utils/codeGenByTemplate.ts @@ -18,7 +18,6 @@ export default async function codeGenByTemplate( let txt: string = document.getText( new vscode.Range(sel[x].start, sel[x].end) ); - // console.log(txt) prompt_input += txt; } var selection = editor.selection; @@ -59,7 +58,6 @@ export default async function codeGenByTemplate( iter = re.exec(templateStr); } console.log("about to request"); - console.log(prompt); lang = getDocumentLanguage(editor); updateStatusBarItem(myStatusBarItem, g_isLoading, true, ""); rs = await getCodeCompletions( diff --git a/src/utils/commentCode.ts b/src/utils/commentCode.ts index 669d032..ee7fd45 100644 --- a/src/utils/commentCode.ts +++ b/src/utils/commentCode.ts @@ -21,14 +21,11 @@ export default function commentCode( return comment + input.replaceAll("\n", "\n" + comment); } if (commentSignal.blockLeft && commentSignal.blockRight) { - console.log("test1"); return commentSignal.blockLeft + input + commentSignal.blockRight; } if (commentSignal.line) { - console.log("test2"); return comment + input.replaceAll("\n", "\n" + comment); } - console.log("test3"); return input; } export function getCommentSignal(lang: string) { @@ -64,7 +61,6 @@ export function getCommentSignal(lang: string) { }; break; case "python": - console.log("python"); commentSignal = { blockLeft: '"""', blockRight: '"""', diff --git a/src/utils/getCodeCompletions.ts b/src/utils/getCodeCompletions.ts index e18bfd0..20a1eac 100644 --- a/src/utils/getCodeCompletions.ts +++ b/src/utils/getCodeCompletions.ts @@ -85,7 +85,6 @@ export function getCodeCompletions( } else { inputText = prompt; } - console.log(inputText); let commandid: string; let time1 = new Date().getTime(); try { @@ -97,9 +96,12 @@ export function getCodeCompletions( try { let time2 = new Date().getTime(); axios - .post(API_URL, payload, { timeout: 120000 }) + .post(API_URL, payload, { proxy: false, timeout: 120000 }) .then(async (res) => { console.log(res); + console.log( + "process time: " + res.data.result.process_time + ); if (res?.data.status === 0) { let codeArray = res?.data.result.output.code; const completions = Array(); @@ -107,14 +109,13 @@ export function getCodeCompletions( const completion = codeArray[i]; let tmpstr = completion; if (tmpstr.trim() === "") continue; - + if (completions.includes(completion)) continue; completions.push(completion); } let timeEnd = new Date().getTime(); console.log(timeEnd - time1, timeEnd - time2); resolve({ completions, commandid }); } else { - console.log(res); try { await getEndData(commandid, res.data.message, "No"); } catch (err) { diff --git a/src/utils/getCodeTranslation.ts b/src/utils/getCodeTranslation.ts index 06480b4..3a89d22 100644 --- a/src/utils/getCodeTranslation.ts +++ b/src/utils/getCodeTranslation.ts @@ -32,9 +32,8 @@ export function getCodeTranslation( }); axios - .post(API_URL, payload, { timeout: 120000 }) + .post(API_URL, payload, { proxy: false, timeout: 120000 }) .then((res) => { - console.log(res); if (res?.data.status === 0) { let codeArray = res?.data.result.output.code; const translation = Array(); @@ -48,6 +47,7 @@ export function getCodeTranslation( resolve({ translation }); } else { console.log(res); + reject("failed"); } }) .catch((err) => { diff --git a/src/utils/getDocumentLanguage.ts b/src/utils/getDocumentLanguage.ts index b26a564..498f174 100644 --- a/src/utils/getDocumentLanguage.ts +++ b/src/utils/getDocumentLanguage.ts @@ -1,8 +1,6 @@ import { TextEditor } from "vscode"; export default function getDocumentLanguage(editor: TextEditor) { const documentLanguageId: string = editor.document.languageId; - console.log("documentLanguageId"); - console.log(documentLanguageId); let lang = ""; switch (documentLanguageId) { case "cpp": diff --git a/src/utils/navUri.ts b/src/utils/navUri.ts index 4d199fa..bac3d64 100644 --- a/src/utils/navUri.ts +++ b/src/utils/navUri.ts @@ -6,6 +6,7 @@ export const navUri = async ( mode: string ) => { const doc = await vscode.workspace.openTextDocument(uri); + await vscode.window.showTextDocument(doc, { viewColumn: vscode.ViewColumn.Beside, preview: true, diff --git a/src/utils/statisticFunc.ts b/src/utils/statisticFunc.ts index a0f1be9..eff847a 100644 --- a/src/utils/statisticFunc.ts +++ b/src/utils/statisticFunc.ts @@ -9,22 +9,26 @@ export function getOpenExtensionData(): Promise { return new Promise((resolve, reject) => { try { axios - .post(`${apiHerf}/tracking/insertVscodeStartRecord`, { - vscodeMachineId: vscode.env.machineId, - vscodeSessionId: vscode.env.sessionId, - platformVersion: os.release(), - systemOs: os.type(), - extensionId: extensionId, - extensionVersion: extensionVersion, - nodeArch: os.arch(), - isNewAppInstall: vscode.env.isNewAppInstall, - vscodeVersion: vscode.version, - product: vscode.env.appHost, - uikind: vscode.env.uiKind, - remoteName: vscode.env.remoteName, - }) + .post( + `${apiHerf}/tracking/insertVscodeStartRecord`, + { + vscodeMachineId: vscode.env.machineId, + vscodeSessionId: vscode.env.sessionId, + platformVersion: os.release(), + systemOs: os.type(), + extensionId: extensionId, + extensionVersion: extensionVersion, + nodeArch: os.arch(), + isNewAppInstall: vscode.env.isNewAppInstall, + vscodeVersion: vscode.version, + product: vscode.env.appHost, + uikind: vscode.env.uiKind, + remoteName: vscode.env.remoteName, + }, + { proxy: false } + ) .then((res) => { - console.log(res); + console.log("写入开机信息", res); resolve(res.data.msg); }) .catch((err) => { @@ -55,7 +59,10 @@ export function getStartData( }; try { axios - .post(`${apiHerf}/tracking/vsCodeOperationRecord`, startParam) + .post(`${apiHerf}/tracking/vsCodeOperationRecord`, startParam, { + proxy: false, + timeout: 1000, + }) .then((res) => { console.log("开始请求测试", res); let commandid = res.data.data.id || ""; @@ -94,7 +101,10 @@ export function getEndData( }; try { axios - .post(`${apiHerf}/tracking/vsCodeOperationRecord`, endparam) + .post(`${apiHerf}/tracking/vsCodeOperationRecord`, endparam, { + proxy: false, + timeout: 1000, + }) .then((res) => { console.log("测试结束埋点", res); resolve(""); @@ -113,7 +123,8 @@ export function getTotalRequestNum(): Promise { try { axios .get( - `${apiHerf}/tracking/selectByVscodeMachineIdTotal?vscodeMachineId=${vscode.env.machineId}` + `${apiHerf}/tracking/selectByVscodeMachineIdTotal?vscodeMachineId=${vscode.env.machineId}`, + { proxy: false } ) .then((res) => { console.log("获取总请求数", res); diff --git a/webview-ui/copy.svg b/webview-ui/copy.svg index 9be25f8..dce3f6f 100644 --- a/webview-ui/copy.svg +++ b/webview-ui/copy.svg @@ -1,3 +1,7 @@ - - + + \ No newline at end of file diff --git a/webview-ui/insert.svg b/webview-ui/insert.svg index 86b118a..3bd6deb 100644 --- a/webview-ui/insert.svg +++ b/webview-ui/insert.svg @@ -1,3 +1,13 @@ - - + + + + \ No newline at end of file diff --git a/webview-ui/main.js b/webview-ui/main.js index 491e52a..a495b3a 100644 --- a/webview-ui/main.js +++ b/webview-ui/main.js @@ -91,7 +91,7 @@ function setVSCodeMessageListener() { break; case "code.changeDstLang": const dstLang = document.getElementById("dstLang"); - if(dstLang.value !== event.data.dstLang){ + if (dstLang.value !== event.data.dstLang) { dstLang.value = event.data.dstLang; //displayData('',dstLang); } diff --git a/webview-ui/styles.css b/webview-ui/styles.css index 0ec2e0c..a153c4e 100644 --- a/webview-ui/styles.css +++ b/webview-ui/styles.css @@ -1,40 +1,39 @@ - -#original,#summary { - width: 95%; - height: 400px; - min-width: 250px; - margin-left: auto; - margin-right: auto; - height: auto; - font-size: small; - border: 1px solid #B0ACAC; - background-color: #333333; - color: #f2f2f2; - overflow-x: scroll; - white-space: nowrap; - - +#original, +#summary { + width: 95%; + height: 400px; + min-width: 250px; + margin-left: auto; + margin-right: auto; + height: auto; + font-size: small; + border: 1px solid #b0acac; + background-color: #333333; + color: #f2f2f2; + overflow-x: scroll; + white-space: nowrap; } #translate-button { - margin: 5px; + margin: 5px; } -#copy-button, #insert-button { - width: 43px; - background-color: transparent; - padding-bottom: 0; - font-size: 10px; - color: #d9d9d9; +#copy-button, +#insert-button { + width: 43px; + background-color: transparent; + padding-bottom: 0; + font-size: 10px; + color: #d9d9d9; } -.title{ - width: 90%; - font-size: 15px; +.title { + width: 90%; + font-size: 15px; } -table{ - width: 95%; - margin-top: 10px; - min-width:250px; - text-align: left; -} \ No newline at end of file +table { + width: 95%; + margin-top: 10px; + min-width: 250px; + text-align: left; +}