From 7646dc046eb562276231de8ec6a4df1bc691cafc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 20:29:21 +0100 Subject: Encapsulate highlighting activation --- editors/code/src/highlighting.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'editors/code/src/highlighting.ts') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 4e224a54c..ced78adc1 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -1,10 +1,30 @@ -import seedrandom = require('seedrandom'); import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; +import * as seedrandom from 'seedrandom'; + import * as scopes from './scopes'; import * as scopesMapper from './scopes_mapper'; import { Server } from './server'; +import { Ctx } from './ctx'; + +export function activateHighlighting(ctx: Ctx) { + vscode.window.onDidChangeActiveTextEditor( + async (editor: vscode.TextEditor | undefined) => { + if (!editor || editor.document.languageId !== 'rust') return; + if (!Server.config.highlightingOn) return; + + const params: lc.TextDocumentIdentifier = { + uri: editor.document.uri.toString(), + }; + const decorations = await ctx.client.sendRequest( + 'rust-analyzer/decorationsRequest', + params, + ); + Server.highlighter.setHighlights(editor, decorations); + }, + ); +} export interface Decoration { range: lc.Range; -- cgit v1.2.3