aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/src/events/change_active_text_editor.ts25
-rw-r--r--editors/code/src/events/index.ts3
-rw-r--r--editors/code/src/highlighting.ts22
-rw-r--r--editors/code/src/main.ts9
4 files changed, 24 insertions, 35 deletions
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts
deleted file mode 100644
index 4384ee567..000000000
--- a/editors/code/src/events/change_active_text_editor.ts
+++ /dev/null
@@ -1,25 +0,0 @@
1import { TextEditor } from 'vscode';
2import { TextDocumentIdentifier } from 'vscode-languageclient';
3import { Decoration } from '../highlighting';
4import { Server } from '../server';
5
6export function makeHandler() {
7 return async function handle(editor: TextEditor | undefined) {
8 if (!editor || editor.document.languageId !== 'rust') {
9 return;
10 }
11
12 if (!Server.config.highlightingOn) {
13 return;
14 }
15
16 const params: TextDocumentIdentifier = {
17 uri: editor.document.uri.toString(),
18 };
19 const decorations = await Server.client.sendRequest<Decoration[]>(
20 'rust-analyzer/decorationsRequest',
21 params,
22 );
23 Server.highlighter.setHighlights(editor, decorations);
24 };
25}
diff --git a/editors/code/src/events/index.ts b/editors/code/src/events/index.ts
deleted file mode 100644
index be135474d..000000000
--- a/editors/code/src/events/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
1import * as changeActiveTextEditor from './change_active_text_editor';
2
3export { changeActiveTextEditor };
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 @@
1import seedrandom = require('seedrandom');
2import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
3import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import * as seedrandom from 'seedrandom';
4
4import * as scopes from './scopes'; 5import * as scopes from './scopes';
5import * as scopesMapper from './scopes_mapper'; 6import * as scopesMapper from './scopes_mapper';
6 7
7import { Server } from './server'; 8import { Server } from './server';
9import { Ctx } from './ctx';
10
11export function activateHighlighting(ctx: Ctx) {
12 vscode.window.onDidChangeActiveTextEditor(
13 async (editor: vscode.TextEditor | undefined) => {
14 if (!editor || editor.document.languageId !== 'rust') return;
15 if (!Server.config.highlightingOn) return;
16
17 const params: lc.TextDocumentIdentifier = {
18 uri: editor.document.uri.toString(),
19 };
20 const decorations = await ctx.client.sendRequest<Decoration[]>(
21 'rust-analyzer/decorationsRequest',
22 params,
23 );
24 Server.highlighter.setHighlights(editor, decorations);
25 },
26 );
27}
8 28
9export interface Decoration { 29export interface Decoration {
10 range: lc.Range; 30 range: lc.Range;
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 7e63a9cac..45657532e 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -4,10 +4,10 @@ import * as lc from 'vscode-languageclient';
4import * as commands from './commands'; 4import * as commands from './commands';
5import { activateInlayHints } from './inlay_hints'; 5import { activateInlayHints } from './inlay_hints';
6import { StatusDisplay } from './status_display'; 6import { StatusDisplay } from './status_display';
7import * as events from './events';
8import * as notifications from './notifications'; 7import * as notifications from './notifications';
9import { Server } from './server'; 8import { Server } from './server';
10import { Ctx } from './ctx'; 9import { Ctx } from './ctx';
10import { activateHighlighting } from './highlighting';
11 11
12let ctx!: Ctx; 12let ctx!: Ctx;
13 13
@@ -37,6 +37,8 @@ export async function activate(context: vscode.ExtensionContext) {
37 ); 37 );
38 ctx.pushCleanup(watchStatus); 38 ctx.pushCleanup(watchStatus);
39 39
40 activateHighlighting(ctx);
41
40 // Notifications are events triggered by the language server 42 // Notifications are events triggered by the language server
41 const allNotifications: [string, lc.GenericNotificationHandler][] = [ 43 const allNotifications: [string, lc.GenericNotificationHandler][] = [
42 [ 44 [
@@ -49,11 +51,6 @@ export async function activate(context: vscode.ExtensionContext) {
49 ], 51 ],
50 ]; 52 ];
51 53
52 // The events below are plain old javascript events, triggered and handled by vscode
53 vscode.window.onDidChangeActiveTextEditor(
54 events.changeActiveTextEditor.makeHandler(),
55 );
56
57 const startServer = () => Server.start(allNotifications); 54 const startServer = () => Server.start(allNotifications);
58 const reloadCommand = () => reloadServer(startServer); 55 const reloadCommand = () => reloadServer(startServer);
59 56