]> git.lizzy.rs Git - rust.git/blobdiff - editors/code/src/main.ts
Add **Copy Run Command Line** command for vscode
[rust.git] / editors / code / src / main.ts
index 4b2d3c8a55791dee5417944e251b51d4a62fcbbc..43cae5c7fe7c67f48a8cf17c78acd0d6a120edcf 100644 (file)
@@ -105,8 +105,10 @@ async function tryActivate(context: vscode.ExtensionContext) {
     ctx.registerCommand('joinLines', commands.joinLines);
     ctx.registerCommand('parentModule', commands.parentModule);
     ctx.registerCommand('syntaxTree', commands.syntaxTree);
+    ctx.registerCommand('viewHir', commands.viewHir);
     ctx.registerCommand('expandMacro', commands.expandMacro);
     ctx.registerCommand('run', commands.run);
+    ctx.registerCommand('copyRunCommandLine', commands.copyRunCommandLine);
     ctx.registerCommand('debug', commands.debug);
     ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
     ctx.registerCommand('openDocs', commands.openDocs);
@@ -131,7 +133,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
     ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
 
     activateInlayHints(ctx);
-    warnAboutRustLangExtensionConflict();
+    warnAboutExtensionConflicts();
 
     vscode.workspace.onDidChangeConfiguration(
         _ => ctx?.client?.sendNotification('workspace/didChangeConfiguration', { settings: "" }),
@@ -166,6 +168,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
         }
         return;
     };
+    if (serverPath(config)) return;
 
     const now = Date.now();
     if (config.package.releaseTag === NIGHTLY_TAG) {
@@ -206,7 +209,6 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
             url: artifact.browser_download_url,
             dest,
             progressTitle: "Downloading rust-analyzer extension",
-            overwrite: true,
         });
     });
 
@@ -277,7 +279,7 @@ async function patchelf(dest: PathLike): Promise<void> {
 }
 
 async function getServer(config: Config, state: PersistentState): Promise<string | undefined> {
-    const explicitPath = process.env.__RA_LSP_SERVER_DEBUG ?? config.serverPath;
+    const explicitPath = serverPath(config);
     if (explicitPath) {
         if (explicitPath.startsWith("~/")) {
             return os.homedir() + explicitPath.slice("~".length);
@@ -286,14 +288,16 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     };
     if (config.package.releaseTag === null) return "rust-analyzer";
 
-    let platform: string | undefined;
-    if (process.arch === "x64" || process.arch === "ia32") {
-        if (process.platform === "linux") platform = "linux";
-        if (process.platform === "darwin") platform = "mac";
-        if (process.platform === "win32") platform = "windows";
-    } else if (process.arch === "arm64" && process.platform === "darwin") {
-        platform = "mac";
-    }
+    const platforms: { [key: string]: string } = {
+        "ia32 win32": "x86_64-pc-windows-msvc",
+        "x64 win32": "x86_64-pc-windows-msvc",
+        "x64 linux": "x86_64-unknown-linux-gnu",
+        "x64 darwin": "x86_64-apple-darwin",
+        "arm64 win32": "aarch64-pc-windows-msvc",
+        "arm64 linux": "aarch64-unknown-linux-gnu",
+        "arm64 darwin": "aarch64-apple-darwin",
+    };
+    const platform = platforms[`${process.arch} ${process.platform}`];
     if (platform === undefined) {
         vscode.window.showErrorMessage(
             "Unfortunately we don't ship binaries for your platform yet. " +
@@ -305,7 +309,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
         );
         return undefined;
     }
-    const ext = platform === "windows" ? ".exe" : "";
+    const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
     const dest = path.join(config.globalStoragePath, `rust-analyzer-${platform}${ext}`);
     const exists = await fs.stat(dest).then(() => true, () => false);
     if (!exists) {
@@ -336,7 +340,6 @@ async function getServer(config: Config, state: PersistentState): Promise<string
             progressTitle: "Downloading rust-analyzer server",
             gunzip: true,
             mode: 0o755,
-            overwrite: true,
         });
     });
 
@@ -349,6 +352,10 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     return dest;
 }
 
+function serverPath(config: Config): string | null {
+    return process.env.__RA_LSP_SERVER_DEBUG ?? config.serverPath;
+}
+
 async function isNixOs(): Promise<boolean> {
     try {
         const contents = await fs.readFile("/etc/os-release");
@@ -411,11 +418,21 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
     }
 }
 
-function warnAboutRustLangExtensionConflict() {
-    const rustLangExt = vscode.extensions.getExtension("rust-lang.rust");
-    if (rustLangExt !== undefined) {
+function warnAboutExtensionConflicts() {
+    const conflicting = [
+        ["rust-analyzer", "matklad.rust-analyzer"],
+        ["Rust", "rust-lang.rust"],
+        ["Rust", "kalitaalexey.vscode-rust"],
+    ];
+
+    const found = conflicting.filter(
+        nameId => vscode.extensions.getExtension(nameId[1]) !== undefined);
+
+    if (found.length > 1) {
+        const fst = found[0];
+        const sec = found[1];
         vscode.window.showWarningMessage(
-            "You have both rust-analyzer (matklad.rust-analyzer) and Rust (rust-lang.rust) " +
+            `You have both the ${fst[0]} (${fst[1]}) and ${sec[0]} (${sec[1]}) ` +
             "plugins enabled. These are known to conflict and cause various functions of " +
             "both plugins to not work correctly. You should disable one of them.", "Got it");
     };