Skip to content

Commit 264d466

Browse files
committed
Resolve path entries in parallel
1 parent 92f5c08 commit 264d466

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

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

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -105,55 +105,57 @@ export class PathExecutableCache implements vscode.Disposable {
105105
const result = new Set<ICompletionResource>();
106106
const fileResource = vscode.Uri.file(path);
107107
const files = await vscode.workspace.fs.readDirectory(fileResource);
108-
for (const [file, fileType] of files) {
109-
let kind: vscode.TerminalCompletionItemKind | undefined;
110-
let formattedPath: string | undefined;
111-
const resource = vscode.Uri.joinPath(fileResource, file);
112-
113-
// Skip unknown or directory file types early
114-
if (fileType === vscode.FileType.Unknown || fileType === vscode.FileType.Directory) {
115-
continue;
116-
}
108+
await Promise.all(
109+
files.map(([file, fileType]) => (async () => {
110+
let kind: vscode.TerminalCompletionItemKind | undefined;
111+
let formattedPath: string | undefined;
112+
const resource = vscode.Uri.joinPath(fileResource, file);
113+
114+
// Skip unknown or directory file types early
115+
if (fileType === vscode.FileType.Unknown || fileType === vscode.FileType.Directory) {
116+
return;
117+
}
117118

118-
try {
119-
const lstat = await fs.lstat(resource.fsPath);
120-
if (lstat.isSymbolicLink()) {
121-
try {
122-
const symlinkRealPath = await fs.realpath(resource.fsPath);
123-
const isExec = await isExecutable(symlinkRealPath, this._cachedWindowsExeExtensions);
124-
if (!isExec) {
125-
continue;
119+
try {
120+
const lstat = await fs.lstat(resource.fsPath);
121+
if (lstat.isSymbolicLink()) {
122+
try {
123+
const symlinkRealPath = await fs.realpath(resource.fsPath);
124+
const isExec = await isExecutable(symlinkRealPath, this._cachedWindowsExeExtensions);
125+
if (!isExec) {
126+
return;
127+
}
128+
kind = vscode.TerminalCompletionItemKind.Method;
129+
formattedPath = `${resource.fsPath} -> ${symlinkRealPath}`;
130+
} catch {
131+
return;
126132
}
127-
kind = vscode.TerminalCompletionItemKind.Method;
128-
formattedPath = `${resource.fsPath} -> ${symlinkRealPath}`;
129-
} catch {
130-
continue;
131133
}
134+
} catch {
135+
// Ignore errors for unreadable files
136+
return;
132137
}
133-
} catch {
134-
// Ignore errors for unreadable files
135-
continue;
136-
}
137138

138-
formattedPath = formattedPath ?? getFriendlyResourcePath(resource, pathSeparator);
139+
formattedPath = formattedPath ?? getFriendlyResourcePath(resource, pathSeparator);
139140

140-
// Check if already added or not executable
141-
if (labels.has(file)) {
142-
continue;
143-
}
141+
// Check if already added or not executable
142+
if (labels.has(file)) {
143+
return;
144+
}
144145

145-
const isExec = kind === vscode.TerminalCompletionItemKind.Method || await isExecutable(formattedPath, this._cachedWindowsExeExtensions);
146-
if (!isExec) {
147-
continue;
148-
}
146+
const isExec = kind === vscode.TerminalCompletionItemKind.Method || await isExecutable(formattedPath, this._cachedWindowsExeExtensions);
147+
if (!isExec) {
148+
return;
149+
}
149150

150-
result.add({
151-
label: file,
152-
documentation: formattedPath,
153-
kind: kind ?? vscode.TerminalCompletionItemKind.Method
154-
});
155-
labels.add(file);
156-
}
151+
result.add({
152+
label: file,
153+
documentation: formattedPath,
154+
kind: kind ?? vscode.TerminalCompletionItemKind.Method
155+
});
156+
labels.add(file);
157+
})())
158+
);
157159
return result;
158160
} catch (e) {
159161
// Ignore errors for directories that can't be read

0 commit comments

Comments
 (0)