aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/events
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-04 10:50:40 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-04 10:50:40 +0000
commit698aa9b3f6420351a41a3fb4819b871fec3c891c (patch)
treec782b2b62dcfaa253b8ed55824772ea7bf8fa16d /editors/code/src/events
parent17aaece6b39c2fb525be0eccce4626fc622e8236 (diff)
parent1ef2c0613134633ef0fe0d515f7d416e482f07fb (diff)
Merge #924
924: Improve show syntax tree r=matklad a=vipentti This implements some of the features discussed in #820. You can now select a range of syntax in a file and then use "Show Syntax Tree" to show its syntax. In addition you can select a range of syntax that is inside a string (typically test cases) and show its syntax as well. Previous behavior is still available, simply use "Show Syntax Tree" without a selection, and you get the live updating syntax tree. Additionally now the live updating tree will update when the active file is changed. Previously you had to type something in the new file to get the syntax tree to update. Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'editors/code/src/events')
-rw-r--r--editors/code/src/events/change_active_text_editor.ts39
-rw-r--r--editors/code/src/events/change_text_document.ts10
2 files changed, 28 insertions, 21 deletions
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts
index af295b2ec..64be56225 100644
--- a/editors/code/src/events/change_active_text_editor.ts
+++ b/editors/code/src/events/change_active_text_editor.ts
@@ -1,23 +1,32 @@
1import { TextEditor } from 'vscode'; 1import { TextEditor } from 'vscode';
2import { TextDocumentIdentifier } from 'vscode-languageclient'; 2import { TextDocumentIdentifier } from 'vscode-languageclient';
3 3
4import {
5 SyntaxTreeContentProvider,
6 syntaxTreeUri
7} from '../commands/syntaxTree';
4import { Decoration } from '../highlighting'; 8import { Decoration } from '../highlighting';
5import { Server } from '../server'; 9import { Server } from '../server';
6 10
7export async function handle(editor: TextEditor | undefined) { 11export function makeHandler(syntaxTreeProvider: SyntaxTreeContentProvider) {
8 if ( 12 return async function handle(editor: TextEditor | undefined) {
9 !Server.config.highlightingOn || 13 if (!editor || editor.document.languageId !== 'rust') {
10 !editor || 14 return;
11 editor.document.languageId !== 'rust' 15 }
12 ) { 16
13 return; 17 syntaxTreeProvider.eventEmitter.fire(syntaxTreeUri);
14 } 18
15 const params: TextDocumentIdentifier = { 19 if (!Server.config.highlightingOn) {
16 uri: editor.document.uri.toString() 20 return;
21 }
22
23 const params: TextDocumentIdentifier = {
24 uri: editor.document.uri.toString()
25 };
26 const decorations = await Server.client.sendRequest<Decoration[]>(
27 'rust-analyzer/decorationsRequest',
28 params
29 );
30 Server.highlighter.setHighlights(editor, decorations);
17 }; 31 };
18 const decorations = await Server.client.sendRequest<Decoration[]>(
19 'rust-analyzer/decorationsRequest',
20 params
21 );
22 Server.highlighter.setHighlights(editor, decorations);
23} 32}
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}