Remove special casing in command factory (revert changes in ctx.ts), update main.createCommands instead

This commit is contained in:
Mark Pots 2025-06-24 11:56:22 +02:00
parent 92da17cfa5
commit e2e24f84c4
2 changed files with 3 additions and 12 deletions

View file

@ -1,7 +1,6 @@
import * as vscode from "vscode";
import type * as lc from "vscode-languageclient/node";
import * as ra from "./lsp_ext";
import * as commands from "./commands";
import { Config, prepareVSCodeConfig } from "./config";
import { createClient } from "./client";
@ -463,17 +462,9 @@ export class Ctx implements RustAnalyzerExtensionApi {
for (const [name, factory] of Object.entries(this.commandFactories)) {
const fullName = `rust-analyzer.${name}`;
let callback;
if (isClientRunning(this)) {
if (name === "run") {
// Special case: support optional argument for `run`
callback = (mode?: "cursor") => {
return commands.run(this, mode)();
};
} else {
// we asserted that `client` is defined
callback = factory.enabled(this);
}
// we asserted that `client` is defined
callback = factory.enabled(this);
} else if (factory.disabled) {
callback = factory.disabled(this);
} else {

View file

@ -167,7 +167,7 @@ function createCommands(): Record<string, CommandFactory> {
viewCrateGraph: { enabled: commands.viewCrateGraph },
viewFullCrateGraph: { enabled: commands.viewFullCrateGraph },
expandMacro: { enabled: commands.expandMacro },
run: { enabled: commands.run },
run: { enabled: (ctx) => (mode?: "cursor") => commands.run(ctx, mode)() },
copyRunCommandLine: { enabled: commands.copyRunCommandLine },
debug: { enabled: commands.debug },
newDebugConfig: { enabled: commands.newDebugConfig },