4499: CodeLens configuration options r=vsrs a=vsrs

This PR
- adds an option to granularly enable\disable all CodeLens, just like the TypeScript extension.
- fixes a minor bug for doctests. It makes no sense to show `Debug` lens for them as cargo `Can't skip running doc tests with --no-run`.

Co-authored-by: vsrs <vit@conrlab.com>
This commit is contained in:
bors[bot]
2020-05-18 07:37:04 +00:00
committed by GitHub
5 changed files with 185 additions and 80 deletions

View File

@@ -443,6 +443,26 @@
"type": "object",
"default": {},
"description": "Optional settings passed to the debug engine. Example:\n{ \"lldb\": { \"terminal\":\"external\"} }"
},
"rust-analyzer.lens.enable": {
"description": "Whether to show CodeLens in Rust files.",
"type": "boolean",
"default": true
},
"rust-analyzer.lens.run": {
"markdownDescription": "Whether to show Run lens. Only applies when `#rust-analyzer.lens.enable#` is set.",
"type": "boolean",
"default": true
},
"rust-analyzer.lens.debug": {
"markdownDescription": "Whether to show Debug lens. Only applies when `#rust-analyzer.lens.enable#` is set.",
"type": "boolean",
"default": true
},
"rust-analyzer.lens.implementations": {
"markdownDescription": "Whether to show Implementations lens. Only applies when `#rust-analyzer.lens.enable#` is set.",
"type": "boolean",
"default": true
}
}
},

View File

@@ -7,7 +7,7 @@ import { startDebugSession, getDebugConfiguration } from '../debug';
const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }];
async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick, showButtons: boolean = true): Promise<RunnableQuickPick | undefined> {
async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick, debuggeeOnly = false, showButtons: boolean = true): Promise<RunnableQuickPick | undefined> {
const editor = ctx.activeRustEditor;
const client = ctx.client;
if (!editor || !client) return;
@@ -33,9 +33,20 @@ async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick, showBu
) {
continue;
}
if (debuggeeOnly && (r.label.startsWith('doctest') || r.label.startsWith('cargo'))) {
continue;
}
items.push(new RunnableQuickPick(r));
}
if (items.length === 0) {
// it is the debug case, run always has at least 'cargo check ...'
// see crates\rust-analyzer\src\main_loop\handlers.rs, handle_runnables
vscode.window.showErrorMessage("There's no debug target!");
return;
}
return await new Promise((resolve) => {
const disposables: vscode.Disposable[] = [];
const close = (result?: RunnableQuickPick) => {
@@ -107,7 +118,7 @@ export function debug(ctx: Ctx): Cmd {
let prevDebuggee: RunnableQuickPick | undefined;
return async () => {
const item = await selectRunnable(ctx, prevDebuggee);
const item = await selectRunnable(ctx, prevDebuggee, true);
if (!item) return;
item.detail = 'restart';
@@ -147,7 +158,7 @@ async function makeDebugConfig(ctx: Ctx, item: RunnableQuickPick): Promise<void>
export function newDebugConfig(ctx: Ctx): Cmd {
return async () => {
const item = await selectRunnable(ctx, undefined, false);
const item = await selectRunnable(ctx, undefined, true, false);
if (!item) return;
await makeDebugConfig(ctx, item);

View File

@@ -16,6 +16,10 @@ export class Config {
"files",
"highlighting",
"updates.channel",
"lens.enable",
"lens.run",
"lens.debug",
"lens.implementations",
]
.map(opt => `${this.rootSection}.${opt}`);
@@ -119,4 +123,13 @@ export class Config {
sourceFileMap: sourceFileMap
};
}
get lens() {
return {
enable: this.get<boolean>("lens.enable"),
run: this.get<boolean>("lens.run"),
debug: this.get<boolean>("lens.debug"),
implementations: this.get<boolean>("lens.implementations"),
};
}
}