aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/main_loop.rs39
-rw-r--r--editors/code/src/client.ts4
-rw-r--r--editors/code/src/ctx.ts4
-rw-r--r--editors/code/src/inlay_hints.ts4
4 files changed, 31 insertions, 20 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 85bde90bb..a64dccd58 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -413,20 +413,27 @@ fn loop_turn(
413 if !removed { 413 if !removed {
414 log::error!("unexpected response: {:?}", resp) 414 log::error!("unexpected response: {:?}", resp)
415 } 415 }
416 if Some(&resp.id) == loop_state.configuration_request_id.as_ref() { 416
417 if Some(resp.id) == loop_state.configuration_request_id {
417 loop_state.configuration_request_id.take(); 418 loop_state.configuration_request_id.take();
418 // TODO kb unwrap-unwrap-unwrap 419 if let Some(err) = resp.error {
419 let new_config = 420 log::error!("failed fetch the server settings: {:?}", err)
420 serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap()) 421 } else if resp.result.is_none() {
421 .unwrap() 422 log::error!("received empty server settings response from the client")
422 .first() 423 } else {
423 .unwrap() 424 let new_config =
424 .to_owned(); 425 serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap())?
425 world_state.update_configuration( 426 .first()
426 new_config.lru_capacity, 427 .expect(
427 get_options(&new_config, text_document_caps), 428 "The client is expected to always send a non-empty config data",
428 get_feature_flags(&new_config, connection), 429 )
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 }
430 } 437 }
431 } 438 }
432 }, 439 },
@@ -657,13 +664,15 @@ fn on_notification(
657 Err(not) => not, 664 Err(not) => not,
658 }; 665 };
659 let not = match notification_cast::<req::DidChangeConfiguration>(not) { 666 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.
661 let request_id = loop_state.next_request_id(); 670 let request_id = loop_state.next_request_id();
662 let request = request_new::<req::WorkspaceConfiguration>( 671 let request = request_new::<req::WorkspaceConfiguration>(
663 request_id.clone(), 672 request_id.clone(),
664 ConfigurationParams::default(), 673 ConfigurationParams::default(),
665 ); 674 );
666 msg_sender.send(request.into()).unwrap(); 675 msg_sender.send(request.into())?;
667 loop_state.configuration_request_id.replace(request_id); 676 loop_state.configuration_request_id.replace(request_id);
668 677
669 return Ok(()); 678 return Ok(());
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 0d0832c44..34965e2fb 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -5,7 +5,7 @@ import { Config } from './config';
5import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed'; 5import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
6import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed'; 6import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
7 7
8export function configToOptions(config: Config): object { 8export function configToServerOptions(config: Config): object {
9 return { 9 return {
10 publishDecorations: !config.highlightingSemanticTokens, 10 publishDecorations: !config.highlightingSemanticTokens,
11 lruCapacity: config.lruCapacity, 11 lruCapacity: config.lruCapacity,
@@ -50,7 +50,7 @@ export async function createClient(config: Config, serverPath: string): Promise<
50 50
51 const clientOptions: lc.LanguageClientOptions = { 51 const clientOptions: lc.LanguageClientOptions = {
52 documentSelector: [{ scheme: 'file', language: 'rust' }], 52 documentSelector: [{ scheme: 'file', language: 'rust' }],
53 initializationOptions: configToOptions(config), 53 initializationOptions: configToServerOptions(config),
54 traceOutputChannel, 54 traceOutputChannel,
55 middleware: { 55 middleware: {
56 // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576 56 // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 934638c6d..d2f49cd23 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3 3
4import { Config } from './config'; 4import { Config } from './config';
5import { createClient, configToOptions } from './client'; 5import { createClient, configToServerOptions } from './client';
6import { isRustEditor, RustEditor } from './util'; 6import { isRustEditor, RustEditor } from './util';
7 7
8export class Ctx { 8export class Ctx {
@@ -20,7 +20,7 @@ export class Ctx {
20 const res = new Ctx(config, extCtx, client, serverPath); 20 const res = new Ctx(config, extCtx, client, serverPath);
21 res.pushCleanup(client.start()); 21 res.pushCleanup(client.start());
22 await client.onReady(); 22 await client.onReady();
23 client.onRequest('workspace/configuration', _ => [configToOptions(config)]); 23 client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
24 return res; 24 return res;
25 } 25 }
26 26
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 542d1f367..98663e0e3 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -18,6 +18,8 @@ export function activateInlayHints(ctx: Ctx) {
18 return this.dispose(); 18 return this.dispose();
19 } 19 }
20 if (!this.updater) this.updater = new HintsUpdater(ctx); 20 if (!this.updater) this.updater = new HintsUpdater(ctx);
21
22 this.updater.syncCacheAndRenderHints();
21 }, 23 },
22 dispose() { 24 dispose() {
23 this.updater?.dispose(); 25 this.updater?.dispose();
@@ -124,7 +126,7 @@ class HintsUpdater implements Disposable {
124 this.syncCacheAndRenderHints(); 126 this.syncCacheAndRenderHints();
125 } 127 }
126 128
127 private syncCacheAndRenderHints() { 129 public syncCacheAndRenderHints() {
128 // FIXME: make inlayHints request pass an array of files? 130 // FIXME: make inlayHints request pass an array of files?
129 this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => { 131 this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => {
130 if (!hints) return; 132 if (!hints) return;