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>
This commit is contained in:
bors[bot] 2020-05-25 07:14:43 +00:00 committed by GitHub
commit 1527feb744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.
#### 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.

View File

@ -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": [

View 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);

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 {
readonly extensionId = "matklad.rust-analyzer";
private readonly rootSection = "rust-analyzer";
readonly rootSection = "rust-analyzer";
private readonly requiresReloadOpts = [
"serverPath",
"cargo",

View 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);