@@ -46,7 +46,7 @@ type ShellGlobalsCacheEntryWithMeta = ShellGlobalsCacheEntry & { timestamp: numb
46
46
const cachedGlobals : Map < string , ShellGlobalsCacheEntryWithMeta > = new Map ( ) ;
47
47
let pathExecutableCache : PathExecutableCache ;
48
48
const CACHE_KEY = 'terminalSuggestGlobalsCacheV2' ;
49
- let globalStorage : vscode . Memento ;
49
+ let globalStorageUri : vscode . Uri ;
50
50
const CACHE_MAX_AGE_MS = 1000 * 60 * 60 * 24 * 7 ; // 7 days
51
51
52
52
function getCacheKey ( machineId : string , remoteAuthority : string | undefined , shellType : TerminalShellType ) : string {
@@ -150,7 +150,7 @@ async function fetchAndCacheShellGlobals(
150
150
151
151
152
152
async function writeGlobalsCache ( ) : Promise < void > {
153
- if ( ! globalStorage ) {
153
+ if ( ! globalStorageUri ) {
154
154
return ;
155
155
}
156
156
// Remove old entries
@@ -165,25 +165,40 @@ async function writeGlobalsCache(): Promise<void> {
165
165
obj [ key ] = value ;
166
166
}
167
167
try {
168
- await globalStorage . update ( CACHE_KEY , obj ) ;
168
+ // Ensure the directory exists
169
+ const terminalSuggestDir = vscode . Uri . joinPath ( globalStorageUri , 'terminal-suggest' ) ;
170
+ await vscode . workspace . fs . createDirectory ( terminalSuggestDir ) ;
171
+ const cacheFile = vscode . Uri . joinPath ( terminalSuggestDir , `${ CACHE_KEY } .json` ) ;
172
+ const data = Buffer . from ( JSON . stringify ( obj ) , 'utf8' ) ;
173
+ await vscode . workspace . fs . writeFile ( cacheFile , data ) ;
169
174
} catch ( err ) {
170
175
console . error ( 'Failed to write terminal suggest globals cache:' , err ) ;
171
176
}
172
177
}
173
178
174
179
175
180
async function readGlobalsCache ( ) : Promise < void > {
176
- if ( ! globalStorage ) {
181
+ if ( ! globalStorageUri ) {
177
182
return ;
178
183
}
179
184
try {
180
- const obj = globalStorage . get < Record < string , ShellGlobalsCacheEntryWithMeta > > ( CACHE_KEY ) ;
185
+ const terminalSuggestDir = vscode . Uri . joinPath ( globalStorageUri , 'terminal-suggest' ) ;
186
+ const cacheFile = vscode . Uri . joinPath ( terminalSuggestDir , `${ CACHE_KEY } .json` ) ;
187
+ const data = await vscode . workspace . fs . readFile ( cacheFile ) ;
188
+ const obj = JSON . parse ( data . toString ( ) ) as Record < string , ShellGlobalsCacheEntryWithMeta > ;
181
189
if ( obj ) {
182
190
for ( const key of Object . keys ( obj ) ) {
183
191
cachedGlobals . set ( key , obj [ key ] ) ;
184
192
}
185
193
}
186
- } catch { }
194
+ } catch ( err ) {
195
+ // File might not exist yet, which is expected on first run
196
+ if ( err instanceof vscode . FileSystemError && err . code === 'FileNotFound' ) {
197
+ // This is expected on first run
198
+ return ;
199
+ }
200
+ console . error ( 'Failed to read terminal suggest globals cache:' , err ) ;
201
+ }
187
202
}
188
203
189
204
@@ -193,7 +208,7 @@ export async function activate(context: vscode.ExtensionContext) {
193
208
context . subscriptions . push ( pathExecutableCache ) ;
194
209
let currentTerminalEnv : ITerminalEnvironment = process . env ;
195
210
196
- globalStorage = context . globalState ;
211
+ globalStorageUri = context . globalStorageUri ;
197
212
await readGlobalsCache ( ) ;
198
213
199
214
// Get a machineId for this install (persisted per machine, not synced)
0 commit comments