feat: support UpdateTest in codelens

This commit is contained in:
roife 2024-12-25 15:56:06 +08:00
parent dd788255b4
commit edb61b10ab
12 changed files with 204 additions and 57 deletions

View file

@ -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."
}
}
},
@ -2295,6 +2300,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": {

View file

@ -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 {

View file

@ -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 = {

View file

@ -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 {

View file

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