Skip to content

Commit 89eded7

Browse files
committed
feat(ai-code-assistant): Simplify suggestion preview workflow
1 parent 2425027 commit 89eded7

3 files changed

Lines changed: 26 additions & 46 deletions

File tree

packages/plugins/script/src/ai-code-assistant/core/NESEngine.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class NESEngine {
2121
private abortController: AbortController | null = null
2222
private onEditApplied?: (lineNumber: number) => void
2323

24-
constructor(private editor: monaco.editor.IStandaloneCodeEditor, private config: NESConfig) {
24+
constructor(private editor: monaco.editor.IStandaloneCodeEditor, _config: NESConfig) {
2525
this.symptomDetector = new SymptomDetector()
2626
this.suggestionQueue = new SuggestionQueue()
2727
this.renderer = new NESRenderer(editor)
@@ -120,7 +120,7 @@ export class NESEngine {
120120
}
121121

122122
/**
123-
* 显示第一个建议(只显示 Glyph,不展开预览
123+
* 显示第一个建议(直接显示预览
124124
*/
125125
private showFirstSuggestion(): void {
126126
const prediction = this.suggestionQueue.peek()
@@ -130,44 +130,19 @@ export class NESEngine {
130130
const total = this.suggestionQueue.size()
131131
const progress = total > 1 ? `${current}/${total}` : undefined
132132

133-
// 只显示 Glyph 和 HintBar,不展开预览
133+
// 直接显示预览(优化:不需要两次 Tab)
134134
this.renderer.renderSuggestion(prediction)
135-
this.renderer.showHintBar(prediction.targetLine, prediction.explanation, false, progress)
136-
137-
// 设置预览状态为未展开
138-
this.previewShown = false
139-
}
140-
}
141-
142-
/**
143-
* 切换到预览模式(Tab 键触发)
144-
*/
145-
public togglePreview(): void {
146-
const prediction = this.suggestionQueue.peek()
147-
if (!prediction) {
148-
return
149-
}
135+
this.renderer.showPreview(prediction)
136+
this.renderer.showHintBar(prediction.targetLine, prediction.explanation, true, progress)
150137

151-
if (!this.previewShown) {
152138
// 跳转到建议位置
153139
this.editor.setPosition({
154140
lineNumber: prediction.targetLine,
155141
column: 1
156142
})
157143
this.editor.revealLineInCenter(prediction.targetLine)
158144

159-
// 展开预览
160-
this.renderer.showPreview(prediction)
161-
162-
// 计算进度
163-
const current = this.suggestionQueue.getCurrentIndex() + 1
164-
const total = this.suggestionQueue.size()
165-
const progress = total > 1 ? `${current}/${total}` : undefined
166-
167-
// 更新 HintBar 提示(显示 "Tab Accept")
168-
this.renderer.showHintBar(prediction.targetLine, prediction.explanation, true, progress)
169-
170-
// 更新状态
145+
// 设置预览状态为已展开
171146
this.previewShown = true
172147
}
173148
}
@@ -230,16 +205,28 @@ export class NESEngine {
230205
// 只清除渲染,不移除队列
231206
this.renderer.clear()
232207

233-
// 如果还有建议,重新显示(只显示 Glyph 和 HintBar
208+
// 如果还有建议,重新显示(直接显示预览
234209
const prediction = this.suggestionQueue.peek()
235210
if (prediction) {
236211
// 计算进度
237212
const current = this.suggestionQueue.getCurrentIndex() + 1
238213
const total = this.suggestionQueue.size()
239214
const progress = total > 1 ? `${current}/${total}` : undefined
240215

216+
// 直接显示预览
241217
this.renderer.renderSuggestion(prediction)
242-
this.renderer.showHintBar(prediction.targetLine, prediction.explanation, false, progress)
218+
this.renderer.showPreview(prediction)
219+
this.renderer.showHintBar(prediction.targetLine, prediction.explanation, true, progress)
220+
221+
// 跳转到建议位置
222+
this.editor.setPosition({
223+
lineNumber: prediction.targetLine,
224+
column: 1
225+
})
226+
this.editor.revealLineInCenter(prediction.targetLine)
227+
228+
// 设置预览状态
229+
this.previewShown = true
243230
}
244231
}
245232

packages/plugins/script/src/ai-code-assistant/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,16 @@ export function initAICodeAssistant(
143143

144144
// 注册快捷键(只注册 NES 相关的)
145145
if (nesEngine) {
146-
// Tab - 智能行为:
147-
// - 预览未展开 → 跳转并展开预览
148-
// - 预览已展开 → 接受建议
149-
// - NES 未激活 → 让 Monaco 处理(FIM)
146+
// Tab - 接受当前建议(预览已默认显示)
147+
// - 单个建议:接受并关闭 NES
148+
// - 多个建议:接受当前,显示下一个预览
150149
editor.onKeyDown((e) => {
151150
if (e.keyCode === monaco.KeyCode.Tab && nesEngine!.isActive()) {
152151
e.preventDefault()
153152
e.stopPropagation()
154153

155-
// 检查预览是否已展开
156-
if (nesEngine!.isPreviewShown()) {
157-
// 预览已展开 → 接受建议
158-
nesEngine!.acceptSuggestion()
159-
} else {
160-
// 预览未展开 → 展开预览
161-
nesEngine!.togglePreview()
162-
}
154+
// 直接接受建议(预览已默认显示)
155+
nesEngine!.acceptSuggestion()
163156
}
164157
})
165158

packages/plugins/script/src/ai-code-assistant/ui/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* ==================== Glyph 箭头图标 ==================== */
77

88
.nes-glyph-arrow-enhanced {
9-
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23667eea"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z"/></svg>') no-repeat center center;
9+
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23667eea" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>') no-repeat center center;
1010
background-size: 18px 18px;
1111
cursor: pointer;
1212
opacity: 0.9;

0 commit comments

Comments
 (0)