diff --git a/docs/user/features.md b/docs/user/features.md index 340bce8355..12ecdec136 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 21039ced88..2f14eaebd2 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 abb53a2481..c2a232d5fd 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 0000000000..7606af8d0c --- /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 ee294fbe31..e8abf8284e 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 3405634f33..0e5a206410 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);