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
This commit is contained in:
veetaha 2020-05-25 03:47:33 +03:00
parent fbb8b884a2
commit 5dab5e7379
6 changed files with 25 additions and 1 deletions

View file

@ -93,6 +93,12 @@ Shows internal statistic about memory usage of rust-analyzer.
Show current rust-analyzer version. 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 #### Run Garbage Collection
Manually triggers GC. Manually triggers GC.

View file

@ -166,6 +166,11 @@
"command": "rust-analyzer.serverVersion", "command": "rust-analyzer.serverVersion",
"title": "Show RA Version", "title": "Show RA Version",
"category": "Rust Analyzer" "category": "Rust Analyzer"
},
{
"command": "rust-analyzer.toggleInlayHints",
"title": "Toggle inlay hints",
"category": "Rust Analyzer"
} }
], ],
"keybindings": [ "keybindings": [

View file

@ -16,6 +16,7 @@ export * from './expand_macro';
export * from './runnables'; export * from './runnables';
export * from './ssr'; export * from './ssr';
export * from './server_version'; export * from './server_version';
export * from './toggle_inlay_hints';
export function collectGarbage(ctx: Ctx): Cmd { export function collectGarbage(ctx: Ctx): Cmd {
return async () => ctx.client.sendRequest(ra.collectGarbage, null); return async () => ctx.client.sendRequest(ra.collectGarbage, null);

View file

@ -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);
};
}

View file

@ -8,7 +8,7 @@ export const NIGHTLY_TAG = "nightly";
export class Config { export class Config {
readonly extensionId = "matklad.rust-analyzer"; readonly extensionId = "matklad.rust-analyzer";
private readonly rootSection = "rust-analyzer"; readonly rootSection = "rust-analyzer";
private readonly requiresReloadOpts = [ private readonly requiresReloadOpts = [
"serverPath", "serverPath",
"cargo", "cargo",

View file

@ -86,6 +86,7 @@ export async function activate(context: vscode.ExtensionContext) {
ctx.registerCommand('ssr', commands.ssr); ctx.registerCommand('ssr', commands.ssr);
ctx.registerCommand('serverVersion', commands.serverVersion); ctx.registerCommand('serverVersion', commands.serverVersion);
ctx.registerCommand('toggleInlayHints', commands.toggleInlayHints);
// Internal commands which are invoked by the server. // Internal commands which are invoked by the server.
ctx.registerCommand('runSingle', commands.runSingle); ctx.registerCommand('runSingle', commands.runSingle);