Skip to content

Commit

Permalink
feat: add expert-code-enhancer feature
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Aug 13, 2024
1 parent ae41855 commit 9e88d6c
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--disable-extensions"
"--extensionDevelopmentPath=${workspaceFolder}"
// "--disable-extensions"
],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "npm: watch",
Expand Down
107 changes: 105 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
"title": "%command.codeViewerHelper%",
"icon": "$(open-editors-view-icon)"
},
{
"command": "aide.expertCodeEnhancer",
"title": "%command.expertCodeEnhancer%",
"icon": "$(extensions-configure-recommended)"
},
{
"command": "aide.renameVariable",
"title": "%command.renameVariable%"
Expand Down Expand Up @@ -170,6 +175,10 @@
{
"command": "aide.codeConvert",
"group": "0_aide@121"
},
{
"command": "aide.expertCodeEnhancer",
"group": "0_aide@122"
}
],
"editor/title": [
Expand All @@ -180,6 +189,10 @@
{
"command": "aide.codeConvert",
"group": "navigation@2"
},
{
"command": "aide.expertCodeEnhancer",
"group": "navigation@3"
}
]
},
Expand Down Expand Up @@ -218,6 +231,96 @@
"scope": "resource",
"markdownDescription": "%config.codeViewerHelperPrompt.description%"
},
"aide.expertCodeEnhancerPromptList": {
"type": "array",
"default": [
{
"match": "**/*",
"title": "%config.expertCodeEnhancerPromptList.solid%",
"prompt": "Please refactor the following code to better adhere to SOLID principles. Focus on Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion where applicable. Explain your changes briefly in comments.",
"sort": 150,
"autoContext": false
},
{
"match": "**/*",
"title": "%config.expertCodeEnhancerPromptList.dry%",
"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.",
"sort": 160,
"autoContext": false
},
{
"match": "**/*",
"title": "%config.expertCodeEnhancerPromptList.designPatterns%",
"prompt": "Analyze the following code and suggest refactoring using appropriate design patterns. Consider creational, structural, and behavioral patterns that could improve the code's flexibility, maintainability, and scalability.",
"sort": 170,
"autoContext": false
},
{
"match": [
"**/*.vue",
"**/*.tsx",
"**/*.jsx"
],
"title": "%config.expertCodeEnhancerPromptList.splitComponents%",
"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 with new component files clearly separated.",
"sort": 140,
"autoContext": true
},
{
"match": "**/*",
"title": "%config.expertCodeEnhancerPromptList.cleanliness%",
"prompt": "Refactor the following code to improve its cleanliness and readability. Focus on consistent naming conventions, appropriate comments, logical code organization, and reducing complexity. Ensure the code follows best practices for the given language.",
"sort": 180,
"autoContext": false
},
{
"match": "**/*",
"title": "%config.expertCodeEnhancerPromptList.performance%",
"prompt": "Review the following code and optimize it for better performance. Focus on algorithmic efficiency, reducing unnecessary computations, and improving data structure usage. If applicable, consider asynchronous operations and memory management.",
"sort": 190,
"autoContext": true
},
{
"match": [
"**/*.sql",
"**/*Repository.{java,kt,scala,cs,py,js,ts}",
"**/*Dao.{java,kt,scala,cs,py,js,ts}",
"**/*Mapper.{java,kt,scala,cs,py,js,ts}",
"**/*Query.{java,kt,scala,cs,py,js,ts}",
"**/*.orm.{py,rb}",
"**/*.entity.{ts,js}",
"**/*Service.{java,kt,scala,cs,py,js,ts}"
],
"title": "%config.expertCodeEnhancerPromptList.databaseQueries%",
"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.",
"sort": 130,
"autoContext": true
},
{
"match": "**/*",
"title": "%config.expertCodeEnhancerPromptList.security%",
"prompt": "Review the following code and enhance its security measures. Focus on identifying and mitigating common vulnerabilities such as SQL injection, XSS, CSRF, and insecure data handling. Provide safer alternatives and explain the security improvements.",
"sort": 200,
"autoContext": true
},
{
"match": [
"**/*.{java,kt,scala,cs,go,cpp,c,rs,py}",
"**/*Async*.{java,kt,scala,cs,go,cpp,c,rs,py}",
"**/*Parallel*.{java,kt,scala,cs,go,cpp,c,rs,py}",
"**/*Concurrent*.{java,kt,scala,cs,go,cpp,c,rs,py}",
"**/*Thread*.{java,kt,scala,cs,go,cpp,c,rs,py}",
"**/*Worker*.{java,kt,scala,cs,go,cpp,c,rs,py}"
],
"title": "%config.expertCodeEnhancerPromptList.concurrency%",
"prompt": "Refactor the following code to improve its concurrency and multithreading capabilities. Focus on efficient resource sharing, preventing race conditions, and enhancing overall parallel processing performance.",
"sort": 180,
"autoContext": true
}
],
"scope": "resource",
"markdownDescription": "%config.expertCodeEnhancerPromptList.description%"
},
"aide.convertLanguagePairs": {
"type": "object",
"default": {},
Expand Down Expand Up @@ -347,8 +450,8 @@
"ignore": "^5.3.2",
"inquirer": "^9.3.4",
"knip": "^5.27.2",
"langchain": "^0.2.15",
"lint-staged": "^15.2.8",
"langchain": "^0.2.16",
"lint-staged": "^15.2.9",
"minimatch": "^9.0.5",
"node-fetch": "^3.3.2",
"p-limit": "^6.1.0",
Expand Down
15 changes: 14 additions & 1 deletion package.nls.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"command.askAI": "✨ Aide: Ask AI",
"command.codeConvert": "✨ Aide: Code Convert",
"command.codeViewerHelper": "✨ Aide: Code Viewer Helper",
"command.expertCodeEnhancer": "✨ Aide: Expert Code Enhancer",
"command.renameVariable": "✨ Aide: Rename Variable",
"command.smartPaste": "✨ Aide: Smart Paste",
"command.batchProcessor": "✨ Aide: AI Batch Processor",
Expand All @@ -16,7 +17,17 @@
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API request concurrency, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/api-concurrency)",
"config.useSystemProxy.description": "Use global proxy (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`), you need to restart `VSCode` to take effect after changing this setting, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/use-system-proxy)",
"config.codeViewerHelperPrompt.description": "Code viewer helper prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
"config.codeViewerHelperPrompt.description": "Code viewer helper AI prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
"config.expertCodeEnhancerPromptList.description": "Expert code enhancer AI prompt template list, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/expert-code-enhancer-prompt-list)",
"config.expertCodeEnhancerPromptList.solid": "Optimize using SOLID principles",
"config.expertCodeEnhancerPromptList.dry": "Apply DRY principle",
"config.expertCodeEnhancerPromptList.designPatterns": "Apply appropriate design patterns",
"config.expertCodeEnhancerPromptList.splitComponents": "Split into smaller components",
"config.expertCodeEnhancerPromptList.cleanliness": "Improve code cleanliness",
"config.expertCodeEnhancerPromptList.performance": "Optimize for performance",
"config.expertCodeEnhancerPromptList.databaseQueries": "Optimize database queries",
"config.expertCodeEnhancerPromptList.security": "Enhance security measures",
"config.expertCodeEnhancerPromptList.concurrency": "Optimize concurrency and multithreading",
"config.convertLanguagePairs.description": "Default convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/convert-language-pairs)",
"config.autoRememberConvertLanguagePairs.description": "Automatically remember convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/auto-remember-convert-language-pairs)",
"config.readClipboardImage.description": "Allow reading clipboard images as AI context in certain scenarios, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/read-clipboard-image)",
Expand Down Expand Up @@ -74,5 +85,7 @@
"input.selectAiSuggestionsVariableName.prompt": "Select AI suggestions variable name",
"input.batchProcessor.prompt": "Let AI batch process your selected {0} files, what do you want AI to do?",
"input.batchProcessor.placeholder": "eg: help me migrate from python2 to python3",
"input.expertCodeEnhancer.selectPrompt.title": "Select code optimize method",
"input.expertCodeEnhancer.customPrompt.placeholder": "Custom optimize prompt",
"file.content": "File: {0}\n```{1}\n{2}\n```\n\n"
}
15 changes: 14 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"command.askAI": "✨ Aide: Ask AI",
"command.codeConvert": "✨ Aide: Code Convert",
"command.codeViewerHelper": "✨ Aide: Code Viewer Helper",
"command.expertCodeEnhancer": "✨ Aide: Expert Code Enhancer",
"command.renameVariable": "✨ Aide: Rename Variable",
"command.smartPaste": "✨ Aide: Smart Paste",
"command.batchProcessor": "✨ Aide: AI Batch Processor",
Expand All @@ -16,7 +17,17 @@
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API request concurrency, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/api-concurrency)",
"config.useSystemProxy.description": "Use global proxy (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`), you need to restart `VSCode` to take effect after changing this setting, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/use-system-proxy)",
"config.codeViewerHelperPrompt.description": "Code viewer helper prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
"config.codeViewerHelperPrompt.description": "Code viewer helper AI prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
"config.expertCodeEnhancerPromptList.description": "Expert code enhancer AI prompt template list, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/expert-code-enhancer-prompt-list)",
"config.expertCodeEnhancerPromptList.solid": "Optimize using SOLID principles",
"config.expertCodeEnhancerPromptList.dry": "Apply DRY principle",
"config.expertCodeEnhancerPromptList.designPatterns": "Apply appropriate design patterns",
"config.expertCodeEnhancerPromptList.splitComponents": "Split into smaller components",
"config.expertCodeEnhancerPromptList.cleanliness": "Improve code cleanliness",
"config.expertCodeEnhancerPromptList.performance": "Optimize for performance",
"config.expertCodeEnhancerPromptList.databaseQueries": "Optimize database queries",
"config.expertCodeEnhancerPromptList.security": "Enhance security measures",
"config.expertCodeEnhancerPromptList.concurrency": "Optimize concurrency and multithreading",
"config.convertLanguagePairs.description": "Default convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/convert-language-pairs)",
"config.autoRememberConvertLanguagePairs.description": "Automatically remember convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/auto-remember-convert-language-pairs)",
"config.readClipboardImage.description": "Allow reading clipboard images as AI context in certain scenarios, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/read-clipboard-image)",
Expand Down Expand Up @@ -74,5 +85,7 @@
"input.selectAiSuggestionsVariableName.prompt": "Select AI suggestions variable name",
"input.batchProcessor.prompt": "Let AI batch process your selected {0} files, what do you want AI to do?",
"input.batchProcessor.placeholder": "eg: help me migrate from python2 to python3",
"input.expertCodeEnhancer.selectPrompt.title": "Select code optimize method",
"input.expertCodeEnhancer.customPrompt.placeholder": "Custom optimize prompt",
"file.content": "File: {0}\n```{1}\n{2}\n```\n\n"
}
15 changes: 14 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"command.askAI": "✨ Aide: 问 AI",
"command.codeConvert": "✨ Aide: 代码转换",
"command.codeViewerHelper": "✨ Aide: 代码查看器助手",
"command.expertCodeEnhancer": "✨ Aide: 让大师帮你改代码",
"command.renameVariable": "✨ Aide: 重命名变量",
"command.smartPaste": "✨ Aide: 智能粘贴",
"command.batchProcessor": "✨ Aide: AI 批量处理文件",
Expand All @@ -16,7 +17,17 @@
"config.openaiBaseUrl.description": "OpenAI Base URL, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API 请求并发数, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/api-concurrency)",
"config.useSystemProxy.description": "是否使用全局代理 (`HTTP_PROXY`、`HTTPS_PROXY`、`ALL_PROXY`) , 更改此设置后需要重启 `VSCode` 才生效, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/use-system-proxy)",
"config.codeViewerHelperPrompt.description": "代码查看器助手 prompt 模板, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/code-viewer-helper-prompt)",
"config.codeViewerHelperPrompt.description": "代码查看器助手 AI 提示词模板, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/code-viewer-helper-prompt)",
"config.expertCodeEnhancerPromptList.description": "大师代码优化 AI 提示词模板列表, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/expert-code-enhancer-prompt-list)",
"config.expertCodeEnhancerPromptList.solid": "使用 SOLID 原则优化",
"config.expertCodeEnhancerPromptList.dry": "应用 DRY 原则",
"config.expertCodeEnhancerPromptList.designPatterns": "应用适当的设计模式",
"config.expertCodeEnhancerPromptList.splitComponents": "拆分为更小的组件",
"config.expertCodeEnhancerPromptList.cleanliness": "提高代码整洁度",
"config.expertCodeEnhancerPromptList.performance": "优化性能",
"config.expertCodeEnhancerPromptList.databaseQueries": "优化数据库查询",
"config.expertCodeEnhancerPromptList.security": "加强安全措施",
"config.expertCodeEnhancerPromptList.concurrency": "优化并发和多线程",
"config.convertLanguagePairs.description": "默认转换语言对照表, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/convert-language-pairs)",
"config.autoRememberConvertLanguagePairs.description": "是否自动记住转换语言对照表, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/auto-remember-convert-language-pairs)",
"config.readClipboardImage.description": "是否允许某些场景读取剪贴板图片作为 AI 上下文, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/read-clipboard-image)",
Expand Down Expand Up @@ -74,5 +85,7 @@
"input.selectAiSuggestionsVariableName.prompt": "选择 AI 建议的变量名",
"input.batchProcessor.prompt": "让 AI 批量处理你选中的 {0} 个文件,你想 AI 做什么?",
"input.batchProcessor.placeholder": "比如:帮我从 python2 迁移到 python3",
"input.expertCodeEnhancer.selectPrompt.title": "选择代码优化方式",
"input.expertCodeEnhancer.customPrompt.placeholder": "自定义优化提示词",
"file.content": "File: {0}\n```{1}\n{2}\n```\n\n"
}
Loading

0 comments on commit 9e88d6c

Please sign in to comment.