From 0db95fc812d2c839e847527b774dfda170266cec Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sun, 3 Mar 2019 22:03:37 +0200 Subject: Allow syntax tree to update when changing files Previously when using the file based syntax tree, it would not update until a change had been made in the new file. Now we automatically update the syntax tree to match the current file. --- .../code/src/events/change_active_text_editor.ts | 39 +++++++++++++--------- editors/code/src/extension.ts | 4 +-- 2 files changed, 26 insertions(+), 17 deletions(-) (limited to 'editors/code') 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 @@ import { TextEditor } from 'vscode'; import { TextDocumentIdentifier } from 'vscode-languageclient'; +import { + SyntaxTreeContentProvider, + syntaxTreeUri +} from '../commands/syntaxTree'; import { Decoration } from '../highlighting'; import { Server } from '../server'; -export async function handle(editor: TextEditor | undefined) { - if ( - !Server.config.highlightingOn || - !editor || - editor.document.languageId !== 'rust' - ) { - return; - } - const params: TextDocumentIdentifier = { - uri: editor.document.uri.toString() +export function makeHandler(syntaxTreeProvider: SyntaxTreeContentProvider) { + return async function handle(editor: TextEditor | undefined) { + if (!editor || editor.document.languageId !== 'rust') { + return; + } + + syntaxTreeProvider.eventEmitter.fire(syntaxTreeUri); + + if (!Server.config.highlightingOn) { + return; + } + + const params: TextDocumentIdentifier = { + uri: editor.document.uri.toString() + }; + const decorations = await Server.client.sendRequest( + 'rust-analyzer/decorationsRequest', + params + ); + Server.highlighter.setHighlights(editor, decorations); }; - const decorations = await Server.client.sendRequest( - 'rust-analyzer/decorationsRequest', - params - ); - Server.highlighter.setHighlights(editor, decorations); } diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 894334c55..941beba18 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -94,13 +94,13 @@ export function activate(context: vscode.ExtensionContext) { notifications.publishDecorations.handle ] ]; + const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); // The events below are plain old javascript events, triggered and handled by vscode vscode.window.onDidChangeActiveTextEditor( - events.changeActiveTextEditor.handle + events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider) ); - const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); disposeOnDeactivation( vscode.workspace.registerTextDocumentContentProvider( 'rust-analyzer', -- cgit v1.2.3