diff options
| author | roife <roifewu@gmail.com> | 2024-12-25 15:56:06 +0800 |
|---|---|---|
| committer | roife <roifewu@gmail.com> | 2024-12-26 19:50:32 +0800 |
| commit | 60b4ed5bd36e88b454c8833f76a7481e01cca66a (patch) | |
| tree | 1cfbd1609908ce2780ce0ed6ca827bc836c14d30 /src/tools/rust-analyzer/editors/code | |
| parent | 08677cb70dce85e1ad4f0e5a5e3dfecf77ec16fd (diff) | |
feat: support UpdateTest in codelens
Diffstat (limited to 'src/tools/rust-analyzer/editors/code')
5 files changed, 60 insertions, 13 deletions
diff --git a/src/tools/rust-analyzer/editors/code/package.json b/src/tools/rust-analyzer/editors/code/package.json index b9249e9ac8b..7dc26c44366 100644 --- a/src/tools/rust-analyzer/editors/code/package.json +++ b/src/tools/rust-analyzer/editors/code/package.json @@ -407,6 +407,11 @@ "$rustc" ], "markdownDescription": "Problem matchers to use for `rust-analyzer.run` command, eg `[\"$rustc\", \"$rust-panic\"]`." + }, + "rust-analyzer.runnables.askBeforeUpdateTest": { + "type": "boolean", + "default": true, + "markdownDescription": "Ask before updating the test when running it." } } }, @@ -2296,6 +2301,16 @@ } }, { + "title": "lens", + "properties": { + "rust-analyzer.lens.update.test.enable": { + "markdownDescription": "Whether to show `Update Test` lens. Only applies when\n`#rust-analyzer.lens.enable#` and `#rust-analyzer.lens.run.enable#` are set.", + "default": true, + "type": "boolean" + } + } + }, + { "title": "general", "properties": { "rust-analyzer.linkedProjects": { diff --git a/src/tools/rust-analyzer/editors/code/src/client.ts b/src/tools/rust-analyzer/editors/code/src/client.ts index eac7b849fdb..5d33d7a6adb 100644 --- a/src/tools/rust-analyzer/editors/code/src/client.ts +++ b/src/tools/rust-analyzer/editors/code/src/client.ts @@ -348,9 +348,9 @@ class ExperimentalFeatures implements lc.StaticFeature { initialize( _capabilities: lc.ServerCapabilities, _documentSelector: lc.DocumentSelector | undefined, - ): void {} - dispose(): void {} - clear(): void {} + ): void { } + dispose(): void { } + clear(): void { } } class OverrideFeatures implements lc.StaticFeature { @@ -368,9 +368,9 @@ class OverrideFeatures implements lc.StaticFeature { initialize( _capabilities: lc.ServerCapabilities, _documentSelector: lc.DocumentSelector | undefined, - ): void {} - dispose(): void {} - clear(): void {} + ): void { } + dispose(): void { } + clear(): void { } } function isCodeActionWithoutEditsAndCommands(value: any): boolean { @@ -398,9 +398,8 @@ export let HOVER_REFERENCE_COMMAND: ra.CommandLink[] = []; function renderCommand(cmd: ra.CommandLink): string { HOVER_REFERENCE_COMMAND.push(cmd); - return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy?${ - HOVER_REFERENCE_COMMAND.length - 1 - } '${cmd.tooltip}')`; + return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy?${HOVER_REFERENCE_COMMAND.length - 1 + } '${cmd.tooltip}')`; } function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString { diff --git a/src/tools/rust-analyzer/editors/code/src/commands.ts b/src/tools/rust-analyzer/editors/code/src/commands.ts index 7ebc186a3ea..dc35fddf49e 100644 --- a/src/tools/rust-analyzer/editors/code/src/commands.ts +++ b/src/tools/rust-analyzer/editors/code/src/commands.ts @@ -1139,11 +1139,37 @@ export function peekTests(ctx: CtxInit): Cmd { }; } +function isUpdatingTest(runnable: ra.Runnable): boolean { + if (!isCargoRunnableArgs(runnable.args)) { + return false; + } + + const env = runnable.args.environment; + return env ? ['UPDATE_EXPECT', 'INSTA_UPDATE', 'SNAPSHOTS'].some(key => key in env) : false; +} + export function runSingle(ctx: CtxInit): Cmd { return async (runnable: ra.Runnable) => { const editor = ctx.activeRustEditor; if (!editor) return; + if (isUpdatingTest(runnable) && ctx.config.askBeforeUpdateTest) { + const selection = await vscode.window.showInformationMessage( + 'rust-analyzer', + { detail: 'Do you want to update tests?', modal: true }, + 'Update Now', + 'Update (and Don\'t ask again)', + ); + + if (selection !== 'Update Now' && selection !== 'Update (and Don\'t ask again)') { + return; + } + + if (selection === 'Update (and Don\'t ask again)') { + ctx.config.setAskBeforeUpdateTest(false); + } + } + const task = await createTaskFromRunnable(runnable, ctx.config); task.group = vscode.TaskGroup.Build; task.presentationOptions = { diff --git a/src/tools/rust-analyzer/editors/code/src/config.ts b/src/tools/rust-analyzer/editors/code/src/config.ts index a97d4beab51..720c473c5b4 100644 --- a/src/tools/rust-analyzer/editors/code/src/config.ts +++ b/src/tools/rust-analyzer/editors/code/src/config.ts @@ -362,6 +362,13 @@ export class Config { get initializeStopped() { return this.get<boolean>("initializeStopped"); } + + get askBeforeUpdateTest() { + return this.get<boolean>("runnables.askBeforeUpdateTest"); + } + async setAskBeforeUpdateTest(value: boolean) { + await this.cfg.update("runnables.askBeforeUpdateTest", value, true); + } } export function prepareVSCodeConfig<T>(resp: T): T { diff --git a/src/tools/rust-analyzer/editors/code/src/main.ts b/src/tools/rust-analyzer/editors/code/src/main.ts index fdf43f66f94..478673d5915 100644 --- a/src/tools/rust-analyzer/editors/code/src/main.ts +++ b/src/tools/rust-analyzer/editors/code/src/main.ts @@ -148,7 +148,7 @@ function createCommands(): Record<string, CommandFactory> { health: "stopped", }); }, - disabled: (_) => async () => {}, + disabled: (_) => async () => { }, }, analyzerStatus: { enabled: commands.analyzerStatus }, @@ -207,10 +207,10 @@ function checkConflictingExtensions() { vscode.window .showWarningMessage( `You have both the rust-analyzer (rust-lang.rust-analyzer) and Rust (rust-lang.rust) ` + - "plugins enabled. These are known to conflict and cause various functions of " + - "both plugins to not work correctly. You should disable one of them.", + "plugins enabled. These are known to conflict and cause various functions of " + + "both plugins to not work correctly. You should disable one of them.", "Got it", ) - .then(() => {}, console.error); + .then(() => { }, console.error); } } |
