Skip to content

Commit 8a23bec

Browse files
Style fixes
1 parent 332799d commit 8a23bec

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,27 @@ fn loop_turn(
413413
if !removed {
414414
log::error!("unexpected response: {:?}", resp)
415415
}
416-
if Some(&resp.id) == loop_state.configuration_request_id.as_ref() {
416+
417+
if Some(resp.id) == loop_state.configuration_request_id {
417418
loop_state.configuration_request_id.take();
418-
// TODO kb unwrap-unwrap-unwrap
419-
let new_config =
420-
serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap())
421-
.unwrap()
422-
.first()
423-
.unwrap()
424-
.to_owned();
425-
world_state.update_configuration(
426-
new_config.lru_capacity,
427-
get_options(&new_config, text_document_caps),
428-
get_feature_flags(&new_config, connection),
429-
);
419+
if let Some(err) = resp.error {
420+
log::error!("failed fetch the server settings: {:?}", err)
421+
} else if resp.result.is_none() {
422+
log::error!("received empty server settings response from the client")
423+
} else {
424+
let new_config =
425+
serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap())?
426+
.first()
427+
.expect(
428+
"The client is expected to always send a non-empty config data",
429+
)
430+
.to_owned();
431+
world_state.update_configuration(
432+
new_config.lru_capacity,
433+
get_options(&new_config, text_document_caps),
434+
get_feature_flags(&new_config, connection),
435+
);
436+
}
430437
}
431438
}
432439
},
@@ -657,13 +664,15 @@ fn on_notification(
657664
Err(not) => not,
658665
};
659666
let not = match notification_cast::<req::DidChangeConfiguration>(not) {
660-
Ok(_params) => {
667+
Ok(_) => {
668+
// As stated in https://github.com/microsoft/language-server-protocol/issues/676,
669+
// this notification's parameters should be ignored and the actual config queried separately.
661670
let request_id = loop_state.next_request_id();
662671
let request = request_new::<req::WorkspaceConfiguration>(
663672
request_id.clone(),
664673
ConfigurationParams::default(),
665674
);
666-
msg_sender.send(request.into()).unwrap();
675+
msg_sender.send(request.into())?;
667676
loop_state.configuration_request_id.replace(request_id);
668677

669678
return Ok(());

editors/code/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Config } from './config';
55
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
66
import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
77

8-
export function configToOptions(config: Config): object {
8+
export function configToServerOptions(config: Config): object {
99
return {
1010
publishDecorations: !config.highlightingSemanticTokens,
1111
lruCapacity: config.lruCapacity,
@@ -50,7 +50,7 @@ export async function createClient(config: Config, serverPath: string): Promise<
5050

5151
const clientOptions: lc.LanguageClientOptions = {
5252
documentSelector: [{ scheme: 'file', language: 'rust' }],
53-
initializationOptions: configToOptions(config),
53+
initializationOptions: configToServerOptions(config),
5454
traceOutputChannel,
5555
middleware: {
5656
// Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576

editors/code/src/ctx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import * as lc from 'vscode-languageclient';
33

44
import { Config } from './config';
5-
import { createClient, configToOptions } from './client';
5+
import { createClient, configToServerOptions } from './client';
66
import { isRustEditor, RustEditor } from './util';
77

88
export class Ctx {
@@ -20,7 +20,7 @@ export class Ctx {
2020
const res = new Ctx(config, extCtx, client, serverPath);
2121
res.pushCleanup(client.start());
2222
await client.onReady();
23-
client.onRequest('workspace/configuration', _ => [configToOptions(config)]);
23+
client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
2424
return res;
2525
}
2626

editors/code/src/inlay_hints.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export function activateInlayHints(ctx: Ctx) {
1818
return this.dispose();
1919
}
2020
if (!this.updater) this.updater = new HintsUpdater(ctx);
21+
22+
this.updater.syncCacheAndRenderHints();
2123
},
2224
dispose() {
2325
this.updater?.dispose();
@@ -124,7 +126,7 @@ class HintsUpdater implements Disposable {
124126
this.syncCacheAndRenderHints();
125127
}
126128

127-
private syncCacheAndRenderHints() {
129+
public syncCacheAndRenderHints() {
128130
// FIXME: make inlayHints request pass an array of files?
129131
this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => {
130132
if (!hints) return;

0 commit comments

Comments
 (0)