about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhuntc <huntchr@gmail.com>2024-07-30 16:26:56 +1000
committerhuntc <huntchr@gmail.com>2024-07-30 16:26:56 +1000
commit786ef8393c78819d09d519939dd103b89b000a44 (patch)
tree60273fca6ca5eb2e43106a29f7abcce8fc0bb2f9
parenta22aeb2c75e66c61e4a6416c169bff15234f59f1 (diff)
downloadrust-786ef8393c78819d09d519939dd103b89b000a44.tar.gz
rust-786ef8393c78819d09d519939dd103b89b000a44.zip
Checks date for any RA
-rw-r--r--src/tools/rust-analyzer/editors/code/src/bootstrap.ts19
-rw-r--r--src/tools/rust-analyzer/editors/code/tests/unit/bootstrap.test.ts23
2 files changed, 22 insertions, 20 deletions
diff --git a/src/tools/rust-analyzer/editors/code/src/bootstrap.ts b/src/tools/rust-analyzer/editors/code/src/bootstrap.ts
index ebcafd6f72e..521d0ba4c1d 100644
--- a/src/tools/rust-analyzer/editors/code/src/bootstrap.ts
+++ b/src/tools/rust-analyzer/editors/code/src/bootstrap.ts
@@ -154,21 +154,16 @@ function orderFromPath(
     raVersionResolver: (path: string) => string | undefined,
 ): string {
     const capture = path.match(/^.*\/toolchains\/(.*)\/bin\/rust-analyzer$/);
-
     if (capture?.length === 2) {
         const toolchain = capture[1]!;
-        if (toolchain.startsWith("stable-")) {
-            return "1";
+        // It is a semver, so we must resolve Rust Analyzer's version.
+        const raVersion = raVersionResolver(path);
+        const raDate = raVersion?.match(/^rust-analyzer .*\(.* (\d{4}-\d{2}-\d{2})\)$/);
+        if (raDate?.length === 2) {
+            const precedence = toolchain.startsWith("nightly-") ? "/0" : "/1";
+            return "0-" + raDate[1] + precedence;
         } else {
-            // It is a semver, so we must resolve Rust Analyzer's version.
-            const raVersion = raVersionResolver(path);
-            const raDate = raVersion?.match(/^rust-analyzer .*\(.* (\d{4}-\d{2}-\d{2})\)$/);
-            if (raDate?.length === 2) {
-                const precedence = toolchain.startsWith("nightly-") ? "/0" : "/1";
-                return "0-" + raDate[1] + precedence;
-            } else {
-                return "2";
-            }
+            return "2";
         }
     } else {
         return "2";
diff --git a/src/tools/rust-analyzer/editors/code/tests/unit/bootstrap.test.ts b/src/tools/rust-analyzer/editors/code/tests/unit/bootstrap.test.ts
index 78eb8f08cea..6e17d73adc4 100644
--- a/src/tools/rust-analyzer/editors/code/tests/unit/bootstrap.test.ts
+++ b/src/tools/rust-analyzer/editors/code/tests/unit/bootstrap.test.ts
@@ -52,11 +52,15 @@ export async function getTests(ctx: Context) {
             assert.deepStrictEqual(
                 _private.orderFromPath(
                     "/Users/myuser/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rust-analyzer",
-                    function () {
-                        assert.fail("Shouldn't get here.");
+                    function (path: string) {
+                        assert.deepStrictEqual(
+                            path,
+                            "/Users/myuser/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rust-analyzer",
+                        );
+                        return "rust-analyzer 1.79.0 (129f3b99 2024-06-10)";
                     },
                 ),
-                "1",
+                "0-2024-06-10/1",
             );
         });
 
@@ -75,11 +79,14 @@ export async function getTests(ctx: Context) {
                     "/Users/myuser/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rust-analyzer",
                     "/Users/myuser/.rustup/toolchains/nightly-2022-11-22-aarch64-apple-darwin/bin/rust-analyzer",
                     function (path: string) {
-                        assert.deepStrictEqual(
-                            path,
-                            "/Users/myuser/.rustup/toolchains/nightly-2022-11-22-aarch64-apple-darwin/bin/rust-analyzer",
-                        );
-                        return "rust-analyzer 1.67.0-nightly (b7bc90fe 2022-11-21)";
+                        if (
+                            path ===
+                            "/Users/myuser/.rustup/toolchains/nightly-2022-11-22-aarch64-apple-darwin/bin/rust-analyzer"
+                        ) {
+                            return "rust-analyzer 1.67.0-nightly (b7bc90fe 2022-11-21)";
+                        } else {
+                            return "rust-analyzer 1.79.0 (129f3b99 2024-06-10)";
+                        }
                     },
                 ),
                 "/Users/myuser/.rustup/toolchains/nightly-2022-11-22-aarch64-apple-darwin/bin/rust-analyzer",