diff options
Diffstat (limited to 'editors/code/src/events')
-rw-r--r-- | editors/code/src/events/change_active_text_editor.ts | 14 | ||||
-rw-r--r-- | editors/code/src/events/change_text_document.ts | 19 |
2 files changed, 33 insertions, 0 deletions
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts new file mode 100644 index 000000000..bbdd53098 --- /dev/null +++ b/editors/code/src/events/change_active_text_editor.ts | |||
@@ -0,0 +1,14 @@ | |||
1 | import { TextEditor } from "vscode"; | ||
2 | import { TextDocumentIdentifier } from "vscode-languageclient"; | ||
3 | |||
4 | import { Server } from "../server"; | ||
5 | import { Decoration } from "../highlighting"; | ||
6 | |||
7 | export async function handle(editor: TextEditor | undefined) { | ||
8 | if (!Server.config.highlightingOn || !editor || editor.document.languageId != 'rust') return | ||
9 | let params: TextDocumentIdentifier = { | ||
10 | uri: editor.document.uri.toString() | ||
11 | } | ||
12 | let decorations = await Server.client.sendRequest<Decoration[]>("m/decorationsRequest", params) | ||
13 | Server.highlighter.setHighlights(editor, decorations) | ||
14 | } \ No newline at end of file | ||
diff --git a/editors/code/src/events/change_text_document.ts b/editors/code/src/events/change_text_document.ts new file mode 100644 index 000000000..83ee6c9ee --- /dev/null +++ b/editors/code/src/events/change_text_document.ts | |||
@@ -0,0 +1,19 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | |||
3 | import { syntaxTreeUri, TextDocumentContentProvider } from '../commands/syntaxTree'; | ||
4 | |||
5 | export function createHandler(textDocumentContentProvider: TextDocumentContentProvider) { | ||
6 | return (event: vscode.TextDocumentChangeEvent) => { | ||
7 | let doc = event.document | ||
8 | if (doc.languageId != "rust") return | ||
9 | afterLs(() => { | ||
10 | textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri); | ||
11 | }) | ||
12 | } | ||
13 | } | ||
14 | |||
15 | // We need to order this after LS updates, but there's no API for that. | ||
16 | // Hence, good old setTimeout. | ||
17 | function afterLs(f: () => any) { | ||
18 | setTimeout(f, 10) | ||
19 | } | ||