Skip to content

Commit 48c5830

Browse files
committed
Lean onto default implementation of configs
1 parent e4cf40a commit 48c5830

File tree

8 files changed

+24
-70
lines changed

8 files changed

+24
-70
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub struct Config {
3838

3939
#[derive(Debug, Clone)]
4040
pub struct FilesConfig {
41-
watcher: FilesWatcher,
42-
exclude: Vec<String>,
41+
pub watcher: FilesWatcher,
42+
pub exclude: Vec<String>,
4343
}
4444

4545
#[derive(Debug, Clone)]
46-
enum FilesWatcher {
46+
pub enum FilesWatcher {
4747
Client,
4848
Notify,
4949
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use serde::{de::DeserializeOwned, Serialize};
3030
use threadpool::ThreadPool;
3131

3232
use crate::{
33-
config::Config,
33+
config::{Config, FilesWatcher},
3434
diagnostics::DiagnosticTask,
3535
main_loop::{
3636
pending_requests::{PendingRequest, PendingRequests},
@@ -40,7 +40,6 @@ use crate::{
4040
world::{WorldSnapshot, WorldState},
4141
Result,
4242
};
43-
use req::ConfigurationParams;
4443

4544
#[derive(Debug)]
4645
pub struct LspError {
@@ -122,12 +121,13 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
122121
};
123122

124123
let globs = config
125-
.exclude_globs
124+
.files
125+
.exclude
126126
.iter()
127127
.map(|glob| crate::vfs_glob::Glob::new(glob))
128128
.collect::<std::result::Result<Vec<_>, _>>()?;
129129

130-
if config.use_client_watching {
130+
if let FilesWatcher::Client = config.files.watcher {
131131
let registration_options = req::DidChangeWatchedFilesRegistrationOptions {
132132
watchers: workspaces
133133
.iter()
@@ -153,7 +153,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
153153
workspaces,
154154
config.lru_capacity,
155155
&globs,
156-
Watch(!config.use_client_watching),
156+
Watch(matches!(config.files.watcher, FilesWatcher::Notify)),
157157
config,
158158
)
159159
};
@@ -607,7 +607,12 @@ fn on_notification(
607607
let request_id = loop_state.next_request_id();
608608
let request = request_new::<req::WorkspaceConfiguration>(
609609
request_id.clone(),
610-
ConfigurationParams::default(),
610+
req::ConfigurationParams {
611+
items: vec![req::ConfigurationItem {
612+
scope_uri: None,
613+
section: Some("rust-analyzer".to_string()),
614+
}],
615+
},
611616
);
612617
msg_sender.send(request.into())?;
613618
loop_state.configuration_request_id = Some(request_id);

crates/rust-analyzer/src/req.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize};
66

77
pub use lsp_types::{
88
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
9-
CodeLensParams, CompletionParams, CompletionResponse, ConfigurationParams, DiagnosticTag,
10-
DidChangeConfigurationParams, DidChangeWatchedFilesParams,
9+
CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
10+
DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
1111
DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams,
1212
DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType,
1313
PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken,

editors/code/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@
217217
"type": "boolean",
218218
"markdownDescription": "Whether to show `can't find Cargo.toml` error message"
219219
},
220-
221220
"rust-analyzer.cargo.noDefaultFeatures": {
222221
"type": "boolean",
223222
"default": false,
@@ -272,7 +271,6 @@
272271
"default": true,
273272
"markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)"
274273
},
275-
276274
"rust-analyzer.inlayHints.typeHints": {
277275
"type": "boolean",
278276
"default": true,
@@ -298,7 +296,6 @@
298296
"exclusiveMinimum": true,
299297
"description": "Maximum length for inlay hints"
300298
},
301-
302299
"rust-analyzer.completion.addCallParenthesis": {
303300
"type": "boolean",
304301
"default": true,
@@ -318,7 +315,6 @@
318315
"type": "boolean",
319316
"description": "Show function name and docs in parameter hints"
320317
},
321-
322318
"rust-analyzer.highlighting.semanticTokens": {
323319
"type": "boolean",
324320
"default": false,
@@ -370,7 +366,7 @@
370366
"description": "Enable logging of VS Code extensions itself",
371367
"type": "boolean",
372368
"default": false
373-
},
369+
}
374370
}
375371
},
376372
"problemPatterns": [

editors/code/src/client.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@ 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 configToServerOptions(config: Config) {
9-
return {
10-
lruCapacity: config.lruCapacity,
11-
12-
inlayHintsType: config.inlayHints.typeHints,
13-
inlayHintsParameter: config.inlayHints.parameterHints,
14-
inlayHintsChaining: config.inlayHints.chainingHints,
15-
inlayHintsMaxLength: config.inlayHints.maxLength,
16-
17-
cargoWatchEnable: config.cargoWatchOptions.enable,
18-
cargoWatchArgs: config.cargoWatchOptions.arguments,
19-
cargoWatchCommand: config.cargoWatchOptions.command,
20-
cargoWatchAllTargets: config.cargoWatchOptions.allTargets,
21-
22-
excludeGlobs: config.excludeGlobs,
23-
useClientWatching: config.useClientWatching,
24-
featureFlags: config.featureFlags,
25-
withSysroot: config.withSysroot,
26-
cargoFeatures: config.cargoFeatures,
27-
rustfmtArgs: config.rustfmtArgs,
28-
vscodeLldb: vscode.extensions.getExtension("vadimcn.vscode-lldb") != null,
29-
};
30-
}
31-
328
export async function createClient(config: Config, serverPath: string, cwd: string): Promise<lc.LanguageClient> {
339
// '.' Is the fallback if no folder is open
3410
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
@@ -48,7 +24,7 @@ export async function createClient(config: Config, serverPath: string, cwd: stri
4824

4925
const clientOptions: lc.LanguageClientOptions = {
5026
documentSelector: [{ scheme: 'file', language: 'rust' }],
51-
initializationOptions: configToServerOptions(config),
27+
initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
5228
traceOutputChannel,
5329
middleware: {
5430
// Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576

editors/code/src/config.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ export class Config {
1111
private readonly rootSection = "rust-analyzer";
1212
private readonly requiresReloadOpts = [
1313
"serverPath",
14-
"cargoFeatures",
15-
"excludeGlobs",
16-
"useClientWatching",
14+
"cargo",
15+
"files",
1716
"highlighting",
1817
"updates.channel",
1918
]
@@ -71,17 +70,8 @@ export class Config {
7170
get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; }
7271
get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; }
7372
get highlightingSemanticTokens() { return this.cfg.get<boolean>("highlighting.semanticTokens")!; }
74-
get lruCapacity() { return this.cfg.get<null | number>("lruCapacity")!; }
75-
get excludeGlobs() { return this.cfg.get<string[]>("excludeGlobs")!; }
76-
get useClientWatching() { return this.cfg.get<boolean>("useClientWatching")!; }
77-
get featureFlags() { return this.cfg.get<Record<string, boolean>>("featureFlags")!; }
78-
get rustfmtArgs() { return this.cfg.get<string[]>("rustfmtArgs")!; }
79-
get loadOutDirsFromCheck() { return this.cfg.get<boolean>("loadOutDirsFromCheck")!; }
8073
get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; }
8174

82-
// for internal use
83-
get withSysroot() { return this.cfg.get<boolean>("withSysroot", true)!; }
84-
8575
get inlayHints() {
8676
return {
8777
typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!,
@@ -91,21 +81,9 @@ export class Config {
9181
};
9282
}
9383

94-
get cargoWatchOptions() {
95-
return {
96-
enable: this.cfg.get<boolean>("cargo-watch.enable")!,
97-
arguments: this.cfg.get<string[]>("cargo-watch.arguments")!,
98-
allTargets: this.cfg.get<boolean>("cargo-watch.allTargets")!,
99-
command: this.cfg.get<string>("cargo-watch.command")!,
100-
};
101-
}
102-
103-
get cargoFeatures() {
84+
get checkOnSave() {
10485
return {
105-
noDefaultFeatures: this.cfg.get<boolean>("cargoFeatures.noDefaultFeatures")!,
106-
allFeatures: this.cfg.get<boolean>("cargoFeatures.allFeatures")!,
107-
features: this.cfg.get<string[]>("cargoFeatures.features")!,
108-
loadOutDirsFromCheck: this.cfg.get<boolean>("cargoFeatures.loadOutDirsFromCheck")!,
86+
command: this.cfg.get<string>("checkOnSave.command")!,
10987
};
11088
}
11189
}

editors/code/src/ctx.ts

Lines changed: 1 addition & 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, configToServerOptions } from './client';
5+
import { createClient } from './client';
66
import { isRustEditor, RustEditor } from './util';
77

88
export class Ctx {
@@ -25,7 +25,6 @@ export class Ctx {
2525
const res = new Ctx(config, extCtx, client, serverPath);
2626
res.pushCleanup(client.start());
2727
await client.onReady();
28-
client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]);
2928
return res;
3029
}
3130

editors/code/src/status_display.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Ctx } from './ctx';
77
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
88

99
export function activateStatusDisplay(ctx: Ctx) {
10-
const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
10+
const statusDisplay = new StatusDisplay(ctx.config.checkOnSave.command);
1111
ctx.pushCleanup(statusDisplay);
1212
const client = ctx.client;
1313
if (client != null) {

0 commit comments

Comments
 (0)