]> git.lizzy.rs Git - rust.git/commitdiff
Style fixes
authorKirill Bulatov <mail4score@gmail.com>
Fri, 20 Mar 2020 22:01:47 +0000 (00:01 +0200)
committerKirill Bulatov <mail4score@gmail.com>
Mon, 30 Mar 2020 10:39:14 +0000 (13:39 +0300)
crates/rust-analyzer/src/main_loop.rs
editors/code/src/client.ts
editors/code/src/ctx.ts
editors/code/src/inlay_hints.ts

index 85bde90bbc26fd0ae862a7d99982f827ca817d7f..a64dccd58c8a483635074c1f67d209f06b67aef9 100644 (file)
@@ -413,20 +413,27 @@ fn loop_turn(
                 if !removed {
                     log::error!("unexpected response: {:?}", resp)
                 }
-                if Some(&resp.id) == loop_state.configuration_request_id.as_ref() {
+
+                if Some(resp.id) == loop_state.configuration_request_id {
                     loop_state.configuration_request_id.take();
-                    // TODO kb unwrap-unwrap-unwrap
-                    let new_config =
-                        serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap())
-                            .unwrap()
-                            .first()
-                            .unwrap()
-                            .to_owned();
-                    world_state.update_configuration(
-                        new_config.lru_capacity,
-                        get_options(&new_config, text_document_caps),
-                        get_feature_flags(&new_config, connection),
-                    );
+                    if let Some(err) = resp.error {
+                        log::error!("failed fetch the server settings: {:?}", err)
+                    } else if resp.result.is_none() {
+                        log::error!("received empty server settings response from the client")
+                    } else {
+                        let new_config =
+                            serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap())?
+                                .first()
+                                .expect(
+                                    "The client is expected to always send a non-empty config data",
+                                )
+                                .to_owned();
+                        world_state.update_configuration(
+                            new_config.lru_capacity,
+                            get_options(&new_config, text_document_caps),
+                            get_feature_flags(&new_config, connection),
+                        );
+                    }
                 }
             }
         },
@@ -657,13 +664,15 @@ fn on_notification(
         Err(not) => not,
     };
     let not = match notification_cast::<req::DidChangeConfiguration>(not) {
-        Ok(_params) => {
+        Ok(_) => {
+            // As stated in https://github.com/microsoft/language-server-protocol/issues/676,
+            // this notification's parameters should be ignored and the actual config queried separately.
             let request_id = loop_state.next_request_id();
             let request = request_new::<req::WorkspaceConfiguration>(
                 request_id.clone(),
                 ConfigurationParams::default(),
             );
-            msg_sender.send(request.into()).unwrap();
+            msg_sender.send(request.into())?;
             loop_state.configuration_request_id.replace(request_id);
 
             return Ok(());
index 0d0832c44fc77ae75494fe784a4b1c364c9303cf..34965e2fbcfec72bb6729ffe567a2f9a77b95dfd 100644 (file)
@@ -5,7 +5,7 @@ import { Config } from './config';
 import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
 import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
 
-export function configToOptions(config: Config): object {
+export function configToServerOptions(config: Config): object {
     return {
         publishDecorations: !config.highlightingSemanticTokens,
         lruCapacity: config.lruCapacity,
@@ -50,7 +50,7 @@ export async function createClient(config: Config, serverPath: string): Promise<
 
     const clientOptions: lc.LanguageClientOptions = {
         documentSelector: [{ scheme: 'file', language: 'rust' }],
-        initializationOptions: configToOptions(config),
+        initializationOptions: configToServerOptions(config),
         traceOutputChannel,
         middleware: {
             // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
index 934638c6df9e641e770249653aefd6b539e7dee9..d2f49cd23d3dd75db0033a98527f0186d5be65d5 100644 (file)
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
 import * as lc from 'vscode-languageclient';
 
 import { Config } from './config';
-import { createClient, configToOptions } from './client';
+import { createClient, configToServerOptions } from './client';
 import { isRustEditor, RustEditor } from './util';
 
 export class Ctx {
@@ -20,7 +20,7 @@ export class Ctx {
         const res = new Ctx(config, extCtx, client, serverPath);
         res.pushCleanup(client.start());
         await client.onReady();
-        client.onRequest('workspace/configuration', _ => [configToOptions(config)]);
+        client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
         return res;
     }
 
index 542d1f3672bde767efc71fd6f73f18bf70ca127a..98663e0e32639c28eb0544e4231f5bb8f74d1174 100644 (file)
@@ -18,6 +18,8 @@ export function activateInlayHints(ctx: Ctx) {
                 return this.dispose();
             }
             if (!this.updater) this.updater = new HintsUpdater(ctx);
+
+            this.updater.syncCacheAndRenderHints();
         },
         dispose() {
             this.updater?.dispose();
@@ -124,7 +126,7 @@ class HintsUpdater implements Disposable {
         this.syncCacheAndRenderHints();
     }
 
-    private syncCacheAndRenderHints() {
+    public syncCacheAndRenderHints() {
         // FIXME: make inlayHints request pass an array of files?
         this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => {
             if (!hints) return;