Skip to content

Commit b7ddf44

Browse files
authored
Merge pull request microsoft#259414 from microsoft/tyriar/258512__259342__259339__259343
Don't refresh cached globals automatically
2 parents e9733de + c2cc558 commit b7ddf44

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

extensions/terminal-suggest/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
"terminalCompletionProvider",
1818
"terminalShellEnv"
1919
],
20+
"contributes": {
21+
"commands": [
22+
{
23+
"command": "terminal.integrated.suggest.clearCachedGlobals",
24+
"category": "Terminal",
25+
"title": "%terminal.integrated.suggest.clearCachedGlobals%"
26+
}
27+
]
28+
},
2029
"scripts": {
2130
"compile": "npx gulp compile-extension:terminal-suggest",
2231
"watch": "npx gulp watch-extension:terminal-suggest",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"description": "Extension to add terminal completions for zsh, bash, and fish terminals.",
33
"displayName": "Terminal Suggest for VS Code",
4-
"view.name": "Terminal Suggest"
4+
"view.name": "Terminal Suggest",
5+
"terminal.integrated.suggest.clearCachedGlobals": "Clear Suggest Cached Globals"
56
}

extensions/terminal-suggest/src/terminalSuggestMain.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ const getShellSpecificGlobals: Map<TerminalShellType, (options: ExecOptionsWithS
7676
[TerminalShellType.PowerShell, getPwshGlobals],
7777
]);
7878

79-
8079
async function getShellGlobals(
8180
shellType: TerminalShellType,
8281
existingCommands?: Set<string>,
@@ -106,8 +105,11 @@ async function getShellGlobals(
106105
shouldRefresh = true;
107106
}
108107
if (!shouldRefresh && cached.commands) {
109-
// Trigger background refresh
110-
void fetchAndCacheShellGlobals(shellType, existingCommands, machineId, remoteAuthority, true);
108+
// NOTE: This used to trigger a background refresh in order to ensure all commands
109+
// are up to date, but this ends up launching way too many processes. Especially on
110+
// Windows where this caused significant performance issues as processes can block
111+
// the extension host for several seconds
112+
// (https://github.com/microsoft/vscode/issues/259343).
111113
return cached.commands;
112114
}
113115
}
@@ -253,15 +255,14 @@ export async function activate(context: vscode.ExtensionContext) {
253255
}
254256

255257
const commandsInPath = await pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType);
256-
const shellGlobals = await getShellGlobals(terminalShellType, commandsInPath?.labels, machineId, remoteAuthority);
258+
const shellGlobals = await getShellGlobals(terminalShellType, commandsInPath?.labels, machineId, remoteAuthority) ?? [];
257259

258-
const shellGlobalsArr = shellGlobals ?? [];
259260
if (!commandsInPath?.completionResources) {
260261
console.debug('#terminalCompletions No commands found in path');
261262
return;
262263
}
263264
// Order is important here, add shell globals first so they are prioritized over path commands
264-
const commands = [...shellGlobalsArr, ...commandsInPath.completionResources];
265+
const commands = [...shellGlobals, ...commandsInPath.completionResources];
265266
const currentCommandString = getCurrentCommandAndArgs(terminalContext.commandLine, terminalContext.cursorPosition, terminalShellType);
266267
const pathSeparator = isWindows ? '\\' : '/';
267268
const tokenType = getTokenType(terminalContext, terminalShellType);
@@ -305,6 +306,10 @@ export async function activate(context: vscode.ExtensionContext) {
305306
}
306307
}, '/', '\\'));
307308
await watchPathDirectories(context, currentTerminalEnv, pathExecutableCache);
309+
310+
context.subscriptions.push(vscode.commands.registerCommand('terminal.integrated.suggest.clearCachedGlobals', () => {
311+
cachedGlobals.clear();
312+
}));
308313
}
309314

310315
/**

0 commit comments

Comments
 (0)