aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/extension.ts17
-rw-r--r--editors/code/src/notifications/index.ts5
-rw-r--r--editors/code/src/notifications/publish_decorations.ts20
-rw-r--r--editors/code/src/server.ts27
4 files changed, 44 insertions, 25 deletions
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index f1bc0b457..44e74f4cc 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -1,8 +1,10 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient';
2 3
3import * as commands from './commands'; 4import * as commands from './commands';
4import { TextDocumentContentProvider } from './commands/syntaxTree'; 5import { TextDocumentContentProvider } from './commands/syntaxTree';
5import * as events from './events'; 6import * as events from './events';
7import * as notifications from './notifications';
6import { Server } from './server'; 8import { Server } from './server';
7 9
8export function activate(context: vscode.ExtensionContext) { 10export function activate(context: vscode.ExtensionContext) {
@@ -14,6 +16,7 @@ export function activate(context: vscode.ExtensionContext) {
14 disposeOnDeactivation(vscode.commands.registerCommand(name, f)); 16 disposeOnDeactivation(vscode.commands.registerCommand(name, f));
15 } 17 }
16 18
19 // Commands are requests from vscode to the language server
17 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); 20 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle);
18 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); 21 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
19 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle); 22 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);
@@ -22,19 +25,27 @@ export function activate(context: vscode.ExtensionContext) {
22 registerCommand('ra-lsp.run', commands.runnables.handle); 25 registerCommand('ra-lsp.run', commands.runnables.handle);
23 registerCommand('ra-lsp.applySourceChange', commands.applySourceChange.handle); 26 registerCommand('ra-lsp.applySourceChange', commands.applySourceChange.handle);
24 27
28 // Notifications are events triggered by the language server
29 const allNotifications: Iterable<[string, lc.GenericNotificationHandler]> = [
30 ['m/publishDecorations', notifications.publishDecorations.handle],
31 ];
32
33 // The events below are plain old javascript events, triggered and handled by vscode
34 vscode.window.onDidChangeActiveTextEditor(events.changeActiveTextEditor.handle);
35
25 const textDocumentContentProvider = new TextDocumentContentProvider(); 36 const textDocumentContentProvider = new TextDocumentContentProvider();
26 disposeOnDeactivation(vscode.workspace.registerTextDocumentContentProvider( 37 disposeOnDeactivation(vscode.workspace.registerTextDocumentContentProvider(
27 'ra-lsp', 38 'ra-lsp',
28 textDocumentContentProvider, 39 textDocumentContentProvider,
29 )); 40 ));
30 41
31 Server.start();
32
33 vscode.workspace.onDidChangeTextDocument( 42 vscode.workspace.onDidChangeTextDocument(
34 events.changeTextDocument.createHandler(textDocumentContentProvider), 43 events.changeTextDocument.createHandler(textDocumentContentProvider),
35 null, 44 null,
36 context.subscriptions); 45 context.subscriptions);
37 vscode.window.onDidChangeActiveTextEditor(events.changeActiveTextEditor.handle); 46
47 // Start the language server, finally!
48 Server.start(allNotifications);
38} 49}
39 50
40export function deactivate(): Thenable<void> { 51export function deactivate(): Thenable<void> {
diff --git a/editors/code/src/notifications/index.ts b/editors/code/src/notifications/index.ts
new file mode 100644
index 000000000..c56576865
--- /dev/null
+++ b/editors/code/src/notifications/index.ts
@@ -0,0 +1,5 @@
1import * as publishDecorations from './publish_decorations';
2
3export {
4 publishDecorations,
5};
diff --git a/editors/code/src/notifications/publish_decorations.ts b/editors/code/src/notifications/publish_decorations.ts
new file mode 100644
index 000000000..d8790386b
--- /dev/null
+++ b/editors/code/src/notifications/publish_decorations.ts
@@ -0,0 +1,20 @@
1import * as vscode from 'vscode';
2
3import { Decoration } from '../highlighting';
4import { Server } from '../server';
5
6export interface PublishDecorationsParams {
7 uri: string;
8 decorations: Decoration[];
9}
10
11export function handle(params: PublishDecorationsParams) {
12 const targetEditor = vscode.window.visibleTextEditors.find(
13 (editor) => editor.document.uri.toString() === params.uri,
14 );
15 if (!Server.config.highlightingOn || !targetEditor) { return; }
16 Server.highlighter.setHighlights(
17 targetEditor,
18 params.decorations,
19 );
20}
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 325023e36..01fd80756 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -1,15 +1,14 @@
1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 1import * as lc from 'vscode-languageclient';
3 2
4import { Config } from './config'; 3import { Config } from './config';
5import { Decoration, Highlighter } from './highlighting'; 4import { Highlighter } from './highlighting';
6 5
7export class Server { 6export class Server {
8 public static highlighter = new Highlighter(); 7 public static highlighter = new Highlighter();
9 public static config = new Config(); 8 public static config = new Config();
10 public static client: lc.LanguageClient; 9 public static client: lc.LanguageClient;
11 10
12 public static start() { 11 public static start(notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>) {
13 const run: lc.Executable = { 12 const run: lc.Executable = {
14 command: 'ra_lsp_server', 13 command: 'ra_lsp_server',
15 options: { cwd: '.' }, 14 options: { cwd: '.' },
@@ -18,7 +17,6 @@ export class Server {
18 run, 17 run,
19 debug: run, 18 debug: run,
20 }; 19 };
21
22 const clientOptions: lc.LanguageClientOptions = { 20 const clientOptions: lc.LanguageClientOptions = {
23 documentSelector: [{ scheme: 'file', language: 'rust' }], 21 documentSelector: [{ scheme: 'file', language: 'rust' }],
24 }; 22 };
@@ -30,25 +28,10 @@ export class Server {
30 clientOptions, 28 clientOptions,
31 ); 29 );
32 Server.client.onReady().then(() => { 30 Server.client.onReady().then(() => {
33 Server.client.onNotification( 31 for (const [type, handler] of notificationHandlers) {
34 'm/publishDecorations', 32 Server.client.onNotification(type, handler);
35 (params: PublishDecorationsParams) => { 33 }
36 const targetEditor = vscode.window.visibleTextEditors.find(
37 (editor) => editor.document.uri.toString() === params.uri,
38 );
39 if (!Server.config.highlightingOn || !targetEditor) { return; }
40 Server.highlighter.setHighlights(
41 targetEditor,
42 params.decorations,
43 );
44 },
45 );
46 }); 34 });
47 Server.client.start(); 35 Server.client.start();
48 } 36 }
49} 37}
50
51interface PublishDecorationsParams {
52 uri: string;
53 decorations: Decoration[];
54}