aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/src/ctx.ts13
-rw-r--r--editors/code/src/highlighting.ts5
-rw-r--r--editors/code/src/inlay_hints.ts6
-rw-r--r--editors/code/src/main.ts21
-rw-r--r--editors/code/src/status_display.ts13
5 files changed, 25 insertions, 33 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 1eff88df2..c06d8ac31 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -17,7 +17,6 @@ export class Ctx {
17 // on the event loop to get a better picture of what we can do here) 17 // on the event loop to get a better picture of what we can do here)
18 client: lc.LanguageClient | null = null; 18 client: lc.LanguageClient | null = null;
19 private extCtx: vscode.ExtensionContext; 19 private extCtx: vscode.ExtensionContext;
20 private onStartHooks: Array<(client: lc.LanguageClient) => void> = [];
21 20
22 constructor(extCtx: vscode.ExtensionContext) { 21 constructor(extCtx: vscode.ExtensionContext) {
23 this.config = new Config(extCtx); 22 this.config = new Config(extCtx);
@@ -39,9 +38,6 @@ export class Ctx {
39 await client.onReady(); 38 await client.onReady();
40 39
41 this.client = client; 40 this.client = client;
42 for (const hook of this.onStartHooks) {
43 hook(client);
44 }
45 } 41 }
46 42
47 get activeRustEditor(): vscode.TextEditor | undefined { 43 get activeRustEditor(): vscode.TextEditor | undefined {
@@ -69,15 +65,6 @@ export class Ctx {
69 pushCleanup(d: Disposable) { 65 pushCleanup(d: Disposable) {
70 this.extCtx.subscriptions.push(d); 66 this.extCtx.subscriptions.push(d);
71 } 67 }
72
73 onStart(hook: (client: lc.LanguageClient) => void) {
74 const client = this.client;
75 if (client == null) {
76 this.onStartHooks.push(hook);
77 } else {
78 hook(client)
79 }
80 }
81} 68}
82 69
83export interface Disposable { 70export interface Disposable {
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index f693fb8ba..a2db04de8 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -7,7 +7,8 @@ import { Ctx, sendRequestWithRetry } from './ctx';
7 7
8export function activateHighlighting(ctx: Ctx) { 8export function activateHighlighting(ctx: Ctx) {
9 const highlighter = new Highlighter(ctx); 9 const highlighter = new Highlighter(ctx);
10 ctx.onStart(client => { 10 const client = ctx.client;
11 if (client != null) {
11 client.onNotification( 12 client.onNotification(
12 'rust-analyzer/publishDecorations', 13 'rust-analyzer/publishDecorations',
13 (params: PublishDecorationsParams) => { 14 (params: PublishDecorationsParams) => {
@@ -28,7 +29,7 @@ export function activateHighlighting(ctx: Ctx) {
28 highlighter.setHighlights(targetEditor, params.decorations); 29 highlighter.setHighlights(targetEditor, params.decorations);
29 }, 30 },
30 ); 31 );
31 }); 32 };
32 33
33 vscode.workspace.onDidChangeConfiguration( 34 vscode.workspace.onDidChangeConfiguration(
34 _ => highlighter.removeHighlights(), 35 _ => highlighter.removeHighlights(),
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 9e400fabe..55bbd7f00 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -33,9 +33,9 @@ export function activateInlayHints(ctx: Ctx) {
33 } 33 }
34 }) 34 })
35 35
36 // We pass async function though it will not be awaited when called, 36 // XXX: we don't await this, thus Promise rejections won't be handled, but
37 // thus Promise rejections won't be handled, but this should never throw in fact... 37 // this should never throw in fact...
38 ctx.onStart(async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)); 38 hintsUpdater.setEnabled(ctx.config.displayInlayHints)
39} 39}
40 40
41interface InlayHintsParams { 41interface InlayHintsParams {
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index ec488c340..0bf2c4829 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -11,6 +11,17 @@ let ctx: Ctx | undefined;
11export async function activate(context: vscode.ExtensionContext) { 11export async function activate(context: vscode.ExtensionContext) {
12 ctx = new Ctx(context); 12 ctx = new Ctx(context);
13 13
14 // Note: we try to start the server before we activate type hints so that it
15 // registers its `onDidChangeDocument` handler before us.
16 //
17 // This a horribly, horribly wrong way to deal with this problem.
18 try {
19 await ctx.startServer();
20 } catch (e) {
21 vscode.window.showErrorMessage(e.message);
22 }
23
24 // Commands which invokes manually via command palette, shortcut, etc.
14 ctx.registerCommand('reload', (ctx) => { 25 ctx.registerCommand('reload', (ctx) => {
15 return async () => { 26 return async () => {
16 vscode.window.showInformationMessage('Reloading rust-analyzer...'); 27 vscode.window.showInformationMessage('Reloading rust-analyzer...');
@@ -28,7 +39,6 @@ export async function activate(context: vscode.ExtensionContext) {
28 } 39 }
29 }) 40 })
30 41
31 // Commands which invokes manually via command palette, shortcut, etc.
32 ctx.registerCommand('analyzerStatus', commands.analyzerStatus); 42 ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
33 ctx.registerCommand('collectGarbage', commands.collectGarbage); 43 ctx.registerCommand('collectGarbage', commands.collectGarbage);
34 ctx.registerCommand('matchingBrace', commands.matchingBrace); 44 ctx.registerCommand('matchingBrace', commands.matchingBrace);
@@ -49,15 +59,6 @@ export async function activate(context: vscode.ExtensionContext) {
49 activateStatusDisplay(ctx); 59 activateStatusDisplay(ctx);
50 60
51 activateHighlighting(ctx); 61 activateHighlighting(ctx);
52 // Note: we try to start the server before we activate type hints so that it
53 // registers its `onDidChangeDocument` handler before us.
54 //
55 // This a horribly, horribly wrong way to deal with this problem.
56 try {
57 await ctx.startServer();
58 } catch (e) {
59 vscode.window.showErrorMessage(e.message);
60 }
61 activateInlayHints(ctx); 62 activateInlayHints(ctx);
62} 63}
63 64
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts
index 326b5217b..ed0d82166 100644
--- a/editors/code/src/status_display.ts
+++ b/editors/code/src/status_display.ts
@@ -9,11 +9,14 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '
9export function activateStatusDisplay(ctx: Ctx) { 9export function activateStatusDisplay(ctx: Ctx) {
10 const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); 10 const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
11 ctx.pushCleanup(statusDisplay); 11 ctx.pushCleanup(statusDisplay);
12 ctx.onStart(client => ctx.pushCleanup(client.onProgress( 12 const client = ctx.client;
13 WorkDoneProgress.type, 13 if (client != null) {
14 'rustAnalyzer/cargoWatcher', 14 ctx.pushCleanup(client.onProgress(
15 params => statusDisplay.handleProgressNotification(params) 15 WorkDoneProgress.type,
16 ))); 16 'rustAnalyzer/cargoWatcher',
17 params => statusDisplay.handleProgressNotification(params)
18 ))
19 }
17} 20}
18 21
19class StatusDisplay implements Disposable { 22class StatusDisplay implements Disposable {