about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2019-12-30 20:29:21 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2019-12-30 21:32:04 +0100
commit7646dc046eb562276231de8ec6a4df1bc691cafc (patch)
tree3820a5c89a7b6317373fca4d68cab01912cc24f6 /editors/code/src
parent17dda0972a68dd88a766c223390317dc2cb3ea00 (diff)
downloadrust-7646dc046eb562276231de8ec6a4df1bc691cafc.tar.gz
rust-7646dc046eb562276231de8ec6a4df1bc691cafc.zip
Encapsulate highlighting activation
Diffstat (limited to 'editors/code/src')
-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 4384ee56768..00000000000
--- a/editors/code/src/events/change_active_text_editor.ts
+++ /dev/null
@@ -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);
-    };
-}
diff --git a/editors/code/src/events/index.ts b/editors/code/src/events/index.ts
deleted file mode 100644
index be135474de6..00000000000
--- a/editors/code/src/events/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import * as changeActiveTextEditor from './change_active_text_editor';
-
-export { changeActiveTextEditor };
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 4e224a54c11..ced78adc110 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -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;
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 7e63a9cac23..45657532e5f 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -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);