Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: auto-restore last session on VS Code reopen#128

Merged
ZhouChaunge merged 5 commits into
mainfrom
feat/auto-restore-session
May 23, 2026
Merged

fix: auto-restore last session on VS Code reopen#128
ZhouChaunge merged 5 commits into
mainfrom
feat/auto-restore-session

Conversation

@YSMsimon

Copy link
Copy Markdown
Collaborator

变更说明 / Summary

重新打开 VS Code 后,插件不再显示空白欢迎页,而是自动加载最近一次的会话,让用户直接继续对话,无需手动打开历史记录列表再点击恢复。
修改位置:src/chat/provider.js 的 ready 事件处理 — 当 sessionId 为空时,优先加载最近一条未归档的会话,若无历史记录才显示欢迎页。

变更类型 / Type of change

  • Bug 修复
  • [x ] 新功能
  • 重构 / 性能优化
  • 文档 / 注释
  • CI / 构建脚本
  • 其他:

影响范围 / Affected areas

  • src/api/**(DeepSeek 接入)
  • [x ] src/chat/**(对话核心)
  • src/tools/**(工具执行,安全敏感)
  • src/webview/**(UI)
  • src/prompts/**
  • package.json / 依赖
  • CI / .github/**
  • 其他:

自检 / Checklist

  • [x ] 本地手动跑过受影响功能
  • [x ] 没有引入新的安全风险(密钥、命令注入、路径穿越)
  • [x ] 没有写入个人 / 测试用 API key
  • [x ] 修改的 webview 资源遵守了 CSP
  • 必要时已更新 README / Release Notes

截图 / 录屏(可选)

关联 Issue

Closes #126

@YSMsimon YSMsimon requested a review from ZhouChaunge as a code owner May 21, 2026 22:59
@YSMsimon YSMsimon self-assigned this May 21, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review by ChatGPT

Comment thread src/chat/provider.js

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review by ChatGPT

Comment thread src/chat/provider.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sessionLoaded payload when no sessions exist or restore fails.

结论:需修改(1) 避免 ready 流程中重复发送 sessions 列表导致潜在 UI 闪烁/冗余开销)

Comment thread src/chat/provider.js Outdated
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 thread src/chat/provider.js Outdated
Comment on lines +209 to +210
const last = all.length ? all.find(s => !s.archived) : null;
if (last) await this._store.load(last.id);

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

Comment thread src/chat/provider.js Outdated
if (!this._store.sessionId) {
try {
const all = this._store.all();
const last = all.length ? all.find(s => !s.archived) : null;
Comment thread src/chat/provider.js Outdated
if (!this._store.sessionId) {
try {
const all = this._store.all();
const last = all.length ? all.find(s => !s.archived) : null;
Comment thread src/chat/provider.js Outdated
Comment on lines +209 to +210
const last = all.length ? all.find(s => !s.archived) : null;
if (last) await this._store.load(last.id);
Comment thread src/chat/provider.js
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 thread src/chat/provider.js Outdated
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);
ZhouChaunge and others added 2 commits May 23, 2026 22:40
- 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.
@ZhouChaunge ZhouChaunge merged commit d1b68dc into main May 23, 2026
17 checks passed
@ZhouChaunge ZhouChaunge deleted the feat/auto-restore-session branch May 23, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UX: 关闭 VS Code 重新打开后不自动恢复上次会话

3 participants