Skip to content

Commit 2a3b4ed

Browse files
committed
feat: add aide.useSystemProxy and aide.aiCommandAutoRun configuration and enhance languageId select
1 parent cebfabd commit 2a3b4ed

26 files changed

Lines changed: 279 additions & 89 deletions

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
"default": "https://api.openai.com/v1",
152152
"markdownDescription": "%config.openaiBaseUrl.description%"
153153
},
154+
"aide.useSystemProxy": {
155+
"type": "boolean",
156+
"default": true,
157+
"markdownDescription": "%config.useSystemProxy.description%"
158+
},
154159
"aide.codeViewerHelperPrompt": {
155160
"type": "string",
156161
"editPresentation": "multilineText",
@@ -217,6 +222,11 @@
217222
"default": true,
218223
"scope": "resource",
219224
"markdownDescription": "%config.aiCommandCopyBeforeRun.description%"
225+
},
226+
"aide.aiCommandAutoRun": {
227+
"type": "boolean",
228+
"default": true,
229+
"markdownDescription": "%config.aiCommandAutoRun.description%"
220230
}
221231
}
222232
}

package.nls.en.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-key)",
1010
"config.openaiModel.description": "OpenAI Model, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-model)",
1111
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
12+
"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)",
1213
"config.codeViewerHelperPrompt.description": "Code viewer helper prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
1314
"config.convertLanguagePairs.description": "Default convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/convert-language-pairs)",
1415
"config.autoRememberConvertLanguagePairs.description": "Automatically remember convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/auto-remember-convert-language-pairs)",
1516
"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)",
16-
"config.aiPrompt.description": "Template for copied content, use #{content} as a placeholder for file content, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-prompt)",
17-
"config.ignorePatterns.description": "Ignored file name patterns, supports glob syntax, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ignore-patterns)",
18-
"config.respectGitIgnore.description": "Respect .gitignore file, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/respect-git-ignore)",
19-
"config.aiCommand.description": "Custom AI command template. Available variables: #{filesRelativePath}, #{filesFullPath}, #{content}, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command)",
20-
"config.aiCommandCopyBeforeRun.description": "Copy AI command to clipboard before running, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command-copy-before-run)",
17+
"config.aiPrompt.description": "Template for copied content, use `#{content}` as a placeholder for file content, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-prompt)",
18+
"config.ignorePatterns.description": "Ignored file name patterns, supports `glob` syntax, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ignore-patterns)",
19+
"config.respectGitIgnore.description": "Respect `.gitignore` file, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/respect-git-ignore)",
20+
"config.aiCommand.description": "Custom `✨ Aide: Ask AI` command template. Available variables:` #{filesRelativePath}`, `#{filesFullPath}`, `#{content}`, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command)",
21+
"config.aiCommandCopyBeforeRun.description": "Copy AI command to clipboard before `✨ Aide: Ask AI` running, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command-copy-before-run)",
22+
"config.aiCommandAutoRun.description": "Automatically run AI command when clicking `✨ Aide: Ask AI`, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command-auto-run)",
2123
"error.noWorkspace": "Unable to determine workspace folder",
2224
"error.invalidConfigKey": "Invalid configuration key",
2325
"error.invalidConfigValueType": "Invalid configuration value type",
@@ -43,6 +45,7 @@
4345
"info.iconContinueMessage": "(You can also click the original generate icon to continue)",
4446
"info.continue": "Continue",
4547
"info.cancel": "Cancel",
48+
"info.commandCopiedToClipboard": "AI command has been copied to clipboard",
4649
"input.array.promptEnding": "Enter comma separated values",
4750
"input.json.promptEnding": "Enter JSON formatted value",
4851
"input.aiCommand.prompt": "Enter question for AI command",

package.nls.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-key)",
1010
"config.openaiModel.description": "OpenAI Model, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-model)",
1111
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
12+
"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)",
1213
"config.codeViewerHelperPrompt.description": "Code viewer helper prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
1314
"config.convertLanguagePairs.description": "Default convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/convert-language-pairs)",
1415
"config.autoRememberConvertLanguagePairs.description": "Automatically remember convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/auto-remember-convert-language-pairs)",
1516
"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)",
16-
"config.aiPrompt.description": "Template for copied content, use #{content} as a placeholder for file content, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-prompt)",
17-
"config.ignorePatterns.description": "Ignored file name patterns, supports glob syntax, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ignore-patterns)",
18-
"config.respectGitIgnore.description": "Respect .gitignore file, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/respect-git-ignore)",
19-
"config.aiCommand.description": "Custom AI command template. Available variables: #{filesRelativePath}, #{filesFullPath}, #{content}, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command)",
20-
"config.aiCommandCopyBeforeRun.description": "Copy AI command to clipboard before running, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command-copy-before-run)",
17+
"config.aiPrompt.description": "Template for copied content, use `#{content}` as a placeholder for file content, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-prompt)",
18+
"config.ignorePatterns.description": "Ignored file name patterns, supports `glob` syntax, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ignore-patterns)",
19+
"config.respectGitIgnore.description": "Respect `.gitignore` file, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/respect-git-ignore)",
20+
"config.aiCommand.description": "Custom `✨ Aide: Ask AI` command template. Available variables:` #{filesRelativePath}`, `#{filesFullPath}`, `#{content}`, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command)",
21+
"config.aiCommandCopyBeforeRun.description": "Copy AI command to clipboard before `✨ Aide: Ask AI` running, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command-copy-before-run)",
22+
"config.aiCommandAutoRun.description": "Automatically run AI command when clicking `✨ Aide: Ask AI`, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/ai-command-auto-run)",
2123
"error.noWorkspace": "Unable to determine workspace folder",
2224
"error.invalidConfigKey": "Invalid configuration key",
2325
"error.invalidConfigValueType": "Invalid configuration value type",
@@ -43,6 +45,7 @@
4345
"info.iconContinueMessage": "(You can also click the original generate icon to continue)",
4446
"info.continue": "Continue",
4547
"info.cancel": "Cancel",
48+
"info.commandCopiedToClipboard": "AI command has been copied to clipboard",
4649
"input.array.promptEnding": "Enter comma separated values",
4750
"input.json.promptEnding": "Enter JSON formatted value",
4851
"input.aiCommand.prompt": "Enter question for AI command",

package.nls.zh-cn.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
"config.openaiKey.description": "OpenAI Key, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-key)",
1010
"config.openaiModel.description": "OpenAI Model, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-model)",
1111
"config.openaiBaseUrl.description": "OpenAI Base URL, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-base-url)",
12+
"config.useSystemProxy.description": "是否使用全局代理 (`HTTP_PROXY`、`HTTPS_PROXY`、`ALL_PROXY`) , 更改此设置后需要重启 `VSCode` 才生效, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/use-system-proxy)",
1213
"config.codeViewerHelperPrompt.description": "代码查看器助手 prompt 模板, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/code-viewer-helper-prompt)",
1314
"config.convertLanguagePairs.description": "默认转换语言对照表, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/convert-language-pairs)",
1415
"config.autoRememberConvertLanguagePairs.description": "是否自动记住转换语言对照表, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/auto-remember-convert-language-pairs)",
1516
"config.readClipboardImage.description": "是否允许某些场景读取剪贴板图片作为 AI 上下文, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/read-clipboard-image)",
16-
"config.aiPrompt.description": "复制内容的模板,使用#{content}作为文件内容的占位符, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ai-prompt)",
17-
"config.ignorePatterns.description": "忽略的文件名模式, 支持 glob 语法, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ignore-patterns)",
18-
"config.respectGitIgnore.description": "是否尊重 .gitignore 文件, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/respect-git-ignore)",
19-
"config.aiCommand.description": "自定义 AI 命令模板。可用变量:#{filesRelativePath}, #{filesFullPath}, #{content}, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ai-command)",
20-
"config.aiCommandCopyBeforeRun.description": "运行前将 AI 命令复制到剪贴板, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ai-command-copy-before-run)",
17+
"config.aiPrompt.description": "复制内容的模板,使用 `#{content}` 作为文件内容的占位符, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ai-prompt)",
18+
"config.ignorePatterns.description": "忽略的文件名模式, 支持 `glob` 语法, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ignore-patterns)",
19+
"config.respectGitIgnore.description": "是否尊重 `.gitignore` 文件, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/respect-git-ignore)",
20+
"config.aiCommand.description": "自定义 `✨ Aide: 问 AI` 命令模板。可用变量:`#{filesRelativePath}`、`#{filesFullPath}`、 `#{content}`, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ai-command)",
21+
"config.aiCommandCopyBeforeRun.description": "运行 `✨ Aide: 问 AI` 前将 AI 命令复制到剪贴板, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ai-command-copy-before-run)",
22+
"config.aiCommandAutoRun.description": "点击 `✨ Aide: 问 AI` 时自动运行 AI 命令, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/ai-command-auto-run)",
2123
"error.noWorkspace": "无法确定工作区文件夹",
2224
"error.invalidConfigKey": "无效的配置键",
2325
"error.invalidConfigValueType": "无效的配置值类型",
@@ -43,6 +45,7 @@
4345
"info.iconContinueMessage": "(你也可以点击原来的生成 icon 以继续)",
4446
"info.continue": "继续",
4547
"info.cancel": "取消",
48+
"info.commandCopiedToClipboard": "AI 命令已复制到剪贴板",
4649
"input.array.promptEnding": "输入逗号分隔的值",
4750
"input.json.promptEnding": "输入 JSON 格式的值",
4851
"input.aiCommand.prompt": "输入 AI 命令的问题",

