Merge branch 'tyriar/258512__259342' into tyriar/258512__259342__259339

This commit is contained in:
Daniel Imms
2025-08-02 09:22:20 -07:00
3 changed files with 15 additions and 14 deletions

View File

@@ -103,6 +103,7 @@ export class PathExecutableCache implements vscode.Disposable {
// Extract executables from PATH // Extract executables from PATH
const paths = pathValue.split(isWindows ? ';' : ':'); const paths = pathValue.split(isWindows ? ';' : ':');
const pathSeparator = isWindows ? '\\' : '/'; const pathSeparator = isWindows ? '\\' : '/';
const promisePaths: string[] = [];
const promises: Promise<Set<ICompletionResource> | undefined>[] = []; const promises: Promise<Set<ICompletionResource> | undefined>[] = [];
const labels: Set<string> = new Set<string>(); const labels: Set<string> = new Set<string>();
@@ -116,6 +117,7 @@ export class PathExecutableCache implements vscode.Disposable {
} }
} else { } else {
// Not cached, need to scan this directory // Not cached, need to scan this directory
promisePaths.push(pathDir);
promises.push(this._getExecutablesInSinglePath(pathDir, pathSeparator, labels)); promises.push(this._getExecutablesInSinglePath(pathDir, pathSeparator, labels));
} }
} }
@@ -123,11 +125,9 @@ export class PathExecutableCache implements vscode.Disposable {
// Process uncached directories // Process uncached directories
if (promises.length > 0) { if (promises.length > 0) {
const resultSets = await Promise.all(promises); const resultSets = await Promise.all(promises);
let uncachedPathIndex = 0; for (const [i, resultSet] of resultSets.entries()) {
const pathDir = promisePaths[i];
for (const pathDir of paths) {
if (!this._cachedExes.has(pathDir)) { if (!this._cachedExes.has(pathDir)) {
const resultSet = resultSets[uncachedPathIndex++];
this._cachedExes.set(pathDir, resultSet || new Set()); this._cachedExes.set(pathDir, resultSet || new Set());
} }
} }
@@ -135,7 +135,12 @@ export class PathExecutableCache implements vscode.Disposable {
// Merge all results from all directories // Merge all results from all directories
const executables = new Set<ICompletionResource>(); const executables = new Set<ICompletionResource>();
const processedPaths: Set<string> = new Set();
for (const pathDir of paths) { for (const pathDir of paths) {
if (processedPaths.has(pathDir)) {
continue;
}
processedPaths.add(pathDir);
const dirExecutables = this._cachedExes.get(pathDir); const dirExecutables = this._cachedExes.get(pathDir);
if (dirExecutables) { if (dirExecutables) {
for (const executable of dirExecutables) { for (const executable of dirExecutables) {

View File

@@ -252,13 +252,9 @@ export async function activate(context: vscode.ExtensionContext) {
return; return;
} }
const [commandsInPath, shellGlobals] = await Promise.all([ const commandsInPath = await pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType);
pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType), const shellGlobals = await getShellGlobals(terminalShellType, commandsInPath?.labels, machineId, remoteAuthority);
(async () => {
const executables = await pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType);
return getShellGlobals(terminalShellType, executables?.labels, machineId, remoteAuthority);
})()
]);
const shellGlobalsArr = shellGlobals ?? []; const shellGlobalsArr = shellGlobals ?? [];
if (!commandsInPath?.completionResources) { if (!commandsInPath?.completionResources) {
console.debug('#terminalCompletions No commands found in path'); console.debug('#terminalCompletions No commands found in path');

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import 'mocha'; import 'mocha';
import { strictEqual } from 'node:assert'; import { deepStrictEqual, strictEqual } from 'node:assert';
import type { MarkdownString } from 'vscode'; import type { MarkdownString } from 'vscode';
import { PathExecutableCache } from '../../env/pathExecutableCache'; import { PathExecutableCache } from '../../env/pathExecutableCache';
@@ -16,12 +16,12 @@ suite('PathExecutableCache', () => {
strictEqual(Array.from(result!.labels!).length, 0); strictEqual(Array.from(result!.labels!).length, 0);
}); });
test('caching is working on successive calls', async () => { test('results are the same on successive calls', async () => {
const cache = new PathExecutableCache(); const cache = new PathExecutableCache();
const env = { PATH: process.env.PATH }; const env = { PATH: process.env.PATH };
const result = await cache.getExecutablesInPath(env); const result = await cache.getExecutablesInPath(env);
const result2 = await cache.getExecutablesInPath(env); const result2 = await cache.getExecutablesInPath(env);
strictEqual(result, result2); deepStrictEqual(result!.labels, result2!.labels);
}); });
test('refresh clears the cache', async () => { test('refresh clears the cache', async () => {