diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-08 20:39:52 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-08 20:39:52 +0100 |
commit | f4ad36e972989c3feed8671d6d6fca0aed37cd8f (patch) | |
tree | f60e1aa4703c3e176315ecd886206848028b8cbf /editors/code/src/events | |
parent | a05e09e9c514878148ddf26aa76d6b9183583d0f (diff) | |
parent | bbf38b9e722e8d6455828ff22242c92219da346d (diff) |
Merge #103
103: WIP: refactor vscode extension r=aochagavia a=aochagavia
Todo:
- [x] Add more comments, so other people can find their way in the codebase
- [x] Resolve remaining tslint suggestions
- [ ] Integrate with CI
@matklad The standard configuration of tslint forbids using `console.log` and `console.error`. Is there any reason we are using those or can I remove them? If they are used for debugging purposes I would prefer to remove them and rely on vscode's excellent debugger.
Co-authored-by: Adolfo OchagavĂa <[email protected]>
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 | ||||
-rw-r--r-- | editors/code/src/events/index.ts | 7 |
3 files changed, 40 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..3440aa0c3 --- /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 { Decoration } from '../highlighting'; | ||
5 | import { Server } from '../server'; | ||
6 | |||
7 | export async function handle(editor: TextEditor | undefined) { | ||
8 | if (!Server.config.highlightingOn || !editor || editor.document.languageId !== 'rust') { return; } | ||
9 | const params: TextDocumentIdentifier = { | ||
10 | uri: editor.document.uri.toString(), | ||
11 | }; | ||
12 | const decorations = await Server.client.sendRequest<Decoration[]>('m/decorationsRequest', params); | ||
13 | Server.highlighter.setHighlights(editor, decorations); | ||
14 | } | ||
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..b3000e026 --- /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 | const 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 | } | ||
diff --git a/editors/code/src/events/index.ts b/editors/code/src/events/index.ts new file mode 100644 index 000000000..b570a7a92 --- /dev/null +++ b/editors/code/src/events/index.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | import * as changeActiveTextEditor from './change_active_text_editor'; | ||
2 | import * as changeTextDocument from './change_text_document'; | ||
3 | |||
4 | export { | ||
5 | changeActiveTextEditor, | ||
6 | changeTextDocument, | ||
7 | }; | ||