diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-01-01 12:44:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-01 12:44:55 +0000 |
| commit | 854caf37d685b9490f35df3cba8b00761a992f3b (patch) | |
| tree | 5ef576faedbe7a01da40b27e1f3d947bf2a3b30d /src/tools/rust-analyzer/editors/code | |
| parent | 1334961586ca72445aa8548c103bb272a0c688fe (diff) | |
| parent | dbf07bab76c8222cf357d622b34e132cfb2059b1 (diff) | |
Merge pull request #18757 from roife/fix-17812
feat: support updating snapshot tests with codelens/hovering/runnables
Diffstat (limited to 'src/tools/rust-analyzer/editors/code')
| -rw-r--r-- | src/tools/rust-analyzer/editors/code/package.json | 25 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/editors/code/src/commands.ts | 26 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/editors/code/src/config.ts | 7 |
3 files changed, 58 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/editors/code/package.json b/src/tools/rust-analyzer/editors/code/package.json index b9249e9ac8b..426414becb3 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." } } }, @@ -1518,6 +1523,16 @@ { "title": "hover", "properties": { + "rust-analyzer.hover.actions.updateTest.enable": { + "markdownDescription": "Whether to show `Update Test` action. Only applies when\n`#rust-analyzer.hover.actions.enable#` and `#rust-analyzer.hover.actions.run.enable#` are set.", + "default": true, + "type": "boolean" + } + } + }, + { + "title": "hover", + "properties": { "rust-analyzer.hover.documentation.enable": { "markdownDescription": "Whether to show documentation on hover.", "default": true, @@ -2296,6 +2311,16 @@ } }, { + "title": "lens", + "properties": { + "rust-analyzer.lens.updateTest.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/commands.ts b/src/tools/rust-analyzer/editors/code/src/commands.ts index 7ebc186a3ea..73e39c900e7 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)") { + await 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 { |
