vscode: migrate highlighting to rust-analyzer-api.ts
import * as vscode from 'vscode';
-import * as lc from 'vscode-languageclient';
+import * as ra from './rust-analyzer-api';
import { ColorTheme, TextMateRuleSettings } from './color_theme';
@@ -8,11 +8,8 @@ import { sendRequestWithRetry } from './util';
export function activateHighlighting(ctx: Ctx) {
const highlighter = new Highlighter(ctx);
- const client = ctx.client;
- if (client != null) {
- client.onNotification(
- 'rust-analyzer/publishDecorations',
- (params: PublishDecorationsParams) => {
+
+ ctx.client.onNotification(ra.publishDecorations, params => {
if (!ctx.config.highlightingOn) return;
const targetEditor = vscode.window.visibleTextEditors.find(
@@ -28,9 +25,8 @@ export function activateHighlighting(ctx: Ctx) {
if (!targetEditor) return;
highlighter.setHighlights(targetEditor, params.decorations);
- },
- );
- }
+ });
+
vscode.workspace.onDidChangeConfiguration(
_ => highlighter.removeHighlights(),
@@ -45,13 +41,10 @@ export function activateHighlighting(ctx: Ctx) {
const client = ctx.client;
if (!client) return;
- const params: lc.TextDocumentIdentifier = {
- uri: editor.document.uri.toString(),
- };
- const decorations = await sendRequestWithRetry<Decoration[]>(
+ const decorations = await sendRequestWithRetry(
client,
- 'rust-analyzer/decorationsRequest',
- params,
+ ra.decorationsRequest,
+ { uri: editor.document.uri.toString() },
);
highlighter.setHighlights(editor, decorations);
},
@@ -60,17 +53,6 @@ export function activateHighlighting(ctx: Ctx) {
);
}
-interface PublishDecorationsParams {
- uri: string;
- decorations: Decoration[];
-}
-
-interface Decoration {
- range: lc.Range;
- tag: string;
- bindingHash?: string;
-}
-
// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
function fancify(seed: string, shade: 'light' | 'dark') {
const random = randomU32Numbers(hashString(seed));
@@ -108,7 +90,7 @@ class Highlighter {
this.decorations = null;
}
- public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) {
+ public setHighlights(editor: vscode.TextEditor, highlights: ra.Decoration[]) {
const client = this.ctx.client;
if (!client) return;
// Initialize decorations if necessary
