Skip to content

Commit cac03f3

Browse files
committed
Migrate ranges from workspace state to global extension storage and update range handling and tasks persistence accordingly
- [Pasted text] - simply don't delete anything. ranges are lightweight - [Pasted text] - is it possible? could it be better than [Fragment]? └── apps └── editor └── src ├── commands │ ├── duplicate-workspace-command.ts │ └── set-ranges-command.ts ├── constants │ └── state-keys.ts ├── context │ ├── context-initialization.ts │ └── providers │ └── workspace │ └── workspace-provider.ts ├── extension.ts ├── i18n │ └── translations │ ├── commands │ │ └── set-ranges-command.ts │ └── common.ts ├── migrations │ ├── index.ts │ ├── migrate-commit-message-details-filename.ts │ ├── migrate-configurations-to-api-configurations.ts │ ├── migrate-edit-context-to-edit-files-system-instructions.ts │ ├── migrate-model-providers-to-providers.ts │ ├── migrate-prompt-templates-suffixes.ts │ ├── migrate-prompt-templates-to-templates.ts │ ├── migrate-ranges-to-global-storage.ts │ └── migrate-settings-keys-to-chatbots-and-models.ts ├── utils │ └── tasks-utils.ts └── views └── prompt ├── backend │ ├── message-handlers │ │ └── index.ts │ └── prompt-view-provider.ts └── frontend └── Home └── hooks └── use-tasks.ts
1 parent 66866f7 commit cac03f3

13 files changed

Lines changed: 315 additions & 131 deletions

File tree

‎apps/editor/src/commands/duplicate-workspace-command.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { WorkspaceProvider } from '../context/providers/workspace/workspace-prov
33
import {
44
EDIT_FORMAT_STATE_KEY,
55
DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY,
6-
RANGES_STATE_KEY,
76
type DuplicateWorkspaceContext
87
} from '../constants/state-keys'
98

@@ -35,17 +34,12 @@ export const duplicate_workspace_command = (
3534
}
3635
}
3736

38-
const ranges =
39-
extension_context.workspaceState.get<Record<string, string>>(
40-
RANGES_STATE_KEY
41-
)
4237
const context_to_save: DuplicateWorkspaceContext = {
4338
selected_files: export_state.selected_files,
4439
selected_files_timestamps: export_state.selected_timestamps,
4540
workspace_root_folders,
4641
timestamp: Date.now(),
47-
open_editors,
48-
ranges
42+
open_editors
4943
}
5044

