aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands/syntaxTree.ts4
-rw-r--r--editors/code/src/events/change_text_document.ts10
-rw-r--r--editors/code/src/extension.ts10
3 files changed, 11 insertions, 13 deletions
diff --git a/editors/code/src/commands/syntaxTree.ts b/editors/code/src/commands/syntaxTree.ts
index 7200ae823..2f50fe14b 100644
--- a/editors/code/src/commands/syntaxTree.ts
+++ b/editors/code/src/commands/syntaxTree.ts
@@ -5,7 +5,7 @@ import { Server } from '../server';
5 5
6export const syntaxTreeUri = vscode.Uri.parse('rust-analyzer://syntaxtree'); 6export const syntaxTreeUri = vscode.Uri.parse('rust-analyzer://syntaxtree');
7 7
8export class TextDocumentContentProvider 8export class SyntaxTreeContentProvider
9 implements vscode.TextDocumentContentProvider { 9 implements vscode.TextDocumentContentProvider {
10 public eventEmitter = new vscode.EventEmitter<vscode.Uri>(); 10 public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
11 public syntaxTree: string = 'Not available'; 11 public syntaxTree: string = 'Not available';
@@ -54,7 +54,7 @@ type SyntaxTreeResult = string;
54// Opens the virtual file that will show the syntax tree 54// Opens the virtual file that will show the syntax tree
55// 55//
56// The contents of the file come from the `TextDocumentContentProvider` 56// The contents of the file come from the `TextDocumentContentProvider`
57export function createHandle(provider: TextDocumentContentProvider) { 57export function createHandle(provider: SyntaxTreeContentProvider) {
58 return async () => { 58 return async () => {
59 const editor = vscode.window.activeTextEditor; 59 const editor = vscode.window.activeTextEditor;
60 const rangeEnabled = !!(editor && !editor.selection.isEmpty); 60 const rangeEnabled = !!(editor && !editor.selection.isEmpty);
diff --git a/editors/code/src/events/change_text_document.ts b/editors/code/src/events/change_text_document.ts
index 6be057245..89488bc61 100644
--- a/editors/code/src/events/change_text_document.ts
+++ b/editors/code/src/events/change_text_document.ts
@@ -1,20 +1,18 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { 3import {
4 syntaxTreeUri, 4 SyntaxTreeContentProvider,
5 TextDocumentContentProvider 5 syntaxTreeUri
6} from '../commands/syntaxTree'; 6} from '../commands/syntaxTree';
7 7
8export function createHandler( 8export function createHandler(syntaxTreeProvider: SyntaxTreeContentProvider) {
9 textDocumentContentProvider: TextDocumentContentProvider
10) {
11 return (event: vscode.TextDocumentChangeEvent) => { 9 return (event: vscode.TextDocumentChangeEvent) => {
12 const doc = event.document; 10 const doc = event.document;
13 if (doc.languageId !== 'rust') { 11 if (doc.languageId !== 'rust') {
14 return; 12 return;
15 } 13 }
16 afterLs(() => { 14 afterLs(() => {
17 textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri); 15 syntaxTreeProvider.eventEmitter.fire(syntaxTreeUri);
18 }); 16 });
19 }; 17 };
20} 18}
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 5134bb258..894334c55 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3 3
4import * as commands from './commands'; 4import * as commands from './commands';
5import { TextDocumentContentProvider } from './commands/syntaxTree'; 5import { SyntaxTreeContentProvider } from './commands/syntaxTree';
6import * as events from './events'; 6import * as events from './events';
7import * as notifications from './notifications'; 7import * as notifications from './notifications';
8import { Server } from './server'; 8import { Server } from './server';
@@ -100,21 +100,21 @@ export function activate(context: vscode.ExtensionContext) {
100 events.changeActiveTextEditor.handle 100 events.changeActiveTextEditor.handle
101 ); 101 );
102 102
103 const textDocumentContentProvider = new TextDocumentContentProvider(); 103 const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
104 disposeOnDeactivation( 104 disposeOnDeactivation(
105 vscode.workspace.registerTextDocumentContentProvider( 105 vscode.workspace.registerTextDocumentContentProvider(
106 'rust-analyzer', 106 'rust-analyzer',
107 textDocumentContentProvider 107 syntaxTreeContentProvider
108 ) 108 )
109 ); 109 );
110 110
111 registerCommand( 111 registerCommand(
112 'rust-analyzer.syntaxTree', 112 'rust-analyzer.syntaxTree',
113 commands.syntaxTree.createHandle(textDocumentContentProvider) 113 commands.syntaxTree.createHandle(syntaxTreeContentProvider)
114 ); 114 );
115 115
116 vscode.workspace.onDidChangeTextDocument( 116 vscode.workspace.onDidChangeTextDocument(
117 events.changeTextDocument.createHandler(textDocumentContentProvider), 117 events.changeTextDocument.createHandler(syntaxTreeContentProvider),
118 null, 118 null,
119 context.subscriptions 119 context.subscriptions
120 ); 120 );