diff options
author | Ville Penttinen <[email protected]> | 2019-03-03 20:03:37 +0000 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-03-03 20:03:37 +0000 |
commit | 0db95fc812d2c839e847527b774dfda170266cec (patch) | |
tree | 89f05d9798cf77a2798ff5fd643649cbb9071e77 /editors/code | |
parent | 1b4e0ec1c868c7f2a0eef1e59bfa382db85a6900 (diff) |
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')
-rw-r--r-- | editors/code/src/events/change_active_text_editor.ts | 39 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 4 |
2 files changed, 26 insertions, 17 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 @@ | |||
1 | import { TextEditor } from 'vscode'; | 1 | import { TextEditor } from 'vscode'; |
2 | import { TextDocumentIdentifier } from 'vscode-languageclient'; | 2 | import { TextDocumentIdentifier } from 'vscode-languageclient'; |
3 | 3 | ||
4 | import { | ||
5 | SyntaxTreeContentProvider, | ||
6 | syntaxTreeUri | ||
7 | } from '../commands/syntaxTree'; | ||
4 | import { Decoration } from '../highlighting'; | 8 | import { Decoration } from '../highlighting'; |
5 | import { Server } from '../server'; | 9 | import { Server } from '../server'; |
6 | 10 | ||
7 | export async function handle(editor: TextEditor | undefined) { | 11 | export 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/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) { | |||
94 | notifications.publishDecorations.handle | 94 | notifications.publishDecorations.handle |
95 | ] | 95 | ] |
96 | ]; | 96 | ]; |
97 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); | ||
97 | 98 | ||
98 | // The events below are plain old javascript events, triggered and handled by vscode | 99 | // The events below are plain old javascript events, triggered and handled by vscode |
99 | vscode.window.onDidChangeActiveTextEditor( | 100 | vscode.window.onDidChangeActiveTextEditor( |
100 | events.changeActiveTextEditor.handle | 101 | events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider) |
101 | ); | 102 | ); |
102 | 103 | ||
103 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); | ||
104 | disposeOnDeactivation( | 104 | disposeOnDeactivation( |
105 | vscode.workspace.registerTextDocumentContentProvider( | 105 | vscode.workspace.registerTextDocumentContentProvider( |
106 | 'rust-analyzer', | 106 | 'rust-analyzer', |