about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2020-02-17 13:40:20 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2020-02-17 13:40:47 +0100
commitd24e612106867c4bb6a1e59bf99aabfb7bc27823 (patch)
treedf40b6265f303b8fba5f804a7f7ff370e844dea0 /editors/code/src
parentdcdbbddd1630a4ed01906c2aff0e2b65ed99a591 (diff)
downloadrust-d24e612106867c4bb6a1e59bf99aabfb7bc27823.tar.gz
rust-d24e612106867c4bb6a1e59bf99aabfb7bc27823.zip
Simplify startup
Diffstat (limited to 'editors/code/src')
-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 1eff88df2a4..c06d8ac3176 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -17,7 +17,6 @@ export class Ctx {
     // on the event loop to get a better picture of what we can do here)
     client: lc.LanguageClient | null = null;
     private extCtx: vscode.ExtensionContext;
-    private onStartHooks: Array<(client: lc.LanguageClient) => void> = [];
 
     constructor(extCtx: vscode.ExtensionContext) {
         this.config = new Config(extCtx);
@@ -39,9 +38,6 @@ export class Ctx {
         await client.onReady();
 
         this.client = client;
-        for (const hook of this.onStartHooks) {
-            hook(client);
-        }
     }
 
     get activeRustEditor(): vscode.TextEditor | undefined {
@@ -69,15 +65,6 @@ export class Ctx {
     pushCleanup(d: Disposable) {
         this.extCtx.subscriptions.push(d);
     }
-
-    onStart(hook: (client: lc.LanguageClient) => void) {
-        const client = this.client;
-        if (client == null) {
-            this.onStartHooks.push(hook);
-        } else {
-            hook(client)
-        }
-    }
 }
 
 export interface Disposable {
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index f693fb8ba78..a2db04de872 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -7,7 +7,8 @@ import { Ctx, sendRequestWithRetry } from './ctx';
 
 export function activateHighlighting(ctx: Ctx) {
     const highlighter = new Highlighter(ctx);
-    ctx.onStart(client => {
+    const client = ctx.client;
+    if (client != null) {
         client.onNotification(
             'rust-analyzer/publishDecorations',
             (params: PublishDecorationsParams) => {
@@ -28,7 +29,7 @@ export function activateHighlighting(ctx: Ctx) {
                 highlighter.setHighlights(targetEditor, params.decorations);
             },
         );
-    });
+    };
 
     vscode.workspace.onDidChangeConfiguration(
         _ => highlighter.removeHighlights(),
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 9e400fabec0..55bbd7f0041 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -33,9 +33,9 @@ export function activateInlayHints(ctx: Ctx) {
         }
     })
 
-    // We pass async function though it will not be awaited when called,
-    // thus Promise rejections won't be handled, but this should never throw in fact...
-    ctx.onStart(async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
+    // XXX: we don't await this, thus Promise rejections won't be handled, but
+    // this should never throw in fact...
+    hintsUpdater.setEnabled(ctx.config.displayInlayHints)
 }
 
 interface InlayHintsParams {
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index ec488c34055..0bf2c4829bb 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -11,6 +11,17 @@ let ctx: Ctx | undefined;
 export async function activate(context: vscode.ExtensionContext) {
     ctx = new Ctx(context);
 
+    // Note: we try to start the server before we activate type hints so that it
+    // registers its `onDidChangeDocument` handler before us.
+    //
+    // This a horribly, horribly wrong way to deal with this problem.
+    try {
+        await ctx.startServer();
+    } catch (e) {
+        vscode.window.showErrorMessage(e.message);
+    }
+
+    // Commands which invokes manually via command palette, shortcut, etc.
     ctx.registerCommand('reload', (ctx) => {
         return async () => {
             vscode.window.showInformationMessage('Reloading rust-analyzer...');
@@ -28,7 +39,6 @@ export async function activate(context: vscode.ExtensionContext) {
         }
     })
 
-    // Commands which invokes manually via command palette, shortcut, etc.
     ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
     ctx.registerCommand('collectGarbage', commands.collectGarbage);
     ctx.registerCommand('matchingBrace', commands.matchingBrace);
@@ -49,15 +59,6 @@ export async function activate(context: vscode.ExtensionContext) {
     activateStatusDisplay(ctx);
 
     activateHighlighting(ctx);
-    // Note: we try to start the server before we activate type hints so that it
-    // registers its `onDidChangeDocument` handler before us.
-    //
-    // This a horribly, horribly wrong way to deal with this problem.
-    try {
-        await ctx.startServer();
-    } catch (e) {
-        vscode.window.showErrorMessage(e.message);
-    }
     activateInlayHints(ctx);
 }
 
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts
index 326b5217b5b..ed0d8216659 100644
--- a/editors/code/src/status_display.ts
+++ b/editors/code/src/status_display.ts
@@ -9,11 +9,14 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '
 export function activateStatusDisplay(ctx: Ctx) {
     const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
     ctx.pushCleanup(statusDisplay);
-    ctx.onStart(client => ctx.pushCleanup(client.onProgress(
-        WorkDoneProgress.type,
-        'rustAnalyzer/cargoWatcher',
-        params => statusDisplay.handleProgressNotification(params)
-    )));
+    const client = ctx.client;
+    if (client != null) {
+        ctx.pushCleanup(client.onProgress(
+            WorkDoneProgress.type,
+            'rustAnalyzer/cargoWatcher',
+            params => statusDisplay.handleProgressNotification(params)
+        ))
+    }
 }
 
 class StatusDisplay implements Disposable {