Skip to content

Commit 25461de

Browse files
committed
Ensure checkpoints correctly save and restore the list of active VS Code editor tabs
1 parent 10a17f2 commit 25461de

5 files changed

Lines changed: 66 additions & 21 deletions

File tree

‎packages/vscode/src/commands/checkpoints-command/actions/create-checkpoint.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY
66
} from '../../../constants/state-keys'
77
import { WorkspaceProvider } from '../../../context/providers/workspace-provider'
8-
import type { Checkpoint } from '../types'
8+
import type { Checkpoint, CheckpointTab } from '../types'
99
import { get_checkpoints } from './get-checkpoints'
1010
import {
1111
copy_optimised_recursively,
@@ -218,6 +218,21 @@ export const create_checkpoint = async (
218218
checkpoints
219219
)
220220

221+
const active_tabs: CheckpointTab[] = []
222+
const tab_groups = vscode.window.tabGroups.all
223+
for (const group of tab_groups) {
224+
for (const tab of group.tabs) {
225+
if (tab.input instanceof vscode.TabInputText) {
226+
active_tabs.push({
227+
uri: (tab.input as vscode.TabInputText).uri.toString(),
228+
view_column: group.viewColumn,
229+
is_active: tab.isActive,
230+
is_group_active: group.isActive
231+
})
232+
}
233+
}
234+
}
235+
221236
const checkpoint_object: Checkpoint = {
222237
title,
223238
timestamp,
@@ -227,7 +242,8 @@ export const create_checkpoint = async (
227242
checked_files: workspace_provider.get_all_checked_paths(),
228243
checked_websites: websites_provider
229244
.get_checked_websites()
230-
.map((w) => w.url)
245+
.map((w) => w.url),
246+
active_tabs
231247
}
232248

233249
checkpoints.unshift(checkpoint_object)

‎packages/vscode/src/commands/checkpoints-command/actions/create-temporary-checkpoint.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { WorkspaceProvider } from '../../../context/providers/workspace-provider'
3-
import type { Checkpoint } from '../types'
3+
import type { Checkpoint, CheckpointTab } from '../types'
44
import { copy_optimised_recursively, get_checkpoint_path } from '../utils'
55
import {
66
get_git_diff,
@@ -95,6 +95,21 @@ export const create_temporary_checkpoint = async (
9595
}
9696
}
9797

98+
const active_tabs: CheckpointTab[] = []
99+
const tab_groups = vscode.window.tabGroups.all
100+
for (const group of tab_groups) {
101+
for (const tab of group.tabs) {
102+
if (tab.input instanceof vscode.TabInputText) {
103+
active_tabs.push({
104+
uri: (tab.input as vscode.TabInputText).uri.toString(),
105+
view_column: group.viewColumn,
106+
is_active: tab.isActive,
107+
is_group_active: group.isActive
108+
})
109+
}
110+
}
111+
}
112+
98113
const new_checkpoint: Checkpoint = {
99114
timestamp,
100115
title: '',
@@ -104,7 +119,8 @@ export const create_temporary_checkpoint = async (
104119
checked_files: workspace_provider.get_all_checked_paths(),
105120
checked_websites: websites_provider
106121
.get_checked_websites()
107-
.map((w) => w.url)
122+
.map((w) => w.url),
123+
active_tabs
108124
}
109125
return new_checkpoint
110126
}

‎packages/vscode/src/commands/checkpoints-command/actions/restore-checkpoint.ts‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,40 @@ export const restore_checkpoint = async (params: {
3434
const operation_in_progress = params.context.workspaceState.get<number>(
3535
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY
3636
)
37-
if (
38-
operation_in_progress &&
39-
Date.now() - operation_in_progress < 60 * 1000
40-
) {
37+
if (operation_in_progress && Date.now() - operation_in_progress < 60 * 1000) {
4138
vscode.window.showWarningMessage(
4239
dictionary.warning_message.CHECKPOINT_OPERATION_IN_PROGRESS
4340
)
4441
return
4542
}
4643

47-
const tab_groups = vscode.window.tabGroups.all
48-
const open_files: {
44+
let open_files: {
4945
uri: vscode.Uri
5046
viewColumn: vscode.ViewColumn
5147
isActive: boolean
5248
}[] = []
53-
for (const group of tab_groups) {
54-
for (const tab of group.tabs) {
55-
if (tab.input instanceof vscode.TabInputText) {
56-
open_files.push({
57-
uri: (tab.input as vscode.TabInputText).uri,
58-
viewColumn: group.viewColumn,
59-
isActive: tab.isActive && group.isActive
60-
})
49+
50+
if (params.checkpoint.active_tabs) {
51+
open_files = params.checkpoint.active_tabs.map((tab) => ({
52+
uri: vscode.Uri.parse(tab.uri),
53+
viewColumn: tab.view_column as vscode.ViewColumn,
54+
isActive: tab.is_active && tab.is_group_active
55+
}))
56+
} else {
57+
const tab_groups = vscode.window.tabGroups.all
58+
for (const group of tab_groups) {
59+
for (const tab of group.tabs) {
60+
if (tab.input instanceof vscode.TabInputText) {
61+
open_files.push({
62+
uri: (tab.input as vscode.TabInputText).uri,
63+
viewColumn: group.viewColumn,
64+
isActive: tab.isActive && group.isActive
65+
})
66+
}
6167
}
6268
}
6369
}
70+
6471
let temp_checkpoint: Checkpoint | undefined
6572
try {
6673
if (response_preview_promise_resolve) {
@@ -81,7 +88,7 @@ export const restore_checkpoint = async (params: {
8188
params.context,
8289
params.panel_provider,
8390
params.websites_provider,
84-
'Before checkpoint restored',
91+
'Before checkpoint restored'
8592
)
8693
}
8794

@@ -429,4 +436,3 @@ export const restore_checkpoint = async (params: {
429436
}
430437
}
431438
}
432-

‎packages/vscode/src/commands/checkpoints-command/types/checkpoint.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ export interface GitCheckpointData {
66
folder_name: string
77
}
88

9+
export interface CheckpointTab {
10+
uri: string
11+
view_column: number
12+
is_active: boolean
13+
is_group_active: boolean
14+
}
15+
916
export interface Checkpoint {
1017
timestamp: number
1118
title: string
@@ -18,4 +25,5 @@ export interface Checkpoint {
1825
response_preview_item_created_at?: number
1926
checked_files?: string[]
2027
checked_websites?: string[]
28+
active_tabs?: CheckpointTab[]
2129
}

‎packages/vscode/src/commands/checkpoints-command/utils/git-utils.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode'
22
import { execSync } from 'child_process'
3-
import * as path from 'path'
43
import { Logger } from '@shared/utils/logger'
54
export interface GitInfo {
65
branch: string

0 commit comments

Comments
 (0)