@@ -9,6 +9,12 @@ import { marked } from 'marked'
99import { EventEmitter } from 'events'
1010import { apply_context_command } from '../commands/apply-context-command/apply-context-command'
1111import { dictionary } from '@shared/constants/dictionary'
12+ import {
13+ CONTEXT_CHECKED_PATHS_STATE_KEY ,
14+ CONTEXT_CHECKED_URLS_STATE_KEY ,
15+ DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY ,
16+ type DuplicateWorkspaceContext
17+ } from '../constants/state-keys'
1218import { ContextProvider } from './providers/context-provider'
1319
1420export const token_count_emitter = new EventEmitter ( )
@@ -20,13 +26,60 @@ const round_token_count_for_badge = (count: number): number => {
2026 return Math . floor ( count / 1000 ) * 1000
2127}
2228
23- export const context_initialization = (
29+ const restore_duplicated_workspace_context = async (
2430 context : vscode . ExtensionContext
25- ) : {
31+ ) => {
32+ const duplicated_context = context . globalState . get < DuplicateWorkspaceContext > (
33+ DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY
34+ )
35+
36+ if ( duplicated_context ?. timestamp ) {
37+ const now = Date . now ( )
38+ const age = now - duplicated_context . timestamp
39+
40+ if ( age <= 60000 ) {
41+ const current_workspace_folders =
42+ vscode . workspace . workspaceFolders ?. map ( ( folder ) => folder . uri . fsPath ) ??
43+ [ ]
44+
45+ const sorted_current_folders = [ ...current_workspace_folders ] . sort ( )
46+ const sorted_saved_folders = [
47+ ...( duplicated_context . workspace_root_folders ?? [ ] )
48+ ] . sort ( )
49+
50+ const are_workspaces_the_same =
51+ sorted_current_folders . length == sorted_saved_folders . length &&
52+ sorted_current_folders . every (
53+ ( value , index ) => value == sorted_saved_folders [ index ]
54+ )
55+ if ( are_workspaces_the_same ) {
56+ await context . workspaceState . update (
57+ CONTEXT_CHECKED_PATHS_STATE_KEY ,
58+ duplicated_context . checked_files
59+ )
60+ await context . workspaceState . update (
61+ CONTEXT_CHECKED_URLS_STATE_KEY ,
62+ duplicated_context . checked_websites
63+ )
64+ }
65+ }
66+
67+ await context . globalState . update (
68+ DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY ,
69+ undefined
70+ )
71+ }
72+ }
73+
74+ export const context_initialization = async (
75+ context : vscode . ExtensionContext
76+ ) : Promise < {
2677 workspace_provider : WorkspaceProvider
2778 open_editors_provider : OpenEditorsProvider
2879 websites_provider : WebsitesProvider
29- } => {
80+ } > => {
81+ await restore_duplicated_workspace_context ( context )
82+
3083 let was_above_threshold = false
3184
3285 const workspace_folders = vscode . workspace . workspaceFolders ?? [ ]
0 commit comments