5145
const edit_format = extension_context.workspaceState.get(

‎apps/editor/src/commands/set-ranges-command.ts‎

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import {
55
WorkspaceProvider,
66
FileItem
77
} from '../context/providers/workspace/workspace-provider'
8-
import {
9-
RANGES_STATE_KEY,
10-
LAST_RANGES_SAVE_LOCATION_STATE_KEY
11-
} from '../constants/state-keys'
8+
import { LAST_RANGES_SAVE_LOCATION_STATE_KEY } from '../constants/state-keys'
129
import { t } from '../i18n'
13-
import { normalize_path } from '../utils/normalize-path'
1410
import { get_error_message } from '@/utils/get-error-message'
1511
import { is_binary_file } from '../utils/is-binary'
12+
import { RangesUtils } from '../utils/ranges-utils'
13+
import { normalize_path } from '../utils/normalize-path'
1614

1715
export const set_ranges_command = (
1816
workspace_provider: WorkspaceProvider,
@@ -29,7 +27,6 @@ export const set_ranges_command = (
2927
const workspace_folder = vscode.workspace.getWorkspaceFolder(
3028
item.resourceUri
3129
)
32-
const workspace_folders = vscode.workspace.workspaceFolders || []
3330

3431
if (!workspace_folder) {
3532
vscode.window.showErrorMessage(
@@ -56,37 +53,30 @@ export const set_ranges_command = (
5653
return
5754
}
5855

59-
const relative_path = path.relative(
60-
workspace_folder.uri.fsPath,
61-
file_path
56+
const relative_path = normalize_path(
57+
path.relative(workspace_folder.uri.fsPath, file_path)
6258
)
6359

64-
const get_path_key_for_state = () => {
65-
const rel_path_unix = normalize_path(relative_path)
66-
if (workspace_folders.length > 1) {
67-
return `${workspace_folder.name}:${rel_path_unix}`
68-
}
69-
return rel_path_unix
70-
}
71-
const state_key = get_path_key_for_state()
72-
7360
const ranges_file_path = path.join(
7461
workspace_folder.uri.fsPath,
7562
'.vscode',
7663
'ranges.json'
7764
)
78-
let file_ranges: Record<string, string> = {}
65+
const file_ranges: Record<string, string> = {}
7966
try {
8067
const content = await fs.readFile(ranges_file_path, 'utf-8')
81-
file_ranges = JSON.parse(content)
68+
const raw_ranges = JSON.parse(content)
69+
for (const [key, value] of Object.entries(raw_ranges)) {
70+
file_ranges[normalize_path(key)] = value as string
71+
}
8272
} catch {}
8373

84-
const state_ranges = extension_context.workspaceState.get<
85-
Record<string, string>
86-
>(RANGES_STATE_KEY, {})
74+
const all_global_ranges = RangesUtils.load_all(extension_context)
75+
const global_ranges_for_workspace =
76+
all_global_ranges[workspace_folder.uri.fsPath] || {}
8777

8878
const file_range_value = file_ranges[relative_path]
89-
const state_range_value = state_ranges[state_key]
79+
const state_range_value = global_ranges_for_workspace[relative_path]
9080
const current_range = file_range_value || state_range_value
9181

9282
const new_ranges = await vscode.window.showInputBox({
@@ -203,13 +193,20 @@ export const set_ranges_command = (
203193
}
204194
}
205195

206-
if (state_ranges[state_key]) {
207-
const updated_state = { ...state_ranges }
208-
delete updated_state[state_key]
209-
await extension_context.workspaceState.update(
210-
RANGES_STATE_KEY,
211-
updated_state
212-
)
196+
if (state_range_value) {
197+
const updated_all = { ...all_global_ranges }
198+
if (updated_all[workspace_folder.uri.fsPath]) {
199+
delete updated_all[workspace_folder.uri.fsPath][relative_path]
200+
if (
201+
Object.keys(updated_all[workspace_folder.uri.fsPath]).length === 0
202+
) {
203+
delete updated_all[workspace_folder.uri.fsPath]
204+
}
205+
}
206+
RangesUtils.save_all({
207+
extension_context,
208+
ranges: updated_all
209+
})
213210
changed = true
214211
}
215212

@@ -238,9 +235,9 @@ export const set_ranges_command = (
238235
picked: last_location !== 'state'
239236
},
240237
{
241-
label: t('common.source.workspace-state'),
238+
label: t('common.source.extension-storage'),
242239
description: t(
243-
'command.set-ranges-command.quick-pick.workspace-state-description'
240+
'command.set-ranges-command.quick-pick.extension-storage-description'
244241
),
245242
picked: last_location === 'state'
246243
}
@@ -275,13 +272,21 @@ export const set_ranges_command = (
275272
JSON.stringify(file_ranges, null, 2)
276273
)
277274

278-
if (state_ranges[state_key]) {
279-
const updated_state = { ...state_ranges }
280-
delete updated_state[state_key]
281-
await extension_context.workspaceState.update(
282-
RANGES_STATE_KEY,
283-
updated_state
284-
)
275+
if (state_range_value) {
276+
const updated_all = { ...all_global_ranges }
277+
if (updated_all[workspace_folder.uri.fsPath]) {
278+
delete updated_all[workspace_folder.uri.fsPath][relative_path]
279+
if (
280+
Object.keys(updated_all[workspace_folder.uri.fsPath])
281+
.length === 0
282+
) {
283+
delete updated_all[workspace_folder.uri.fsPath]
284+
}
285+
}
286+
RangesUtils.save_all({
287+
extension_context,
288+
ranges: updated_all
289+
})
285290
}
286291
} catch (error) {
287292
vscode.window.showErrorMessage(
@@ -291,14 +296,17 @@ export const set_ranges_command = (
291296
)
292297
}
293298
} else {
294-
const updated_state = {
295-
...state_ranges,
296-
[state_key]: formatted_range
299+
const updated_all = { ...all_global_ranges }
300+
if (!updated_all[workspace_folder.uri.fsPath]) {
301+
updated_all[workspace_folder.uri.fsPath] = {}
297302
}
298-
await extension_context.workspaceState.update(
299-
RANGES_STATE_KEY,
300-
updated_state
301-
)
303+
updated_all[workspace_folder.uri.fsPath][relative_path] =
304+
formatted_range
305+
306+
RangesUtils.save_all({
307+
extension_context,
308+
ranges: updated_all
309+
})
302310

303311
if (file_ranges[relative_path]) {
304312
delete file_ranges[relative_path]

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ export type DuplicateWorkspaceContext = {
142142
timestamp: number
143143
workspace_root_folders: string[]
144144
open_editors?: { path: string; view_column?: number }[]
145-
ranges?: Record<string, string>
146145
}
147146

148147
export type HistoryEntry = {

‎apps/editor/src/context/context-initialization.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
CONTEXT_SELECTED_PATHS_STATE_KEY,
1111
CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY,
1212
DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY,
13-
RANGES_STATE_KEY,
1413
type DuplicateWorkspaceContext
1514
} from '../constants/state-keys'
1615
import { SelectedFilesProvider } from './providers/selected-files/selected-files-provider'
@@ -62,12 +61,6 @@ const restore_duplicated_workspace_context = async (
6261
duplicated_context.selected_files_timestamps
6362
)
6463

65-
if (duplicated_context.ranges) {
66-
await extension_context.workspaceState.update(
67-
RANGES_STATE_KEY,
68-
duplicated_context.ranges
69-
)
70-
}
7164
if (duplicated_context.open_editors) {
7265
for (const editor_info of duplicated_context.open_editors) {
7366
try {

‎apps/editor/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import * as vscode from 'vscode'
44
import ignore, { Ignore } from 'ignore'
55
import {
66
CONTEXT_SELECTED_PATHS_STATE_KEY,
7-
CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY,
8-
RANGES_STATE_KEY
7+
CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY
98
} from '@/constants/state-keys'
109
import { IGNORED_LOCK_FILES } from '@/constants/ignored-lock-files'
1110
import { natural_sort } from '@/utils/natural-sort'
1211
import { Logger } from '@shared/utils/logger'
1312
import { display_token_count } from '@shared/utils/display-token-count'
1413
import { TokenCalculator } from './modules/token-calculator'
1514
import { normalize_path } from '@/utils/normalize-path'
15+
import { RangesUtils } from '@/utils/ranges-utils'
1616

1717
export interface IWorkspaceProvider {
1818
get_workspace_roots(): string[]
@@ -61,6 +61,7 @@ export class WorkspaceProvider
6161
private _user_allow_patterns: Ignore = ignore()
6262
private _watcher: vscode.FileSystemWatcher
6363
private _ranges_watcher: vscode.FileSystemWatcher
64+
private _global_ranges_watcher: vscode.FileSystemWatcher
6465
private _gitignore_watcher: vscode.FileSystemWatcher
6566
private _file_ranges: Map<string, string> = new Map()
6667
private _token_calculator: TokenCalculator
@@ -147,6 +148,19 @@ export class WorkspaceProvider
147148
this._ranges_watcher.onDidChange(() => this.load_all_ranges())
148149
this._ranges_watcher.onDidDelete(() => this.load_all_ranges())
149150

151+
const global_ranges_file_path = RangesUtils.get_file_path({
152+
extension_context: this._extension_context
153+
})
154+
this._global_ranges_watcher = vscode.workspace.createFileSystemWatcher(
155+
new vscode.RelativePattern(
156+
vscode.Uri.file(path.dirname(global_ranges_file_path)),
157+
path.basename(global_ranges_file_path)
158+
)
159+
)
160+
this._global_ranges_watcher.onDidCreate(() => this.load_all_ranges())
161+
this._global_ranges_watcher.onDidChange(() => this.load_all_ranges())
162+
this._global_ranges_watcher.onDidDelete(() => this.load_all_ranges())
163+
150164
this.ranges_initialization = this.load_all_ranges()
151165

152166
this.load_selected_files_state()
@@ -263,6 +277,7 @@ export class WorkspaceProvider
263277
dispose() {
264278
this._watcher.dispose()
265279
this._ranges_watcher.dispose()
280+
this._global_ranges_watcher.dispose()
266281
this._gitignore_watcher.dispose()
267282
this._config_change_handler.dispose()
268283
this._on_did_change_selected_files.dispose()
@@ -803,9 +818,12 @@ export class WorkspaceProvider
803818
try {
804819
const content = await fs.promises.readFile(ranges_file_path, 'utf-8')
805820
const ranges = JSON.parse(content) as Record<string, string>
806-
for (const [relativePath, range] of Object.entries(ranges)) {
807-
const absolutePath = path.join(workspace_root, relativePath)
808-
this._file_ranges.set(absolutePath, range)
821+
for (const [relative_path, range] of Object.entries(ranges)) {
822+
const absolute_path = path.join(
823+
workspace_root,
824+
normalize_path(relative_path)
825+
)
826+
this._file_ranges.set(absolute_path, range)
809827
}
810828
} catch (e) {
811829
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') {
@@ -814,45 +832,27 @@ export class WorkspaceProvider
814832
}
815833
}
816834

817-
const state_ranges = this._extension_context.workspaceState.get<
818-
Record<string, string>
819-
>(RANGES_STATE_KEY, {})
820-
for (const [key, range] of Object.entries(state_ranges)) {
821-
const resolved_path = this._resolve_state_path(key)
822-
if (resolved_path && fs.existsSync(resolved_path)) {
823-
this._file_ranges.set(resolved_path, range)
835+
const all_global_ranges = RangesUtils.load_all(this._extension_context)
836+
for (const workspace_root of this._workspace_roots) {
837+
const global_ranges_for_workspace =
838+
all_global_ranges[workspace_root] || {}
839+
for (const [rel_path, range] of Object.entries(
840+
global_ranges_for_workspace
841+
)) {
842+
const absolute_path = path.join(
843+
workspace_root,
844+
normalize_path(rel_path)
845+
)
846+
if (fs.existsSync(absolute_path)) {
847+
this._file_ranges.set(absolute_path, range)
848+
}
824849
}
825850
}
826851

827852
this._token_calculator.clear_caches()
828853
this.refresh()
829854
}
830855

831-
private _resolve_state_path(key: string): string | undefined {
832-
if (this._workspace_roots.length === 1) {
833-
return path.join(this._workspace_roots[0], key)
834-
}
835-
836-
const parts = key.split(':')
837-
if (parts.length > 1) {
838-
const name = parts[0]
839-
const rel_path = parts.slice(1).join(':')
840-
const index = this._workspace_names.indexOf(name)
841-
if (index !== -1) {
842-
return path.join(this._workspace_roots[index], rel_path)
843-
}
844-
}
845-
846-
for (const root of this._workspace_roots) {
847-
const abs = path.join(root, key)
848-
if (fs.existsSync(abs)) {
849-
return abs
850-
}
851-
}
852-
853-
return undefined
854-
}
855-
856856
get_range(filePath: string): string | undefined {
857857
return this._file_ranges.get(filePath)
858858
}

‎apps/editor/src/extension.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
migrate_commit_message_details_filename,
1212
migrate_prompt_templates_to_templates,
1313
migrate_model_providers_to_providers,
14-
migrate_settings_keys_to_chatbots_and_models
14+
migrate_settings_keys_to_chatbots_and_models,
15+
migrate_ranges_to_global_storage
1516
} from './migrations'
1617
import {
1718
agentic_search_command,
@@ -79,6 +80,8 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
7980
await migrate_model_providers_to_providers(extension_context)
8081
// 26 October 2026
8182
await migrate_settings_keys_to_chatbots_and_models(extension_context)
83+
// 8 November 2026
84+
await migrate_ranges_to_global_storage(extension_context)
8285
}
8386

8487
await migrations()

0 commit comments

Comments
 (0)