mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Privatize highlighting
This commit is contained in:
parent
cdd7118cbf
commit
233f1dd2a8
8 changed files with 54 additions and 48 deletions
|
@ -10,6 +10,36 @@ import { Server } from './server';
|
|||
import { Ctx } from './ctx';
|
||||
|
||||
export function activateHighlighting(ctx: Ctx) {
|
||||
const highlighter = new Highlighter();
|
||||
|
||||
ctx.client.onReady().then(() => {
|
||||
ctx.client.onNotification(
|
||||
'rust-analyzer/publishDecorations',
|
||||
(params: PublishDecorationsParams) => {
|
||||
if (!ctx.config.highlightingOn) return;
|
||||
|
||||
const targetEditor = vscode.window.visibleTextEditors.find(
|
||||
editor => {
|
||||
const unescapedUri = unescape(
|
||||
editor.document.uri.toString(),
|
||||
);
|
||||
// Unescaped URI looks like:
|
||||
// file:///c:/Workspace/ra-test/src/main.rs
|
||||
return unescapedUri === params.uri;
|
||||
},
|
||||
);
|
||||
if (!targetEditor) return;
|
||||
|
||||
highlighter.setHighlights(targetEditor, params.decorations);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
vscode.workspace.onDidChangeConfiguration(
|
||||
_ => highlighter.removeHighlights(),
|
||||
ctx.subscriptions,
|
||||
);
|
||||
|
||||
vscode.window.onDidChangeActiveTextEditor(
|
||||
async (editor: vscode.TextEditor | undefined) => {
|
||||
if (!editor || editor.document.languageId !== 'rust') return;
|
||||
|
@ -22,11 +52,17 @@ export function activateHighlighting(ctx: Ctx) {
|
|||
'rust-analyzer/decorationsRequest',
|
||||
params,
|
||||
);
|
||||
Server.highlighter.setHighlights(editor, decorations);
|
||||
highlighter.setHighlights(editor, decorations);
|
||||
},
|
||||
ctx.subscriptions,
|
||||
);
|
||||
}
|
||||
|
||||
interface PublishDecorationsParams {
|
||||
uri: string;
|
||||
decorations: Decoration[];
|
||||
}
|
||||
|
||||
export interface Decoration {
|
||||
range: lc.Range;
|
||||
tag: string;
|
||||
|
@ -81,7 +117,7 @@ function createDecorationFromTextmate(
|
|||
return vscode.window.createTextEditorDecorationType(decorationOptions);
|
||||
}
|
||||
|
||||
export class Highlighter {
|
||||
class Highlighter {
|
||||
private static initDecorations(): Map<
|
||||
string,
|
||||
vscode.TextEditorDecorationType
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue