mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Style fixes
This commit is contained in:
parent
332799d914
commit
8a23bec2cd
4 changed files with 31 additions and 20 deletions
|
@ -413,14 +413,20 @@ fn loop_turn(
|
||||||
if !removed {
|
if !removed {
|
||||||
log::error!("unexpected response: {:?}", resp)
|
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();
|
loop_state.configuration_request_id.take();
|
||||||
// TODO kb unwrap-unwrap-unwrap
|
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 =
|
let new_config =
|
||||||
serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap())
|
serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap())?
|
||||||
.unwrap()
|
|
||||||
.first()
|
.first()
|
||||||
.unwrap()
|
.expect(
|
||||||
|
"The client is expected to always send a non-empty config data",
|
||||||
|
)
|
||||||
.to_owned();
|
.to_owned();
|
||||||
world_state.update_configuration(
|
world_state.update_configuration(
|
||||||
new_config.lru_capacity,
|
new_config.lru_capacity,
|
||||||
|
@ -429,6 +435,7 @@ fn loop_turn(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -657,13 +664,15 @@ fn on_notification(
|
||||||
Err(not) => not,
|
Err(not) => not,
|
||||||
};
|
};
|
||||||
let not = match notification_cast::<req::DidChangeConfiguration>(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_id = loop_state.next_request_id();
|
||||||
let request = request_new::<req::WorkspaceConfiguration>(
|
let request = request_new::<req::WorkspaceConfiguration>(
|
||||||
request_id.clone(),
|
request_id.clone(),
|
||||||
ConfigurationParams::default(),
|
ConfigurationParams::default(),
|
||||||
);
|
);
|
||||||
msg_sender.send(request.into()).unwrap();
|
msg_sender.send(request.into())?;
|
||||||
loop_state.configuration_request_id.replace(request_id);
|
loop_state.configuration_request_id.replace(request_id);
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Config } from './config';
|
||||||
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
|
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
|
||||||
import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
|
import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed';
|
||||||
|
|
||||||
export function configToOptions(config: Config): object {
|
export function configToServerOptions(config: Config): object {
|
||||||
return {
|
return {
|
||||||
publishDecorations: !config.highlightingSemanticTokens,
|
publishDecorations: !config.highlightingSemanticTokens,
|
||||||
lruCapacity: config.lruCapacity,
|
lruCapacity: config.lruCapacity,
|
||||||
|
@ -50,7 +50,7 @@ export async function createClient(config: Config, serverPath: string): Promise<
|
||||||
|
|
||||||
const clientOptions: lc.LanguageClientOptions = {
|
const clientOptions: lc.LanguageClientOptions = {
|
||||||
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
||||||
initializationOptions: configToOptions(config),
|
initializationOptions: configToServerOptions(config),
|
||||||
traceOutputChannel,
|
traceOutputChannel,
|
||||||
middleware: {
|
middleware: {
|
||||||
// Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
|
// Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as lc from 'vscode-languageclient';
|
||||||
|
|
||||||
import { Config } from './config';
|
import { Config } from './config';
|
||||||
import { createClient, configToOptions } from './client';
|
import { createClient, configToServerOptions } from './client';
|
||||||
import { isRustEditor, RustEditor } from './util';
|
import { isRustEditor, RustEditor } from './util';
|
||||||
|
|
||||||
export class Ctx {
|
export class Ctx {
|
||||||
|
@ -20,7 +20,7 @@ export class Ctx {
|
||||||
const res = new Ctx(config, extCtx, client, serverPath);
|
const res = new Ctx(config, extCtx, client, serverPath);
|
||||||
res.pushCleanup(client.start());
|
res.pushCleanup(client.start());
|
||||||
await client.onReady();
|
await client.onReady();
|
||||||
client.onRequest('workspace/configuration', _ => [configToOptions(config)]);
|
client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ export function activateInlayHints(ctx: Ctx) {
|
||||||
return this.dispose();
|
return this.dispose();
|
||||||
}
|
}
|
||||||
if (!this.updater) this.updater = new HintsUpdater(ctx);
|
if (!this.updater) this.updater = new HintsUpdater(ctx);
|
||||||
|
|
||||||
|
this.updater.syncCacheAndRenderHints();
|
||||||
},
|
},
|
||||||
dispose() {
|
dispose() {
|
||||||
this.updater?.dispose();
|
this.updater?.dispose();
|
||||||
|
@ -124,7 +126,7 @@ class HintsUpdater implements Disposable {
|
||||||
this.syncCacheAndRenderHints();
|
this.syncCacheAndRenderHints();
|
||||||
}
|
}
|
||||||
|
|
||||||
private syncCacheAndRenderHints() {
|
public syncCacheAndRenderHints() {
|
||||||
// FIXME: make inlayHints request pass an array of files?
|
// FIXME: make inlayHints request pass an array of files?
|
||||||
this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => {
|
this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => {
|
||||||
if (!hints) return;
|
if (!hints) return;
|
||||||
|
|
Loading…
Reference in a new issue