diff options
| author | Ville Penttinen <villem.penttinen@gmail.com> | 2019-03-03 22:03:37 +0200 |
|---|---|---|
| committer | Ville Penttinen <villem.penttinen@gmail.com> | 2019-03-03 22:03:37 +0200 |
| commit | 0db95fc812d2c839e847527b774dfda170266cec (patch) | |
| tree | 89f05d9798cf77a2798ff5fd643649cbb9071e77 /editors/code/src/events | |
| parent | 1b4e0ec1c868c7f2a0eef1e59bfa382db85a6900 (diff) | |
| download | rust-0db95fc812d2c839e847527b774dfda170266cec.tar.gz rust-0db95fc812d2c839e847527b774dfda170266cec.zip | |
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.
Diffstat (limited to 'editors/code/src/events')
| -rw-r--r-- | editors/code/src/events/change_active_text_editor.ts | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts index af295b2ecba..64be562250e 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<Decoration[]>( + 'rust-analyzer/decorationsRequest', + params + ); + Server.highlighter.setHighlights(editor, decorations); }; - const decorations = await Server.client.sendRequest<Decoration[]>( - 'rust-analyzer/decorationsRequest', - params - ); - Server.highlighter.setHighlights(editor, decorations); } |
