mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
vscode: migrate highlighting to rust-analyzer-api.ts
This commit is contained in:
parent
21ab133966
commit
8c4409b3bb
1 changed files with 20 additions and 38 deletions
|
@ -1,5 +1,5 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as ra from './rust-analyzer-api';
|
||||||
|
|
||||||
import { ColorTheme, TextMateRuleSettings } from './color_theme';
|
import { ColorTheme, TextMateRuleSettings } from './color_theme';
|
||||||
|
|
||||||
|
@ -8,11 +8,8 @@ import { sendRequestWithRetry } from './util';
|
||||||
|
|
||||||
export function activateHighlighting(ctx: Ctx) {
|
export function activateHighlighting(ctx: Ctx) {
|
||||||
const highlighter = new Highlighter(ctx);
|
const highlighter = new Highlighter(ctx);
|
||||||
const client = ctx.client;
|
|
||||||
if (client != null) {
|
ctx.client.onNotification(ra.publishDecorations, params => {
|
||||||
client.onNotification(
|
|
||||||
'rust-analyzer/publishDecorations',
|
|
||||||
(params: PublishDecorationsParams) => {
|
|
||||||
if (!ctx.config.highlightingOn) return;
|
if (!ctx.config.highlightingOn) return;
|
||||||
|
|
||||||
const targetEditor = vscode.window.visibleTextEditors.find(
|
const targetEditor = vscode.window.visibleTextEditors.find(
|
||||||
|
@ -28,9 +25,8 @@ export function activateHighlighting(ctx: Ctx) {
|
||||||
if (!targetEditor) return;
|
if (!targetEditor) return;
|
||||||
|
|
||||||
highlighter.setHighlights(targetEditor, params.decorations);
|
highlighter.setHighlights(targetEditor, params.decorations);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
vscode.workspace.onDidChangeConfiguration(
|
vscode.workspace.onDidChangeConfiguration(
|
||||||
_ => highlighter.removeHighlights(),
|
_ => highlighter.removeHighlights(),
|
||||||
|
@ -45,13 +41,10 @@ export function activateHighlighting(ctx: Ctx) {
|
||||||
const client = ctx.client;
|
const client = ctx.client;
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
|
|
||||||
const params: lc.TextDocumentIdentifier = {
|
const decorations = await sendRequestWithRetry(
|
||||||
uri: editor.document.uri.toString(),
|
|
||||||
};
|
|
||||||
const decorations = await sendRequestWithRetry<Decoration[]>(
|
|
||||||
client,
|
client,
|
||||||
'rust-analyzer/decorationsRequest',
|
ra.decorationsRequest,
|
||||||
params,
|
{ uri: editor.document.uri.toString() },
|
||||||
);
|
);
|
||||||
highlighter.setHighlights(editor, decorations);
|
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
|
// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
|
||||||
function fancify(seed: string, shade: 'light' | 'dark') {
|
function fancify(seed: string, shade: 'light' | 'dark') {
|
||||||
const random = randomU32Numbers(hashString(seed));
|
const random = randomU32Numbers(hashString(seed));
|
||||||
|
@ -108,7 +90,7 @@ class Highlighter {
|
||||||
this.decorations = null;
|
this.decorations = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) {
|
public setHighlights(editor: vscode.TextEditor, highlights: ra.Decoration[]) {
|
||||||
const client = this.ctx.client;
|
const client = this.ctx.client;
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
// Initialize decorations if necessary
|
// Initialize decorations if necessary
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue