mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Encapsulate highlighting activation
This commit is contained in:
parent
17dda0972a
commit
7646dc046e
4 changed files with 24 additions and 35 deletions
|
@ -1,25 +0,0 @@
|
|||
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);
|
||||
};
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
import * as changeActiveTextEditor from './change_active_text_editor';
|
||||
|
||||
export { changeActiveTextEditor };
|
|
@ -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<Decoration[]>(
|
||||
'rust-analyzer/decorationsRequest',
|
||||
params,
|
||||
);
|
||||
Server.highlighter.setHighlights(editor, decorations);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export interface Decoration {
|
||||
range: lc.Range;
|
||||
|
|
|
@ -4,10 +4,10 @@ import * as lc from 'vscode-languageclient';
|
|||
import * as commands from './commands';
|
||||
import { activateInlayHints } from './inlay_hints';
|
||||
import { StatusDisplay } from './status_display';
|
||||
import * as events from './events';
|
||||
import * as notifications from './notifications';
|
||||
import { Server } from './server';
|
||||
import { Ctx } from './ctx';
|
||||
import { activateHighlighting } from './highlighting';
|
||||
|
||||
let ctx!: Ctx;
|
||||
|
||||
|
@ -37,6 +37,8 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
);
|
||||
ctx.pushCleanup(watchStatus);
|
||||
|
||||
activateHighlighting(ctx);
|
||||
|
||||
// Notifications are events triggered by the language server
|
||||
const allNotifications: [string, lc.GenericNotificationHandler][] = [
|
||||
[
|
||||
|
@ -49,11 +51,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
],
|
||||
];
|
||||
|
||||
// The events below are plain old javascript events, triggered and handled by vscode
|
||||
vscode.window.onDidChangeActiveTextEditor(
|
||||
events.changeActiveTextEditor.makeHandler(),
|
||||
);
|
||||
|
||||
const startServer = () => Server.start(allNotifications);
|
||||
const reloadCommand = () => reloadServer(startServer);
|
||||
|
||||
|
|
Loading…
Reference in a new issue