aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-30 13:45:49 +0100
committerGitHub <[email protected]>2020-03-30 13:45:49 +0100
commit671926ac93f0ff921758a919eaf87c056979189f (patch)
tree111c2cc751cb7fcca38eb7518e1d39af394ee243 /editors/code/src
parent9e12b9e6fdc03ea6bc35a88cfb5d5d6751672ec8 (diff)
parent4c897d8d2dd047e0906d585318866c9ae7a21610 (diff)
Merge #3666
3666: Reload part of the server configuration without restarts r=matklad a=SomeoneToIgnore Partially addresses https://github.com/rust-analyzer/rust-analyzer/issues/2857 Closes #3751 Reloads all server configuration that's not related to VFS without restarts. The VFS-related parameters are not considered, since VFS is planned to be rewritten/replaced in the future and I have a suspicion that with the current code, swapping the VFS and the file watchers on the fly will cause big troubles. I have to store and process the config request id separately, since the `workspace/configuration` response returns `any[]` (https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration), if there's a better way to handle those responses, let me know. Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/client.ts49
-rw-r--r--editors/code/src/config.ts6
-rw-r--r--editors/code/src/ctx.ts3
-rw-r--r--editors/code/src/inlay_hints.ts8
-rw-r--r--editors/code/src/main.ts6
5 files changed, 43 insertions, 29 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 98f2f232f..d72ecc58f 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -5,6 +5,31 @@ 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 configToServerOptions(config: Config) {
9 return {
10 publishDecorations: !config.highlightingSemanticTokens,
11 lruCapacity: config.lruCapacity,
12
13 inlayHintsType: config.inlayHints.typeHints,
14 inlayHintsParameter: config.inlayHints.parameterHints,
15 inlayHintsChaining: config.inlayHints.chainingHints,
16 inlayHintsMaxLength: config.inlayHints.maxLength,
17
18 cargoWatchEnable: config.cargoWatchOptions.enable,
19 cargoWatchArgs: config.cargoWatchOptions.arguments,
20 cargoWatchCommand: config.cargoWatchOptions.command,
21 cargoWatchAllTargets: config.cargoWatchOptions.allTargets,
22
23 excludeGlobs: config.excludeGlobs,
24 useClientWatching: config.useClientWatching,
25 featureFlags: config.featureFlags,
26 withSysroot: config.withSysroot,
27 cargoFeatures: config.cargoFeatures,
28 rustfmtArgs: config.rustfmtArgs,
29 vscodeLldb: vscode.extensions.getExtension("vadimcn.vscode-lldb") != null,
30 };
31}
32
8export async function createClient(config: Config, serverPath: string): Promise<lc.LanguageClient> { 33export async function createClient(config: Config, serverPath: string): Promise<lc.LanguageClient> {
9 // '.' Is the fallback if no folder is open 34 // '.' Is the fallback if no folder is open
10 // TODO?: Workspace folders support Uri's (eg: file://test.txt). 35 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
@@ -22,32 +47,10 @@ export async function createClient(config: Config, serverPath: string): Promise<
22 const traceOutputChannel = vscode.window.createOutputChannel( 47 const traceOutputChannel = vscode.window.createOutputChannel(
23 'Rust Analyzer Language Server Trace', 48 'Rust Analyzer Language Server Trace',
24 ); 49 );
25 const cargoWatchOpts = config.cargoWatchOptions;
26 50
27 const clientOptions: lc.LanguageClientOptions = { 51 const clientOptions: lc.LanguageClientOptions = {
28 documentSelector: [{ scheme: 'file', language: 'rust' }], 52 documentSelector: [{ scheme: 'file', language: 'rust' }],
29 initializationOptions: { 53 initializationOptions: configToServerOptions(config),
30 publishDecorations: !config.highlightingSemanticTokens,
31 lruCapacity: config.lruCapacity,
32
33 inlayHintsType: config.inlayHints.typeHints,
34 inlayHintsParameter: config.inlayHints.parameterHints,
35 inlayHintsChaining: config.inlayHints.chainingHints,
36 inlayHintsMaxLength: config.inlayHints.maxLength,
37
38 cargoWatchEnable: cargoWatchOpts.enable,
39 cargoWatchArgs: cargoWatchOpts.arguments,
40 cargoWatchCommand: cargoWatchOpts.command,
41 cargoWatchAllTargets: cargoWatchOpts.allTargets,
42
43 excludeGlobs: config.excludeGlobs,
44 useClientWatching: config.useClientWatching,
45 featureFlags: config.featureFlags,
46 withSysroot: config.withSysroot,
47 cargoFeatures: config.cargoFeatures,
48 rustfmtArgs: config.rustfmtArgs,
49 vscodeLldb: vscode.extensions.getExtension("vadimcn.vscode-lldb") != null,
50 },
51 traceOutputChannel, 54 traceOutputChannel,
52 middleware: { 55 middleware: {
53 // 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/config.ts b/editors/code/src/config.ts
index e77462c1b..501997fef 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -12,9 +12,9 @@ export class Config {
12 private readonly requiresReloadOpts = [ 12 private readonly requiresReloadOpts = [
13 "serverPath", 13 "serverPath",
14 "cargoFeatures", 14 "cargoFeatures",
15 "cargo-watch", 15 "excludeGlobs",
16 "highlighting.semanticTokens", 16 "useClientWatching",
17 "inlayHints", 17 "highlighting",
18 "updates.channel", 18 "updates.channel",
19 ] 19 ]
20 .map(opt => `${this.rootSection}.${opt}`); 20 .map(opt => `${this.rootSection}.${opt}`);
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 84c170ea8..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 } 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,6 +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', _ => [configToServerOptions(config)]);
23 return res; 24 return res;
24 } 25 }
25 26
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 542d1f367..6a8bd942e 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -17,7 +17,11 @@ export function activateInlayHints(ctx: Ctx) {
17 ) { 17 ) {
18 return this.dispose(); 18 return this.dispose();
19 } 19 }
20 if (!this.updater) this.updater = new HintsUpdater(ctx); 20 if (this.updater) {
21 this.updater.syncCacheAndRenderHints();
22 } else {
23 this.updater = new HintsUpdater(ctx);
24 }
21 }, 25 },
22 dispose() { 26 dispose() {
23 this.updater?.dispose(); 27 this.updater?.dispose();
@@ -124,7 +128,7 @@ class HintsUpdater implements Disposable {
124 this.syncCacheAndRenderHints(); 128 this.syncCacheAndRenderHints();
125 } 129 }
126 130
127 private syncCacheAndRenderHints() { 131 syncCacheAndRenderHints() {
128 // FIXME: make inlayHints request pass an array of files? 132 // FIXME: make inlayHints request pass an array of files?
129 this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => { 133 this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => {
130 if (!hints) return; 134 if (!hints) return;
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 980ed925b..a46dbde33 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -91,6 +91,12 @@ export async function activate(context: vscode.ExtensionContext) {
91 activateHighlighting(ctx); 91 activateHighlighting(ctx);
92 } 92 }
93 activateInlayHints(ctx); 93 activateInlayHints(ctx);
94
95 vscode.workspace.onDidChangeConfiguration(
96 _ => ctx?.client?.sendNotification('workspace/didChangeConfiguration', { settings: "" }),
97 null,
98 ctx.subscriptions,
99 );
94} 100}
95 101
96export async function deactivate() { 102export async function deactivate() {