fix: auto-restore last session on VS Code reopen#128
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the chat webview startup flow so that when VS Code is reopened and there is no active sessionId, the extension automatically restores the most recent unarchived chat session instead of showing an empty welcome state (closes #126).
Changes:
- On webview
ready, attempt to find and load the most recent unarchived session when no session is active. - Fall back to posting an empty
sessionLoadedpayload when no sessions exist or restore fails.
结论:需修改(1) 避免 ready 流程中重复发送 sessions 列表导致潜在 UI 闪烁/冗余开销)
Comment on lines
+205
to
+211
| this._store.postList(); | ||
| if (!this._store.sessionId) this._post({ type: 'sessionLoaded', id: null, messages: [] }); | ||
| if (!this._store.sessionId) { | ||
| try { | ||
| const all = this._store.all(); | ||
| const last = all.length ? all.find(s => !s.archived) : null; | ||
| if (last) await this._store.load(last.id); | ||
| else this._post({ type: 'sessionLoaded', id: null, messages: [] }); |
Comment on lines
+209
to
+210
| const last = all.length ? all.find(s => !s.archived) : null; | ||
| if (last) await this._store.load(last.id); |
| if (!this._store.sessionId) { | ||
| try { | ||
| const all = this._store.all(); | ||
| const last = all.length ? all.find(s => !s.archived) : null; |
| if (!this._store.sessionId) { | ||
| try { | ||
| const all = this._store.all(); | ||
| const last = all.length ? all.find(s => !s.archived) : null; |
Comment on lines
+209
to
+210
| const last = all.length ? all.find(s => !s.archived) : null; | ||
| if (last) await this._store.load(last.id); |
| const last = all.length ? all.find(s => !s.archived) : null; | ||
| if (last) await this._store.load(last.id); | ||
| else this._post({ type: 'sessionLoaded', id: null, messages: [] }); | ||
| } catch { |
Comment on lines
+205
to
+210
| this._store.postList(); | ||
| if (!this._store.sessionId) this._post({ type: 'sessionLoaded', id: null, messages: [] }); | ||
| if (!this._store.sessionId) { | ||
| try { | ||
| const all = this._store.all(); | ||
| const last = all.length ? all.find(s => !s.archived) : null; | ||
| if (last) await this._store.load(last.id); |
- Move postList() out of the unconditional call site; when a session is auto-restored, load() already calls postList() internally, so calling it upfront caused two back-to-back 'sessions' messages (activeId null then the restored id), leading to potential UI flicker. - Rename variable 'last' to 'latest' for clearer semantics (find returns the first unarchived item in the time-sorted list, not the last element). - Add postList() to the catch fallback so the sidebar is always populated even when auto-restore fails. Addresses Copilot review comments (medium + low) on PR #128.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明 / Summary
重新打开 VS Code 后,插件不再显示空白欢迎页,而是自动加载最近一次的会话,让用户直接继续对话,无需手动打开历史记录列表再点击恢复。
修改位置:src/chat/provider.js 的 ready 事件处理 — 当 sessionId 为空时,优先加载最近一条未归档的会话,若无历史记录才显示欢迎页。
变更类型 / Type of change
影响范围 / Affected areas
src/api/**(DeepSeek 接入)src/chat/**(对话核心)src/tools/**(工具执行,安全敏感)src/webview/**(UI)src/prompts/**package.json/ 依赖.github/**自检 / Checklist
截图 / 录屏(可选)
关联 Issue
Closes #126