fix: check sdk binary existence concurrently
Previously, getSDKGoOptions would blindly list all subdirectories in
the sdk directory as valid Go versions. This caused issues when files
like .DS_Store were present.
This change modifies getSDKGoOptions to verify that the 'go' binary
exists within the expected path for each subdirectory. It performs
these checks concurrently for better performance.
diff --git a/extension/src/goEnvironmentStatus.ts b/extension/src/goEnvironmentStatus.ts
index 31d5d8d..4ed4203 100644
--- a/extension/src/goEnvironmentStatus.ts
+++ b/extension/src/goEnvironmentStatus.ts
@@ -466,12 +466,23 @@
}
const readdir = promisify(fs.readdir);
const subdirs = await readdir(sdkPath);
+ const stat = promisify(fs.stat);
+
// The dir happens to be the version, which will be used as the label.
// The path is assembled and used as the description.
- return subdirs.map(
- (dir: string) =>
- new GoEnvironmentOption(path.join(sdkPath, dir, 'bin', correctBinname('go')), dir.replace('go', 'Go '))
+ const options = await Promise.all(
+ subdirs.map(async (dir) => {
+ const binpath = path.join(sdkPath, dir, 'bin', correctBinname('go'));
+ try {
+ if ((await stat(binpath)).isFile()) {
+ return new GoEnvironmentOption(binpath, dir.replace('go', 'Go '));
+ }
+ } catch {
+ // ignore
+ }
+ })
);
+ return options.filter(Boolean) as GoEnvironmentOption[];
}
export async function getDefaultGoOption(): Promise<GoEnvironmentOption | undefined> {
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I spotted some possible problems with your PR:
1. You usually need to reference a bug number for all but trivial or cosmetic fixes. For the vscode-go repo, the format is usually 'Fixes golang/vscode-go#1234' or 'Updates golang/vscode-go#1234' at the end of the commit message. Should you have a bug reference?
Please address any problems by updating the GitHub PR.
When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.
To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.
For more details, see:
(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |