Skip to content

Commit 4fbca1c

Browse files
committed
vscode: use ctx.subscriptions instead of local .disposables
1 parent 09a760e commit 4fbca1c

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

editors/code/src/commands/syntax_tree.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const AST_FILE_SCHEME = "rust-analyzer";
1212
export function syntaxTree(ctx: Ctx): Cmd {
1313
const tdcp = new TextDocumentContentProvider(ctx);
1414

15-
ctx.pushCleanup(new AstInspector);
16-
ctx.pushCleanup(tdcp);
15+
void new AstInspector(ctx);
16+
1717
ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider(AST_FILE_SCHEME, tdcp));
1818

1919
return async () => {
@@ -35,17 +35,14 @@ export function syntaxTree(ctx: Ctx): Cmd {
3535
};
3636
}
3737

38-
class TextDocumentContentProvider implements vscode.TextDocumentContentProvider, Disposable {
38+
class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
3939
readonly uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
4040
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
41-
private readonly disposables: Disposable[] = [];
41+
4242

4343
constructor(private readonly ctx: Ctx) {
44-
vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, this.disposables);
45-
vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, this.disposables);
46-
}
47-
dispose() {
48-
this.disposables.forEach(d => d.dispose());
44+
vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, ctx.subscriptions);
45+
vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, ctx.subscriptions);
4946
}
5047

5148
private onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) {
@@ -88,16 +85,16 @@ class AstInspector implements vscode.HoverProvider, Disposable {
8885
border: "#ffffff 1px solid",
8986
});
9087
private rustEditor: undefined | RustEditor;
91-
private readonly disposables: Disposable[] = [];
9288

93-
constructor() {
94-
this.disposables.push(vscode.languages.registerHoverProvider({ scheme: AST_FILE_SCHEME }, this));
95-
vscode.workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, this.disposables);
96-
vscode.window.onDidChangeVisibleTextEditors(this.onDidChangeVisibleTextEditors, this, this.disposables);
89+
constructor(ctx: Ctx) {
90+
ctx.pushCleanup(vscode.languages.registerHoverProvider({ scheme: AST_FILE_SCHEME }, this));
91+
vscode.workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, ctx.subscriptions);
92+
vscode.window.onDidChangeVisibleTextEditors(this.onDidChangeVisibleTextEditors, this, ctx.subscriptions);
93+
94+
ctx.pushCleanup(this);
9795
}
9896
dispose() {
9997
this.setRustEditor(undefined);
100-
this.disposables.forEach(d => d.dispose());
10198
}
10299

103100
private onDidCloseTextDocument(doc: vscode.TextDocument) {

0 commit comments

Comments
 (0)