Unnamed repository; edit this file 'description' to name the repository.
Capture the components array and check it for rust-analyzer
Musteab 4 days ago
parent c0ff09b · commit c883367
-rw-r--r--editors/code/src/bootstrap.ts13
-rw-r--r--editors/code/tests/unit/bootstrap.test.ts2
2 files changed, 9 insertions, 6 deletions
diff --git a/editors/code/src/bootstrap.ts b/editors/code/src/bootstrap.ts
index 98c2b359bf..440f21cbe3 100644
--- a/editors/code/src/bootstrap.ts
+++ b/editors/code/src/bootstrap.ts
@@ -176,13 +176,16 @@ async function fileExists(uri: vscode.Uri) {
);
}
-// Matches a `components` array that lists `rust-analyzer`. The elements are matched with
-// `[^\]]` rather than `.` so that the array may be spread over several lines, which is just
-// as valid TOML as keeping it on one. TOML strings come in both quote flavours.
-const RA_COMPONENT_RE = /components\s*=\s*\[[^\]]*["']rust-analyzer["'][^\]]*\]/;
+// Captures the elements of a `components` array. They are matched with `[^\]]` rather than `.`
+// so that the array may be spread over several lines, which is just as valid TOML as keeping it
+// on one, while still stopping at the end of the array.
+const COMPONENTS_RE = /components\s*=\s*\[(?<components>[^\]]*)\]/;
+// TOML strings come in both quote flavours.
+const RA_COMPONENT_RE = /["']rust-analyzer["']/;
function declaresRaComponent(toolchainFileContents: string): boolean {
- return RA_COMPONENT_RE.test(toolchainFileContents);
+ const components = toolchainFileContents.match(COMPONENTS_RE)?.groups?.["components"];
+ return components !== undefined && RA_COMPONENT_RE.test(components);
}
async function hasToolchainFileWithRaDeclared(uri: vscode.Uri): Promise<boolean> {
diff --git a/editors/code/tests/unit/bootstrap.test.ts b/editors/code/tests/unit/bootstrap.test.ts
index 8d348b9ccb..259428da41 100644
--- a/editors/code/tests/unit/bootstrap.test.ts
+++ b/editors/code/tests/unit/bootstrap.test.ts
@@ -158,7 +158,7 @@ channel = "1.88"
components = [
"cargo",
]
-path = "/opt/rust-analyzer"
+# add "rust-analyzer" here to use the matching server
`,
),
);