From 3cdaba12e7bdd680742caeccfa5f4ee3fa406ef3 Mon Sep 17 00:00:00 2001 From: JinmingYang <2214962083@qq.com> Date: Fri, 16 Aug 2024 04:39:05 +0800 Subject: [PATCH] docs: add Expert Code Enhancer doc --- README.md | 7 +-- README_CN.md | 7 +-- README_JP.md | 7 +-- package.json | 30 +++---------- src/extension/config.ts | 8 ++-- src/extension/index.ts | 3 +- src/extension/providers/webview.ts | 20 +++++++++ website/.vitepress/config/en.ts | 8 ++++ website/.vitepress/config/zh.ts | 8 ++++ .../expert-code-enhancer-prompt-list.md | 42 ++++++++++++++++++ .../en/guide/features/expert-code-enhancer.md | 37 +++++++++++++++ website/en/guide/getting-started/index.md | 18 +++++--- .../videos/aide-expert-code-enhancer.mp4 | Bin 0 -> 3258817 bytes .../expert-code-enhancer-prompt-list.md | 42 ++++++++++++++++++ .../zh/guide/features/expert-code-enhancer.md | 37 +++++++++++++++ website/zh/guide/getting-started/index.md | 18 +++++--- .../zh/guide/use-another-llm/aide-models.md | 1 + 17 files changed, 240 insertions(+), 53 deletions(-) create mode 100644 website/en/guide/configuration/expert-code-enhancer-prompt-list.md create mode 100644 website/en/guide/features/expert-code-enhancer.md create mode 100644 website/public/videos/aide-expert-code-enhancer.mp4 create mode 100644 website/zh/guide/configuration/expert-code-enhancer-prompt-list.md create mode 100644 website/zh/guide/features/expert-code-enhancer.md diff --git a/README.md b/README.md index 9fe5864..96294ae 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,12 @@ https://github.com/user-attachments/assets/55f85f8e-7515-4da3-b850-9c078b3440d5 - 🔄 **[Code Convert](https://aide.nicepkg.cn/guide/features/code-convert)**: Transform code between any programming languages with one click. - 📖 **[Code Viewer Helper](https://aide.nicepkg.cn/guide/features/code-viewer-helper)**: Add detailed comments to enhance code readability. -- 🔀 **[Smart Paste](https://aide.nicepkg.cn/guide/features/smart-paste)**: Intelligently convert clipboard content (code or images) when pasting. -- 🤖 **[AI Batch Processor](https://aide.nicepkg.cn/guide/features/batch-processor)**: Process multiple files using AI according to custom requirements. +- 🔧 **[Expert Code Enhancer](https://aide.nicepkg.cn/guide/features/expert-code-enhancer)**: Hand your code over to AI for optimization and see how an expert would write it. +- 📋 **[Smart Paste](https://aide.nicepkg.cn/guide/features/smart-paste)**: Intelligently convert clipboard content (code or images) when pasting. +- 🗂️ **[AI Batch Processor](https://aide.nicepkg.cn/guide/features/batch-processor)**: Process multiple files using AI according to custom requirements. - 🏷 **[Rename Variable](https://aide.nicepkg.cn/guide/features/rename-variable)**: Get AI-suggested variable names with explanations. - 💬 **[Ask AI](https://aide.nicepkg.cn/guide/features/ask-ai)**: Execute custom AI commands on selected files or folders. -- 📋 **[Copy as AI Prompt](https://aide.nicepkg.cn/guide/features/copy-as-prompt)**: Easily copy files/folders content as AI prompts. +- 📝 **[Copy as AI Prompt](https://aide.nicepkg.cn/guide/features/copy-as-prompt)**: Easily copy files/folders content as AI prompts. ## Installation 📦 diff --git a/README_CN.md b/README_CN.md index a890795..4347fb3 100644 --- a/README_CN.md +++ b/README_CN.md @@ -30,11 +30,12 @@ https://github.com/user-attachments/assets/55f85f8e-7515-4da3-b850-9c078b3440d5 - 🔄 **[代码转换](https://aide.nicepkg.cn/zh/guide/features/code-convert)**: 一键在任何编程语言之间转换代码。 - 📖 **[代码查看器助手](https://aide.nicepkg.cn/zh/guide/features/code-viewer-helper)**: 添加详细注释以提高代码可读性。 -- 🔀 **[智能粘贴](https://aide.nicepkg.cn/zh/guide/features/smart-paste)**: 粘贴时智能转换剪贴板内容(代码或图片)。 -- 🤖 **[AI 批量处理文件](https://aide.nicepkg.cn/zh/guide/features/batch-processor)**: 根据自定义要求使用 AI 处理多个文件。 +- 🔧 **[让大师帮你改代码](https://aide.nicepkg.cn/zh/guide/features/expert-code-enhancer)**: 把你的代码给 AI 优化,看看大师是怎么写代码的。 +- 📋 **[智能粘贴](https://aide.nicepkg.cn/zh/guide/features/smart-paste)**: 粘贴时智能转换剪贴板内容(代码或图片)。 +- 🗂️ **[AI 批量处理文件](https://aide.nicepkg.cn/zh/guide/features/batch-processor)**: 根据自定义要求使用 AI 处理多个文件。 - 🏷 **[重命名变量](https://aide.nicepkg.cn/zh/guide/features/rename-variable)**: 获取 AI 建议的变量名及解释。 - 💬 **[问 AI](https://aide.nicepkg.cn/zh/guide/features/ask-ai)**: 对选定的文件或文件夹执行自定义 AI 命令。 -- 📋 **[复制为 AI 提示词](https://aide.nicepkg.cn/zh/guide/features/copy-as-prompt)**: 轻松复制文件/文件夹内容作为 AI 提示。 +- 📝 **[复制为 AI 提示词](https://aide.nicepkg.cn/zh/guide/features/copy-as-prompt)**: 轻松复制文件/文件夹内容作为 AI 提示。 ## 安装 📦 diff --git a/README_JP.md b/README_JP.md index ce94c9f..867a409 100644 --- a/README_JP.md +++ b/README_JP.md @@ -30,11 +30,12 @@ https://github.com/user-attachments/assets/55f85f8e-7515-4da3-b850-9c078b3440d5 - 🔄 **[コード変換](https://aide.nicepkg.cn/guide/features/code-convert)**: ワンクリックで任意のプログラミング言語間でコードを変換します。 - 📖 **[コードビューアヘルパー](https://aide.nicepkg.cn/guide/features/code-viewer-helper)**: 詳細なコメントを追加してコードの可読性を向上させます。 -- 🔀 **[スマートペースト](https://aide.nicepkg.cn/guide/features/smart-paste)**: クリップボードの内容(コードや画像)を貼り付け時にインテリジェントに変換します。 -- 🤖 **[AI バッチプロセッサ](https://aide.nicepkg.cn/guide/features/batch-processor)**: カスタム要件に従って AI を使用して複数のファイルを処理します。 +- 🔧 **[エキスパートコードエンハンサー](https://aide.nicepkg.cn/guide/features/expert-code-enhancer)**: コードを AI に渡して最適化し、エキスパートがどのように書くか見てみましょう。 +- 📋 **[スマートペースト](https://aide.nicepkg.cn/guide/features/smart-paste)**: クリップボードの内容(コードや画像)を貼り付け時にインテリジェントに変換します。 +- 🗂️ **[AI バッチプロセッサ](https://aide.nicepkg.cn/guide/features/batch-processor)**: カスタム要件に従って AI を使用して複数のファイルを処理します。 - 🏷 **[変数のリネーム](https://aide.nicepkg.cn/guide/features/rename-variable)**: 説明付きの AI 提案の変数名を取得します。 - 💬 **[AI に質問](https://aide.nicepkg.cn/guide/features/ask-ai)**: 選択したファイルやフォルダにカスタム AI コマンドを実行します。 -- 📋 **[AI プロンプトとしてコピー](https://aide.nicepkg.cn/guide/features/copy-as-prompt)**: ファイル/フォルダの内容を AI プロンプトとして簡単にコピーします。 +- 📝 **[AI プロンプトとしてコピー](https://aide.nicepkg.cn/guide/features/copy-as-prompt)**: ファイル/フォルダの内容を AI プロンプトとして簡単にコピーします。 ## インストール 📦 diff --git a/package.json b/package.json index ce9429e..ef1056b 100644 --- a/package.json +++ b/package.json @@ -66,24 +66,6 @@ "onStartupFinished" ], "contributes": { - "viewsContainers": { - "activitybar": [ - { - "id": "aide", - "title": "Aide", - "icon": "res/icon-mask.png" - } - ] - }, - "views": { - "aide": [ - { - "type": "webview", - "id": "aide.webview", - "name": "Aide" - } - ] - }, "commands": [ { "command": "aide.copyAsPrompt", @@ -231,12 +213,6 @@ "scope": "resource", "markdownDescription": "%config.codeViewerHelperPrompt.description%" }, - "aide.expertCodeEnhancerPromptList": { - "type": "array", - "default": [], - "scope": "resource", - "markdownDescription": "%config.expertCodeEnhancerPromptList.description%" - }, "aide.convertLanguagePairs": { "type": "object", "default": {}, @@ -248,6 +224,12 @@ "default": true, "markdownDescription": "%config.autoRememberConvertLanguagePairs.description%" }, + "aide.expertCodeEnhancerPromptList": { + "type": "array", + "default": [], + "scope": "resource", + "markdownDescription": "%config.expertCodeEnhancerPromptList.description%" + }, "aide.readClipboardImage": { "type": "boolean", "default": false, diff --git a/src/extension/config.ts b/src/extension/config.ts index 8a34a6f..8011296 100644 --- a/src/extension/config.ts +++ b/src/extension/config.ts @@ -63,6 +63,10 @@ const configKey = { ...pkgConfig['aide.aiCommandAutoRun'], type: 'boolean' }, + expertCodeEnhancerPromptList: { + ...pkgConfig['aide.expertCodeEnhancerPromptList'], + type: 'array' + }, autoRememberConvertLanguagePairs: { ...pkgConfig['aide.autoRememberConvertLanguagePairs'], type: 'boolean' @@ -76,10 +80,6 @@ const configKey = { type: 'object', optional: true }, - expertCodeEnhancerPromptList: { - ...pkgConfig['aide.expertCodeEnhancerPromptList'], - type: 'array' - }, codeViewerHelperPrompt: { ...pkgConfig['aide.codeViewerHelperPrompt'], type: 'string' diff --git a/src/extension/index.ts b/src/extension/index.ts index 1df6450..d945617 100644 --- a/src/extension/index.ts +++ b/src/extension/index.ts @@ -11,7 +11,6 @@ import { logger } from './logger' import { enablePolyfill } from './polyfill' import { registerProviders } from './providers' import { initAideKeyUsageStatusBar } from './providers/aide-key-usage-statusbar' -import { renderWebview } from './providers/webview' import { redisStorage, stateStorage } from './storage' export const activate = async (context: vscode.ExtensionContext) => { @@ -31,7 +30,7 @@ export const activate = async (context: vscode.ExtensionContext) => { await initAideKeyUsageStatusBar(context) await autoOpenCorrespondingFiles(context) await cleanup(context) - await renderWebview(context) + // await renderWebview(context) } catch (err) { logger.warn('Failed to activate extension', err) } diff --git a/src/extension/providers/webview.ts b/src/extension/providers/webview.ts index 587d9f7..65cded5 100644 --- a/src/extension/providers/webview.ts +++ b/src/extension/providers/webview.ts @@ -2,6 +2,26 @@ import { saveImage, setupHtml } from '@extension/utils' import type { WebviewToExtensionsMsg } from '@shared/types/msg' import * as vscode from 'vscode' +// { +// "viewsContainers": { +// "activitybar": [ +// { +// "id": "aide", +// "title": "Aide", +// "icon": "res/icon-mask.png" +// } +// ] +// }, +// "views": { +// "aide": [ +// { +// "type": "webview", +// "id": "aide.webview", +// "name": "Aide" +// } +// ] +// }, +// } class AideWebViewProvider implements vscode.WebviewViewProvider { public static readonly viewType = 'aide.webview' diff --git a/website/.vitepress/config/en.ts b/website/.vitepress/config/en.ts index 8e5548c..2ecec93 100644 --- a/website/.vitepress/config/en.ts +++ b/website/.vitepress/config/en.ts @@ -88,6 +88,10 @@ function sidebar(): DefaultTheme.Sidebar { text: 'Code Convert', link: '/code-convert' }, + { + text: 'Expert Code Enhancer', + link: '/expert-code-enhancer' + }, { text: 'Smart Paste', link: '/smart-paste' @@ -141,6 +145,10 @@ function sidebar(): DefaultTheme.Sidebar { text: 'aide.autoRememberConvertLanguagePairs', link: '/auto-remember-convert-language-pairs' }, + { + text: 'aide.expertCodeEnhancerPromptList', + link: '/expert-code-enhancer-prompt-list' + }, { text: 'aide.readClipboardImage', link: '/read-clipboard-image' diff --git a/website/.vitepress/config/zh.ts b/website/.vitepress/config/zh.ts index c793c48..e104962 100644 --- a/website/.vitepress/config/zh.ts +++ b/website/.vitepress/config/zh.ts @@ -113,6 +113,10 @@ function sidebar(): DefaultTheme.Sidebar { text: '智能代码转换', link: '/code-convert' }, + { + text: '让大师帮你改代码', + link: '/expert-code-enhancer' + }, { text: '智能粘贴', link: '/smart-paste' @@ -172,6 +176,10 @@ function sidebar(): DefaultTheme.Sidebar { text: 'aide.autoRememberConvertLanguagePairs', link: '/auto-remember-convert-language-pairs' }, + { + text: 'aide.expertCodeEnhancerPromptList', + link: '/expert-code-enhancer-prompt-list' + }, { text: 'aide.readClipboardImage', link: '/read-clipboard-image' diff --git a/website/en/guide/configuration/expert-code-enhancer-prompt-list.md b/website/en/guide/configuration/expert-code-enhancer-prompt-list.md new file mode 100644 index 0000000..8d55ac6 --- /dev/null +++ b/website/en/guide/configuration/expert-code-enhancer-prompt-list.md @@ -0,0 +1,42 @@ +# aide.expertCodeEnhancerPromptList + +This configuration allows you to customize ==the AI prompt list for expert code enhancement==. + +With these prompts, you can specify how to optimize and refactor your code. Prompts can be customized to match specific files based on file path patterns. + +**Prompt Configuration Fields:** + +| Field | Description | Required | Default | +| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- | +| `match` | File path matching pattern, supports [glob](https://github.com/isaacs/node-glob) syntax. The prompt will only be displayed if the current file path matches. | No | `"**/*"` | +| `title` | Title of the prompt, displayed in the selection list. | Yes | | +| `prompt` | Content of the prompt, describing the optimization operation needed. | Yes | | +| `sort` | Sorting weight, the smaller the number, the higher it ranks. | No | `1000` | +| `autoContext` | Whether to enable automatic context support. When enabled, AI will also read files potentially related to the current file before processing the code. Defaults to `false`. Requires the `function_call` feature. | No | `false` | + +**Usage Example:** + +```json +{ + "aide.expertCodeEnhancerPromptList": [ + { + "match": ["**/*.sql", "**/*Repository.{java,kt,scala,cs,py,js,ts}"], + "title": "Optimize Database Queries", + "prompt": "Analyze and optimize the database queries in the following code. Focus on improving query performance, reducing unnecessary joins, optimizing indexing suggestions, and ensuring efficient data retrieval patterns.", + "autoContext": true + }, + { + "match": ["**/*.vue", "**/*.tsx", "**/*.jsx"], + "title": "Split Into Smaller Components", + "prompt": "Analyze the following code and split it into smaller, more manageable components. Focus on identifying reusable parts, separating concerns, and improving overall component structure. Provide the refactored code.", + "autoContext": true + }, + { + "match": "**/*", + "title": "Optimize Using DRY Principles", + "prompt": "Refactor the following code to eliminate redundancy and improve maintainability by applying the DRY (Don't Repeat Yourself) principle. Identify repeated code patterns and abstract them into reusable functions or classes as appropriate.", + "autoContext": false + } + ] +} +``` diff --git a/website/en/guide/features/expert-code-enhancer.md b/website/en/guide/features/expert-code-enhancer.md new file mode 100644 index 0000000..27fd8f4 --- /dev/null +++ b/website/en/guide/features/expert-code-enhancer.md @@ -0,0 +1,37 @@ +# Expert Code Enhancer + +Command Name: `aide.expertCodeEnhancer` + +Use AI to optimize and refactor the entire file or selected code. Supports multiple programming languages. + +::: warning Warning + +This feature sometimes requires AI models that support the `function_call` capability. + +::: + +**Scenarios:** + +- When inheriting a legacy project, you want to optimize hard-to-read code. +- Helps you clean up and refactor legacy code to make it more readable. +- You want to improve your own coding skills. +- Helps you refactor code following principles like SOLID and DRY. +- Automatically applies appropriate design patterns to your code. +- Automatically checks and fixes security vulnerabilities in your code. +- Automatically detects and optimizes performance issues in your code. +- Allows custom AI optimization prompts for specific files, replacing many traditional code handling scripts. + +**Usage:** + +- Select the code in the editor. +- Click the pencil icon at the top right or right-click and select `✨ Aide: Expert Code Enhancer`. + +::: tip +If the output is interrupted, you can click the original pencil icon or right-click and select `✨ Aide: Expert Code Enhancer` to continue. +::: + +