aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-31 16:22:43 +0000
committerAleksey Kladov <[email protected]>2019-12-31 16:22:43 +0000
commite4b588868f822b9c200a8ce77d24bfab5aeca4b8 (patch)
tree6241f2088d0b1d8eeae9cceef4aee74a48d31993 /editors
parent1327aed7f6289043091aa9179282030c6f13ddbe (diff)
Refactor status activation
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/ctx.ts5
-rw-r--r--editors/code/src/highlighting.ts42
-rw-r--r--editors/code/src/main.ts17
-rw-r--r--editors/code/src/server.ts9
-rw-r--r--editors/code/src/status_display.ts10
5 files changed, 38 insertions, 45 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 693ce05ed..0e62a3a85 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -84,6 +84,11 @@ export class Ctx {
84 } 84 }
85 throw 'unreachable'; 85 throw 'unreachable';
86 } 86 }
87
88 onNotification(method: string, handler: lc.GenericNotificationHandler) {
89 this.client.onReady()
90 .then(() => this.client.onNotification(method, handler))
91 }
87} 92}
88 93
89export type Cmd = (...args: any[]) => any; 94export type Cmd = (...args: any[]) => any;
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index d383d87ef..d4e961b5b 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -10,28 +10,26 @@ import { Ctx } from './ctx';
10export function activateHighlighting(ctx: Ctx) { 10export function activateHighlighting(ctx: Ctx) {
11 const highlighter = new Highlighter(ctx); 11 const highlighter = new Highlighter(ctx);
12 12
13 ctx.client.onReady().then(() => { 13 ctx.onNotification(
14 ctx.client.onNotification( 14 'rust-analyzer/publishDecorations',
15 'rust-analyzer/publishDecorations', 15 (params: PublishDecorationsParams) => {
16 (params: PublishDecorationsParams) => { 16 if (!ctx.config.highlightingOn) return;
17 if (!ctx.config.highlightingOn) return; 17
18 18 const targetEditor = vscode.window.visibleTextEditors.find(
19 const targetEditor = vscode.window.visibleTextEditors.find( 19 editor => {
20 editor => { 20 const unescapedUri = unescape(
21 const unescapedUri = unescape( 21 editor.document.uri.toString(),
22 editor.document.uri.toString(), 22 );
23 ); 23 // Unescaped URI looks like:
24 // Unescaped URI looks like: 24 // file:///c:/Workspace/ra-test/src/main.rs
25 // file:///c:/Workspace/ra-test/src/main.rs 25 return unescapedUri === params.uri;
26 return unescapedUri === params.uri; 26 },
27 }, 27 );
28 ); 28 if (!targetEditor) return;
29 if (!targetEditor) return; 29
30 30 highlighter.setHighlights(targetEditor, params.decorations);
31 highlighter.setHighlights(targetEditor, params.decorations); 31 },
32 }, 32 );
33 );
34 });
35 33
36 vscode.workspace.onDidChangeConfiguration( 34 vscode.workspace.onDidChangeConfiguration(
37 _ => highlighter.removeHighlights(), 35 _ => highlighter.removeHighlights(),
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 0c4abdac8..511f17ca4 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -1,9 +1,8 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient';
3 2
4import * as commands from './commands'; 3import * as commands from './commands';
5import { activateInlayHints } from './inlay_hints'; 4import { activateInlayHints } from './inlay_hints';
6import { StatusDisplay } from './status_display'; 5import { activateStatusDisplay } from './status_display';
7import { Server } from './server'; 6import { Server } from './server';
8import { Ctx } from './ctx'; 7import { Ctx } from './ctx';
9import { activateHighlighting } from './highlighting'; 8import { activateHighlighting } from './highlighting';
@@ -32,18 +31,7 @@ export async function activate(context: vscode.ExtensionContext) {
32 ctx.overrideCommand('type', commands.onEnter); 31 ctx.overrideCommand('type', commands.onEnter);
33 } 32 }
34 33
35 const watchStatus = new StatusDisplay(ctx.config.cargoWatchOptions.command); 34 const startServer = () => Server.start();
36 ctx.pushCleanup(watchStatus);
37
38 // Notifications are events triggered by the language server
39 const allNotifications: [string, lc.GenericNotificationHandler][] = [
40 [
41 '$/progress',
42 params => watchStatus.handleProgressNotification(params),
43 ],
44 ];
45
46 const startServer = () => Server.start(allNotifications);
47 const reloadCommand = () => reloadServer(startServer); 35 const reloadCommand = () => reloadServer(startServer);
48 36
49 vscode.commands.registerCommand('rust-analyzer.reload', reloadCommand); 37 vscode.commands.registerCommand('rust-analyzer.reload', reloadCommand);
@@ -55,6 +43,7 @@ export async function activate(context: vscode.ExtensionContext) {
55 vscode.window.showErrorMessage(e.message); 43 vscode.window.showErrorMessage(e.message);
56 } 44 }
57 45
46 activateStatusDisplay(ctx);
58 activateHighlighting(ctx); 47 activateHighlighting(ctx);
59 48
60 if (ctx.config.displayInlayHints) { 49 if (ctx.config.displayInlayHints) {
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 2bb21da6b..5dc8a36bd 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -15,9 +15,7 @@ export class Server {
15 public static config = new Config(); 15 public static config = new Config();
16 public static client: lc.LanguageClient; 16 public static client: lc.LanguageClient;
17 17
18 public static async start( 18 public static async start() {
19 notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>,
20 ) {
21 // '.' Is the fallback if no folder is open 19 // '.' Is the fallback if no folder is open
22 // TODO?: Workspace folders support Uri's (eg: file://test.txt). It might be a good idea to test if the uri points to a file. 20 // TODO?: Workspace folders support Uri's (eg: file://test.txt). It might be a good idea to test if the uri points to a file.
23 let folder: string = '.'; 21 let folder: string = '.';
@@ -92,11 +90,6 @@ export class Server {
92 }, 90 },
93 }; 91 };
94 Server.client.registerProposedFeatures(); 92 Server.client.registerProposedFeatures();
95 Server.client.onReady().then(() => {
96 for (const [type, handler] of notificationHandlers) {
97 Server.client.onNotification(type, handler);
98 }
99 });
100 Server.client.start(); 93 Server.client.start();
101 } 94 }
102} 95}
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts
index 48cf0655b..e3719075b 100644
--- a/editors/code/src/status_display.ts
+++ b/editors/code/src/status_display.ts
@@ -1,8 +1,16 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { Ctx } from './ctx';
4
3const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; 5const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
4 6
5export class StatusDisplay implements vscode.Disposable { 7export function activateStatusDisplay(ctx: Ctx) {
8 const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
9 ctx.pushCleanup(statusDisplay);
10 ctx.onNotification('$/progress', params => statusDisplay.handleProgressNotification(params));
11}
12
13class StatusDisplay implements vscode.Disposable {
6 packageName?: string; 14 packageName?: string;
7 15
8 private i = 0; 16 private i = 0;