mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Start new ctx module
This commit is contained in:
parent
9cad88dd95
commit
e53ccb6e99
4 changed files with 63 additions and 20 deletions
30
editors/code/src/ctx.ts
Normal file
30
editors/code/src/ctx.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import { Server } from './server';
|
||||
|
||||
|
||||
export class Ctx {
|
||||
private extCtx: vscode.ExtensionContext
|
||||
|
||||
constructor(extCtx: vscode.ExtensionContext) {
|
||||
this.extCtx = extCtx
|
||||
}
|
||||
|
||||
get client(): lc.LanguageClient {
|
||||
return Server.client
|
||||
}
|
||||
|
||||
registerCommand(
|
||||
name: string,
|
||||
factory: (ctx: Ctx) => () => Promise<vscode.TextEditor>,
|
||||
) {
|
||||
const fullName = `rust-analyzer.${name}`
|
||||
const cmd = factory(this);
|
||||
const d = vscode.commands.registerCommand(fullName, cmd);
|
||||
this.pushCleanup(d);
|
||||
}
|
||||
|
||||
pushCleanup(d: { dispose(): any }) {
|
||||
this.extCtx.subscriptions.push(d)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue