aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/events/change_active_text_editor.ts
blob: 4384ee56768c178a62476ec8e760a13ac38e364a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { TextEditor } from 'vscode';
import { TextDocumentIdentifier } from 'vscode-languageclient';
import { Decoration } from '../highlighting';
import { Server } from '../server';

export function makeHandler() {
    return async function handle(editor: TextEditor | undefined) {
        if (!editor || editor.document.languageId !== 'rust') {
            return;
        }

        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);
    };
}