Don't refresh cached globals automatically

Fixes #259343
Fixes #256746
This commit is contained in:
Daniel Imms
2025-08-03 05:15:19 -07:00
parent cda153f038
commit f9059d5a79
3 changed files with 22 additions and 7 deletions

View File

@@ -17,6 +17,15 @@
"terminalCompletionProvider",
"terminalShellEnv"
],
"contributes": {
"commands": [
{
"command": "terminal.integrated.suggest.clearCachedGlobals",
"category": "Terminal",
"title": "%terminal.integrated.suggest.clearCachedGlobals%"
}
]
},
"scripts": {
"compile": "npx gulp compile-extension:terminal-suggest",
"watch": "npx gulp watch-extension:terminal-suggest",

View File

@@ -1,5 +1,6 @@
{
"description": "Extension to add terminal completions for zsh, bash, and fish terminals.",
"displayName": "Terminal Suggest for VS Code",
"view.name": "Terminal Suggest"
"view.name": "Terminal Suggest",
"terminal.integrated.suggest.clearCachedGlobals": "Clear Suggest Cached Globals"
}

View File

@@ -76,7 +76,6 @@ const getShellSpecificGlobals: Map<TerminalShellType, (options: ExecOptionsWithS
[TerminalShellType.PowerShell, getPwshGlobals],
]);
async function getShellGlobals(
shellType: TerminalShellType,
existingCommands?: Set<string>,
@@ -106,8 +105,11 @@ async function getShellGlobals(
shouldRefresh = true;
}
if (!shouldRefresh && cached.commands) {
// Trigger background refresh
void fetchAndCacheShellGlobals(shellType, existingCommands, machineId, remoteAuthority, true);
// NOTE: This used to trigger a background refresh in order to ensure all commands
// are up to date, but this ends up launching way too many processes. Especially on
// Windows where this caused significant performance issues as processes can block
// the extension host for several seconds
// (https://github.com/microsoft/vscode/issues/259343).
return cached.commands;
}
}
@@ -253,15 +255,14 @@ export async function activate(context: vscode.ExtensionContext) {
}
const commandsInPath = await pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType);
const shellGlobals = await getShellGlobals(terminalShellType, commandsInPath?.labels, machineId, remoteAuthority);
const shellGlobals = await getShellGlobals(terminalShellType, commandsInPath?.labels, machineId, remoteAuthority) ?? [];
const shellGlobalsArr = shellGlobals ?? [];
if (!commandsInPath?.completionResources) {
console.debug('#terminalCompletions No commands found in path');
return;
}
// Order is important here, add shell globals first so they are prioritized over path commands
const commands = [...shellGlobalsArr, ...commandsInPath.completionResources];
const commands = [...shellGlobals, ...commandsInPath.completionResources];
const currentCommandString = getCurrentCommandAndArgs(terminalContext.commandLine, terminalContext.cursorPosition, terminalShellType);
const pathSeparator = isWindows ? '\\' : '/';
const tokenType = getTokenType(terminalContext, terminalShellType);
@@ -305,6 +306,10 @@ export async function activate(context: vscode.ExtensionContext) {
}
}, '/', '\\'));
await watchPathDirectories(context, currentTerminalEnv, pathExecutableCache);
context.subscriptions.push(vscode.commands.registerCommand('terminal.integrated.suggest.clearCachedGlobals', () => {
cachedGlobals.clear();
}));
}
/**