mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Refactor applySourceChange
This commit is contained in:
parent
83d2527880
commit
5aebf1081d
7 changed files with 68 additions and 89 deletions
|
@ -27,6 +27,28 @@ export class Ctx {
|
|||
this.pushCleanup(d);
|
||||
}
|
||||
|
||||
overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) {
|
||||
const defaultCmd = `default:${name}`;
|
||||
const override = factory(this);
|
||||
const original = (...args: any[]) =>
|
||||
vscode.commands.executeCommand(defaultCmd, ...args);
|
||||
try {
|
||||
const d = vscode.commands.registerCommand(
|
||||
name,
|
||||
async (...args: any[]) => {
|
||||
if (!(await override(...args))) {
|
||||
return await original(...args);
|
||||
}
|
||||
},
|
||||
);
|
||||
this.pushCleanup(d);
|
||||
} catch (_) {
|
||||
vscode.window.showWarningMessage(
|
||||
'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pushCleanup(d: { dispose(): any }) {
|
||||
this.extCtx.subscriptions.push(d);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue