]> git.lizzy.rs Git - rust.git/commitdiff
Introduce `toggle inlay hints` vscode command
authorveetaha <veetaha2@gmail.com>
Mon, 25 May 2020 00:47:33 +0000 (03:47 +0300)
committerveetaha <veetaha2@gmail.com>
Mon, 25 May 2020 00:59:46 +0000 (03:59 +0300)
Users now can assign a shortcut for this command
via the general vscode
keybindings ui or `keybinding.json file`

Closes: #4599
docs/user/features.md
editors/code/package.json
editors/code/src/commands/index.ts
editors/code/src/commands/toggle_inlay_hints.ts [new file with mode: 0644]
editors/code/src/config.ts
editors/code/src/main.ts

index 340bce835565fa793c598711ee2496543c70218d..12ecdec136a2a1fc6119c6661af9b0035b814ba2 100644 (file)
@@ -93,6 +93,12 @@ Shows internal statistic about memory usage of rust-analyzer.
 
 Show current rust-analyzer version.
 
+#### Toggle inlay hints
+
+Toggle inlay hints view for the current workspace.
+It is recommended to assign a shortcut for this command to quickly turn off
+inlay hints when they prevent you from reading/writing the code.
+
 #### Run Garbage Collection
 
 Manually triggers GC.
index 21039ced88588000be7d4944237e62feaa797b2f..2f14eaebd258bf85bb04a4e83fb6ceab694e22a1 100644 (file)
                 "command": "rust-analyzer.serverVersion",
                 "title": "Show RA Version",
                 "category": "Rust Analyzer"
+            },
+            {
+                "command": "rust-analyzer.toggleInlayHints",
+                "title": "Toggle inlay hints",
+                "category": "Rust Analyzer"
             }
         ],
         "keybindings": [
index abb53a2481525dfc7f2dc5fce424d8a49670b149..c2a232d5fd8773ca4531151c191f74e1c956fdfa 100644 (file)
@@ -16,6 +16,7 @@ export * from './expand_macro';
 export * from './runnables';
 export * from './ssr';
 export * from './server_version';
+export * from './toggle_inlay_hints';
 
 export function collectGarbage(ctx: Ctx): Cmd {
     return async () => ctx.client.sendRequest(ra.collectGarbage, null);
diff --git a/editors/code/src/commands/toggle_inlay_hints.ts b/editors/code/src/commands/toggle_inlay_hints.ts
new file mode 100644 (file)
index 0000000..7606af8
--- /dev/null
@@ -0,0 +1,11 @@
+import * as vscode from 'vscode';
+import { Ctx, Cmd } from '../ctx';
+
+export function toggleInlayHints(ctx: Ctx): Cmd {
+    return async () => {
+        await vscode
+            .workspace
+            .getConfiguration(`${ctx.config.rootSection}.inlayHints`)
+            .update('enable', !ctx.config.inlayHints.enable, vscode.ConfigurationTarget.Workspace);
+    };
+}
index ee294fbe312c4c9b5e121cbb769fd5f97b42dccb..e8abf8284eb7380c8f641f369c5c006fcba8c776 100644 (file)
@@ -8,7 +8,7 @@ export const NIGHTLY_TAG = "nightly";
 export class Config {
     readonly extensionId = "matklad.rust-analyzer";
 
-    private readonly rootSection = "rust-analyzer";
+    readonly rootSection = "rust-analyzer";
     private readonly requiresReloadOpts = [
         "serverPath",
         "cargo",
index 3405634f3395c8df2f26a0857a21302087f6d509..0e5a206410e0a4e6dcedbfb77b60b41f84b447c2 100644 (file)
@@ -86,6 +86,7 @@ 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);