|
399 | 399 | <DebugPanel/> |
400 | 400 |
|
401 | 401 | <!-- AI 代码操作(解释/重构/生成测试) --> |
402 | | - <AiCodeAction v-if="aiCodeCtx" :language="currentLanguage" :code="aiCodeCtx.code" :action="aiCodeCtx.action" |
| 402 | + <AiCodeAction v-if="aiCodeCtx" :language="currentLanguage" :code="aiCodeCtx.code" :action="aiCodeCtx.action" :diagnostics="aiCodeCtx.diagnostics" |
403 | 403 | @replace="onAiReplace" @insert="onAiInsert" @close="aiCodeCtx = null"/> |
404 | 404 |
|
405 | 405 | <!-- .gitignore 模板 --> |
|
463 | 463 | <button class="w-full text-left px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer" @click="aiCodeAction('explain')">{{ t('aiCode.title.explain') }}</button> |
464 | 464 | <button class="w-full text-left px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer" @click="aiCodeAction('refactor')">{{ t('aiCode.title.refactor') }}</button> |
465 | 465 | <button class="w-full text-left px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer" @click="aiCodeAction('test')">{{ t('aiCode.title.test') }}</button> |
| 466 | + <button v-if="canBlame || editorCtx.lsp" class="w-full text-left px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer" @click="aiFixDiagnostics">{{ t('aiCode.title.fix') }}</button> |
466 | 467 | <div class="border-t border-gray-100 dark:border-gray-700 my-1"></div> |
467 | 468 | <button class="w-full text-left px-3 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer" @click="sendToTerminal"> |
468 | 469 | {{ t('app.sendToTerminal') }} |
@@ -543,6 +544,7 @@ import {useWorkspace} from './composables/useWorkspace' |
543 | 544 | import {useTextCommands} from './composables/useTextCommands' |
544 | 545 | import {useBookmarks} from './composables/useBookmarks' |
545 | 546 | import {foldAll, unfoldAll, matchBrackets} from '@codemirror/language' |
| 547 | +import {diagnostics} from './editor/lspDiagnostics' |
546 | 548 | import {useGitPermalink} from './composables/useGitPermalink' |
547 | 549 | import {useRevealInTree} from './composables/useRevealInTree' |
548 | 550 | import {useWorkspaceRoots} from './composables/useWorkspaceRoots' |
@@ -1420,7 +1422,21 @@ const runTests = async () => { |
1420 | 1422 | } |
1421 | 1423 |
|
1422 | 1424 | // C2:对选区(无选区则整篇)执行 AI 操作:解释 / 重构 / 生成测试 |
1423 | | -const aiCodeCtx = ref<{action: 'explain' | 'refactor' | 'test'; code: string; from: number; to: number} | null>(null) |
| 1425 | +const aiCodeCtx = ref<{action: 'explain' | 'refactor' | 'test' | 'fix'; code: string; from: number; to: number; diagnostics?: string} | null>(null) |
| 1426 | +// AI 修复诊断:把当前文件的 LSP 诊断交给 AI 修复整篇 |
| 1427 | +const aiFixDiagnostics = () => { |
| 1428 | + closeEditorCtx() |
| 1429 | + const view = editorView.value |
| 1430 | + if (!view) { |
| 1431 | + return |
| 1432 | + } |
| 1433 | + if (!diagnostics.value.length) { |
| 1434 | + toast.info(t('app.noDiagnostics')) |
| 1435 | + return |
| 1436 | + } |
| 1437 | + const diagText = diagnostics.value.map(d => `[${d.severity}] L${d.line}:${d.col} ${d.message}`).join('\n') |
| 1438 | + aiCodeCtx.value = {action: 'fix', code: view.state.doc.toString(), from: 0, to: view.state.doc.length, diagnostics: diagText} |
| 1439 | +} |
1424 | 1440 | const aiCodeAction = (action: 'explain' | 'refactor' | 'test') => { |
1425 | 1441 | closeEditorCtx() |
1426 | 1442 | const view = editorView.value |
@@ -2228,6 +2244,7 @@ const paletteCommands = computed<PaletteCommand[]>(() => [ |
2228 | 2244 | {id: 'explainCode', label: t('command.explainCode'), icon: Sparkles, run: () => explainCode()}, |
2229 | 2245 | {id: 'generateTests', label: t('command.generateTests'), icon: Sparkles, run: () => generateTests()}, |
2230 | 2246 | {id: 'formatWithAi', label: t('command.formatWithAi'), icon: Sparkles, run: () => formatWithAi()}, |
| 2247 | + {id: 'aiFixDiagnostics', label: t('command.aiFixDiagnostics'), icon: Sparkles, run: () => aiFixDiagnostics()}, |
2231 | 2248 | {id: 'history', label: t('command.history'), icon: History, run: () => { showHistory.value = true }}, |
2232 | 2249 | {id: 'diff', label: t('command.diff'), icon: GitCompare, run: () => openDiff()}, |
2233 | 2250 | {id: 'compareClipboard', label: t('command.compareClipboard'), icon: GitCompare, run: () => compareWithClipboard()}, |
|
0 commit comments