Skip to content

Commit cda153f

Browse files
committed
Merge branch 'tyriar/258512__259342' into tyriar/258512__259342__259339
2 parents 200c648 + 956b533 commit cda153f

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

extensions/terminal-suggest/src/env/pathExecutableCache.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export class PathExecutableCache implements vscode.Disposable {
103103
// Extract executables from PATH
104104
const paths = pathValue.split(isWindows ? ';' : ':');
105105
const pathSeparator = isWindows ? '\\' : '/';
106+
const promisePaths: string[] = [];
106107
const promises: Promise<Set<ICompletionResource> | undefined>[] = [];
107108
const labels: Set<string> = new Set<string>();
108109

@@ -116,26 +117,30 @@ export class PathExecutableCache implements vscode.Disposable {
116117
}
117118
} else {
118119
// Not cached, need to scan this directory
120+
promisePaths.push(pathDir);
119121
promises.push(this._getExecutablesInSinglePath(pathDir, pathSeparator, labels));
120122
}
121123
}
122124

123125
// Process uncached directories
124126
if (promises.length > 0) {
125127
const resultSets = await Promise.all(promises);
126-
let uncachedPathIndex = 0;
127-
128-
for (const pathDir of paths) {
128+
for (const [i, resultSet] of resultSets.entries()) {
129+
const pathDir = promisePaths[i];
129130
if (!this._cachedExes.has(pathDir)) {
130-
const resultSet = resultSets[uncachedPathIndex++];
131131
this._cachedExes.set(pathDir, resultSet || new Set());
132132
}
133133
}
134134
}
135135

136136
// Merge all results from all directories
137137
const executables = new Set<ICompletionResource>();
138+
const processedPaths: Set<string> = new Set();
138139
for (const pathDir of paths) {
140+
if (processedPaths.has(pathDir)) {
141+
continue;
142+
}
143+
processedPaths.add(pathDir);
139144
const dirExecutables = this._cachedExes.get(pathDir);
140145
if (dirExecutables) {
141146
for (const executable of dirExecutables) {

extensions/terminal-suggest/src/terminalSuggestMain.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,9 @@ export async function activate(context: vscode.ExtensionContext) {
252252
return;
253253
}
254254

255-
const [commandsInPath, shellGlobals] = await Promise.all([
256-
pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType),
257-
(async () => {
258-
const executables = await pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType);
259-
return getShellGlobals(terminalShellType, executables?.labels, machineId, remoteAuthority);
260-
})()
261-
]);
255+
const commandsInPath = await pathExecutableCache.getExecutablesInPath(terminal.shellIntegration?.env?.value, terminalShellType);
256+
const shellGlobals = await getShellGlobals(terminalShellType, commandsInPath?.labels, machineId, remoteAuthority);
257+
262258
const shellGlobalsArr = shellGlobals ?? [];
263259
if (!commandsInPath?.completionResources) {
264260
console.debug('#terminalCompletions No commands found in path');

extensions/terminal-suggest/src/test/env/pathExecutableCache.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import 'mocha';
7-
import { strictEqual } from 'node:assert';
7+
import { deepStrictEqual, strictEqual } from 'node:assert';
88
import type { MarkdownString } from 'vscode';
99
import { PathExecutableCache } from '../../env/pathExecutableCache';
1010

@@ -16,12 +16,12 @@ suite('PathExecutableCache', () => {
1616
strictEqual(Array.from(result!.labels!).length, 0);
1717
});
1818

19-
test('caching is working on successive calls', async () => {
19+
test('results are the same on successive calls', async () => {
2020
const cache = new PathExecutableCache();
2121
const env = { PATH: process.env.PATH };
2222
const result = await cache.getExecutablesInPath(env);
2323
const result2 = await cache.getExecutablesInPath(env);
24-
strictEqual(result, result2);
24+
deepStrictEqual(result!.labels, result2!.labels);
2525
});
2626

2727
test('refresh clears the cache', async () => {

0 commit comments

Comments
 (0)