diff options
-rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 27 |
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"; | |||
12 | export function syntaxTree(ctx: Ctx): Cmd { | 12 | export 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 | ||
38 | class TextDocumentContentProvider implements vscode.TextDocumentContentProvider, Disposable { | 38 | class 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) { |