]> git.lizzy.rs Git - rust.git/blobdiff - editors/code/src/main.ts
Preliminary implementation of lazy CodeAssits
[rust.git] / editors / code / src / main.ts
index dbb2411921bb5d853b8d0a8df8e28e7d0b681696..a92c676fa2dd7ddda1b9f5047c9ad9e58707349b 100644 (file)
@@ -12,10 +12,13 @@ import { log, assert, isValidExecutable } from './util';
 import { PersistentState } from './persistent_state';
 import { fetchRelease, download } from './net';
 import { activateTaskProvider } from './tasks';
+import { setContextValue } from './util';
 import { exec } from 'child_process';
 
 let ctx: Ctx | undefined;
 
+const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
+
 export async function activate(context: vscode.ExtensionContext) {
     // Register a "dumb" onEnter command for the case where server fails to
     // start.
@@ -54,6 +57,8 @@ export async function activate(context: vscode.ExtensionContext) {
     // This a horribly, horribly wrong way to deal with this problem.
     ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath);
 
+    setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
+
     // Commands which invokes manually via command palette, shortcut, etc.
 
     // Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
@@ -86,14 +91,15 @@ export async function activate(context: vscode.ExtensionContext) {
 
     ctx.registerCommand('ssr', commands.ssr);
     ctx.registerCommand('serverVersion', commands.serverVersion);
+    ctx.registerCommand('toggleInlayHints', commands.toggleInlayHints);
 
     // Internal commands which are invoked by the server.
     ctx.registerCommand('runSingle', commands.runSingle);
     ctx.registerCommand('debugSingle', commands.debugSingle);
     ctx.registerCommand('showReferences', commands.showReferences);
-    ctx.registerCommand('applySourceChange', commands.applySourceChange);
-    ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEdit);
-    ctx.registerCommand('selectAndApplySourceChange', commands.selectAndApplySourceChange);
+    ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEditCommand);
+    ctx.registerCommand('resolveCodeAction', commands.resolveCodeAction);
+    ctx.registerCommand('applyActionGroup', commands.applyActionGroup);
 
     ctx.pushCleanup(activateTaskProvider(workspaceFolder));
 
@@ -109,6 +115,7 @@ export async function activate(context: vscode.ExtensionContext) {
 }
 
 export async function deactivate() {
+    setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
     await ctx?.client.stop();
     ctx = undefined;
 }
@@ -193,7 +200,7 @@ async function patchelf(dest: PathLike): Promise<void> {
     await vscode.window.withProgress(
         {
             location: vscode.ProgressLocation.Notification,
-            title: "Patching rust-analysis for NixOS"
+            title: "Patching rust-analyzer for NixOS"
         },
         async (progress, _) => {
             const expression = `
@@ -280,7 +287,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     await download(artifact.browser_download_url, dest, "Downloading rust-analyzer server", { mode: 0o755 });
 
     // Patching executable if that's NixOS.
-    if (fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
+    if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
         await patchelf(dest);
     }