about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-25 07:14:43 +0000
committerGitHub <noreply@github.com>2020-05-25 07:14:43 +0000
commit1527feb744c7911b6ca482554f0399d3ef0ebfdc (patch)
tree7393ee6defa8951afafe90f0c180e7c0f4f1db70 /editors/code/src
parentfbb8b884a2dbc3ced720c84f4604466e223f6d69 (diff)
parent5dab5e737909532e4a65390541393af6ee72f65b (diff)
downloadrust-1527feb744c7911b6ca482554f0399d3ef0ebfdc.tar.gz
rust-1527feb744c7911b6ca482554f0399d3ef0ebfdc.zip
Merge #4601
4601: Introduce `toggle inlay hints` vscode command r=matklad a=Veetaha

Users now can assign a shortcut for this command
via the general vscode
keybindings ui or `keybindings.json` file

<details>
<summary>Demo</summary>

![demo](https://user-images.githubusercontent.com/36276403/82768941-b4fd1c80-9e3a-11ea-9d5b-a40fa1e4dbc6.gif)

</details>

<details>
<summary>Howto assign a shortcut</summary>

![demo2](https://user-images.githubusercontent.com/36276403/82769350-c8a98280-9e3c-11ea-8a95-1266a539826d.gif)


</details>

Closes: #4599

Co-authored-by: veetaha <veetaha2@gmail.com>
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands/index.ts1
-rw-r--r--editors/code/src/commands/toggle_inlay_hints.ts11
-rw-r--r--editors/code/src/config.ts2
-rw-r--r--editors/code/src/main.ts1
4 files changed, 14 insertions, 1 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index abb53a24815..c2a232d5fd8 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -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
index 00000000000..7606af8d0cb
--- /dev/null
+++ b/editors/code/src/commands/toggle_inlay_hints.ts
@@ -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);
+    };
+}
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index ee294fbe312..e8abf8284eb 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -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",
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 3405634f339..0e5a206410e 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -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);