feat: 补全文档中文翻译(LLM,OpenAI 兼容接口)
补全列表底部的英文 godoc 翻译成中文: - internal/ai: OpenAI 兼容最小客户端 + TranslateDoc(保留代码标识符) - app 层 docTranslation: 内存+磁盘缓存、inflight 去重、失败哨兵防重复请求 - 自定义补全面板渲染(RenderCompletions 钩子),文档区异步换译文, 不重送候选列表、不打断选择状态 - 设置新增「文档翻译」:开关 + 接口地址/API Key/模型 三件套, 兼容 DeepSeek/GLM/Ollama/OpenAI 等,没配齐时静默关闭
This commit is contained in:
1 parent
83abecd607
commit
f401c3de85
7 files changed
+467
No files matched your search
@@ -27,6 +27,13 @@ type settings struct {
|
||||
// InlayHints 控制参数名/类型这类内联提示。
|
||||
// 老配置文件里没有这一项,读的时候要按「默认开」处理(见 loadSettings)。
|
||||
InlayHints bool `json:"inlayHints"`
|
||||
// TranslateDocs 开关补全文档的中文翻译(需配好下面的 AI 接口)。
|
||||
TranslateDocs bool `json:"translateDocs"`
|
||||
// AI 接口三件套:OpenAI 兼容的地址、Key 与模型名,
|
||||
// 如 https://api.deepseek.com/v1 + sk-xxx + deepseek-chat。
|
||||
AIBaseURL string `json:"aiBaseUrl"`
|
||||
AIAPIKey string `json:"aiApiKey"`
|
||||
AIModel string `json:"aiModel"`
|
||||
}
|
||||
|
||||
// defaultSettings 是没配置过时的取值,和改动前的硬编码保持一致。
|
||||
@@ -43,6 +50,7 @@ func defaultSettings() settings {
|
||||
History: true,
|
||||
AutoSnapshot: true,
|
||||
InlayHints: true,
|
||||
TranslateDocs: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +189,24 @@ func (a *App) settingsDialog(c *ui.Context) {
|
||||
}
|
||||
})
|
||||
|
||||
// AI 文档翻译:补全列表底部的英文 godoc 译成中文。
|
||||
row("文档翻译", func() {
|
||||
ui.Checkbox(c, &a.setDlg.TranslateDocs, "补全文档翻译成中文(OpenAI 兼容接口)")
|
||||
})
|
||||
if a.setDlg.TranslateDocs {
|
||||
row("接口地址", func() {
|
||||
ui.TextInput(c, &a.setDlg.AIBaseURL).FillWidth().FontSize(12)
|
||||
})
|
||||
row("API Key", func() {
|
||||
ui.TextInput(c, &a.setDlg.AIAPIKey).FillWidth().FontSize(12)
|
||||
})
|
||||
row("模型", func() {
|
||||
ui.TextInput(c, &a.setDlg.AIModel).FillWidth().FontSize(12)
|
||||
})
|
||||
ui.Text(c, "示例:https://api.deepseek.com/v1 + deepseek-chat,或本地 Ollama http://localhost:11434/v1。").
|
||||
FontSize(10).TextColor(t.TextMuted).SingleLine()
|
||||
}
|
||||
|
||||
ui.Row(c).Gap(8).Justify(ui.End).Children(func() {
|
||||
if ui.Button(c, "恢复默认").Clicked() {
|
||||
a.setDlg = defaultSettings()
|
||||
|
||||
Reference in new issue
Block a user