src/ai/get-reference-file-paths.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export const getReferenceFilePaths = async ({
3333
const aiRunnable = await modelProvider.createStructuredOutputRunnable({
3434
useHistory: false,
3535
zodSchema: z.object({
36-
referenceFileRelativePaths: z.array(z.string()).length(3).describe(`
37-
The relative paths of the three most useful files related to the currently edited file.
38-
`),
36+
referenceFileRelativePaths: z.array(z.string()).min(0).max(3).describe(`
37+
The relative paths of the up to three most useful files related to the currently edited file. This can include 0 to 3 files.
38+
`),
3939
dependenceFileRelativePath: z.string().describe(`
4040
The relative path of the dependency file for the current file. If the dependency file is not found, return an empty string.
4141
`)

src/commands/ask-ai.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const handleAskAI = async (
4545

4646
const aiCommand = await getConfigKey('aiCommand')
4747
const aiCommandCopyBeforeRun = await getConfigKey('aiCommandCopyBeforeRun')
48+
const aiCommandAutoRun = await getConfigKey('aiCommandAutoRun')
4849
let userInput = ''
4950

5051
if (aiCommand.includes('#{question}')) {
@@ -63,7 +64,16 @@ export const handleAskAI = async (
6364

6465
if (aiCommandCopyBeforeRun) {
6566
await vscode.env.clipboard.writeText(finalCommand)
67+
68+
// Show info message only if the command is not set to auto-run
69+
if (!aiCommandAutoRun) {
70+
await vscode.window.showInformationMessage(
71+
t('info.commandCopiedToClipboard')
72+
)
73+
}
6674
}
6775

68-
await executeCommand(finalCommand, workspaceFolder.uri.fsPath)
76+
if (aiCommandAutoRun) {
77+
await executeCommand(finalCommand, workspaceFolder.uri.fsPath)
78+
}
6979
}

src/commands/code-convert.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import {
33
getCurrentSessionIdHistoriesMap
44
} from '@/ai/helpers'
55
import { getConfigKey, setConfigKey } from '@/config'
6-
import { languageIds } from '@/constants'
6+
import { languageIdExts, languageIds } from '@/constants'
77
import { createTmpFileInfo } from '@/file-utils/create-tmp-file'
88
import { showContinueMessage } from '@/file-utils/show-continue-message'
99
import { tmpFileWriter } from '@/file-utils/tmp-file-writer'
1010
import { t } from '@/i18n'
11+
import { getLanguageId } from '@/utils'
1112
import type { BaseLanguageModelInput } from '@langchain/core/language_models/base'
1213
import type { RunnableConfig } from '@langchain/core/runnables'
1314
import * as vscode from 'vscode'
@@ -61,7 +62,7 @@ const getTargetLanguageInfo = async (originalFileLanguageId: string) => {
6162
if (!targetLanguageInfo) {
6263
targetLanguageInfo =
6364
(await vscode.window.showQuickPick(
64-
[customLanguageOption, ...languageIds],
65+
[customLanguageOption, ...languageIds, ...languageIdExts],
6566
{
6667
placeHolder: t('input.codeConvertTargetLanguage.prompt'),
6768
canPickMany: false
@@ -98,9 +99,10 @@ const getTargetLanguageInfo = async (originalFileLanguageId: string) => {
9899
}
99100
}
100101

101-
const [targetLanguageId, ...targetLanguageRest] =
102+
const [targetLanguageIdOrExt, ...targetLanguageRest] =
102103
targetLanguageInfo.split(/\s+/)
103104
const targetLanguageDescription = targetLanguageRest.join(' ')
105+
const targetLanguageId = getLanguageId(targetLanguageIdOrExt || 'plaintext')
104106

105107
return {
106108
targetLanguageId: targetLanguageId || targetLanguageInfo,

src/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ const configKey = {
5959
...pkgConfig['aide.aiCommandCopyBeforeRun'],
6060
type: 'boolean'
6161
},
62+
aiCommandAutoRun: {
63+
...pkgConfig['aide.aiCommandAutoRun'],
64+
type: 'boolean'
65+
},
6266
autoRememberConvertLanguagePairs: {
6367
...pkgConfig['aide.autoRememberConvertLanguagePairs'],
6468
type: 'boolean'
@@ -76,6 +80,10 @@ const configKey = {
7680
...pkgConfig['aide.codeViewerHelperPrompt'],
7781
type: 'string'
7882
},
83+
useSystemProxy: {
84+
...pkgConfig['aide.useSystemProxy'],
85+
type: 'boolean'
86+
},
7987
openaiKey: {
8088
...pkgConfig['aide.openaiKey'],
8189
type: 'string'

src/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ export const languageIdExtMap = {
7272
}
7373

7474
export const languageIds = Object.keys(languageIdExtMap)
75+
export const languageIdExts = Object.values(languageIdExtMap).flat()
76+
export const languageExtIdMap = Object.fromEntries(
77+
Object.entries(languageIdExtMap).flatMap(([id, exts]) =>
78+
exts.map(ext => [ext, id])
79+
)
80+
)

src/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { t } from './i18n'
44

55
let globalContext: vscode.ExtensionContext | undefined
66

7-
export function setContext(context: vscode.ExtensionContext) {
7+
export const setContext = (context: vscode.ExtensionContext) => {
88
globalContext = context
99
}
1010

11-
export function getContext(): vscode.ExtensionContext {
11+
export const getContext = (): vscode.ExtensionContext => {
1212
if (!globalContext) {
1313
throw new Error(t('error.noContext'))
1414
}

0 commit comments

Comments
 (0)