From 5dab5e737909532e4a65390541393af6ee72f65b Mon Sep 17 00:00:00 2001 From: veetaha Date: Mon, 25 May 2020 03:47:33 +0300 Subject: Introduce `toggle inlay hints` vscode command 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 | 6 ++++++ editors/code/package.json | 5 +++++ editors/code/src/commands/index.ts | 1 + editors/code/src/commands/toggle_inlay_hints.ts | 11 +++++++++++ editors/code/src/config.ts | 2 +- editors/code/src/main.ts | 1 + 6 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 editors/code/src/commands/toggle_inlay_hints.ts diff --git a/docs/user/features.md b/docs/user/features.md index 340bce835..12ecdec13 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -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. diff --git a/editors/code/package.json b/editors/code/package.json index 21039ced8..2f14eaebd 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -166,6 +166,11 @@ "command": "rust-analyzer.serverVersion", "title": "Show RA Version", "category": "Rust Analyzer" + }, + { + "command": "rust-analyzer.toggleInlayHints", + "title": "Toggle inlay hints", + "category": "Rust Analyzer" } ], "keybindings": [ diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index abb53a248..c2a232d5f 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 000000000..7606af8d0 --- /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 ee294fbe3..e8abf8284 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 3405634f3..0e5a20641 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); -- cgit v1.2.3