aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
authorveetaha <[email protected]>2020-03-31 14:57:03 +0100
committerveetaha <[email protected]>2020-03-31 14:57:03 +0100
commit4fbca1c64df789c1fa46d083d6555b0d0b3107c0 (patch)
tree7fe1e7f7779a9da25a1bf79883944dc9cae0ac66 /editors/code/src
parent09a760e52e20dcd79d902b05065934615cc4d56b (diff)
vscode: use ctx.subscriptions instead of local .disposables
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands/syntax_tree.ts27
1 files changed, 12 insertions, 15 deletions
diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts
index 21ecf2661..eba511193 100644
--- a/editors/code/src/commands/syntax_tree.ts
+++ b/editors/code/src/commands/syntax_tree.ts
@@ -12,8 +12,8 @@ const AST_FILE_SCHEME = "rust-analyzer";
12export function syntaxTree(ctx: Ctx): Cmd { 12export function syntaxTree(ctx: Ctx): Cmd {
13 const tdcp = new TextDocumentContentProvider(ctx); 13 const tdcp = new TextDocumentContentProvider(ctx);
14 14
15 ctx.pushCleanup(new AstInspector); 15 void new AstInspector(ctx);
16 ctx.pushCleanup(tdcp); 16
17 ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider(AST_FILE_SCHEME, tdcp)); 17 ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider(AST_FILE_SCHEME, tdcp));
18 18
19 return async () => { 19 return async () => {
@@ -35,17 +35,14 @@ export function syntaxTree(ctx: Ctx): Cmd {
35 }; 35 };
36} 36}
37 37
38class TextDocumentContentProvider implements vscode.TextDocumentContentProvider, Disposable { 38class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
39 readonly uri = vscode.Uri.parse('rust-analyzer://syntaxtree'); 39 readonly uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
40 readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>(); 40 readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
41 private readonly disposables: Disposable[] = []; 41
42 42
43 constructor(private readonly ctx: Ctx) { 43 constructor(private readonly ctx: Ctx) {
44 vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, this.disposables); 44 vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, ctx.subscriptions);
45 vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, this.disposables); 45 vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, ctx.subscriptions);
46 }
47 dispose() {
48 this.disposables.forEach(d => d.dispose());
49 } 46 }
50 47
51 private onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) { 48 private onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) {
@@ -88,16 +85,16 @@ class AstInspector implements vscode.HoverProvider, Disposable {
88 border: "#ffffff 1px solid", 85 border: "#ffffff 1px solid",
89 }); 86 });
90 private rustEditor: undefined | RustEditor; 87 private rustEditor: undefined | RustEditor;
91 private readonly disposables: Disposable[] = [];
92 88
93 constructor() { 89 constructor(ctx: Ctx) {
94 this.disposables.push(vscode.languages.registerHoverProvider({ scheme: AST_FILE_SCHEME }, this)); 90 ctx.pushCleanup(vscode.languages.registerHoverProvider({ scheme: AST_FILE_SCHEME }, this));
95 vscode.workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, this.disposables); 91 vscode.workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, ctx.subscriptions);
96 vscode.window.onDidChangeVisibleTextEditors(this.onDidChangeVisibleTextEditors, this, this.disposables); 92 vscode.window.onDidChangeVisibleTextEditors(this.onDidChangeVisibleTextEditors, this, ctx.subscriptions);
93
94 ctx.pushCleanup(this);
97 } 95 }
98 dispose() { 96 dispose() {
99 this.setRustEditor(undefined); 97 this.setRustEditor(undefined);
100 this.disposables.forEach(d => d.dispose());
101 } 98 }
102 99
103 private onDidCloseTextDocument(doc: vscode.TextDocument) { 100 private onDidCloseTextDocument(doc: vscode.TextDocument) {