aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-01-07 11:37:38 +0000
committerAleksey Kladov <[email protected]>2021-01-07 12:07:19 +0000
commit037caec62c881e11325f93627d9bfd44fb374d51 (patch)
treed81cef123586950822b88581454f3bf1a86f8349
parentc8ace3a295aa63ff7f210f11840e7fc9de65264c (diff)
Use american spelling for config
As per https://github.com/rust-analyzer/rust-analyzer/blob/171c3c08fe245938fb25321394233de5fe2abc7c/docs/dev/style.md#variable-naming Also implement config aliasing, for pain-free settings migrations in the future
-rw-r--r--crates/rust-analyzer/src/config.rs31
-rw-r--r--docs/user/generated_config.adoc2
-rw-r--r--editors/code/package.json2
3 files changed, 24 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index e3ba81ac6..2d3e25cbf 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -7,7 +7,7 @@
7//! configure the server itself, feature flags are passed into analysis, and 7//! configure the server itself, feature flags are passed into analysis, and
8//! tweak things like automatic insertion of `()` in completions. 8//! tweak things like automatic insertion of `()` in completions.
9 9
10use std::{convert::TryFrom, ffi::OsString, path::PathBuf}; 10use std::{convert::TryFrom, ffi::OsString, iter, path::PathBuf};
11 11
12use flycheck::FlycheckConfig; 12use flycheck::FlycheckConfig;
13use hir::PrefixKind; 13use hir::PrefixKind;
@@ -28,7 +28,8 @@ use crate::{caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfi
28config_data! { 28config_data! {
29 struct ConfigData { 29 struct ConfigData {
30 /// The strategy to use when inserting new imports or merging imports. 30 /// The strategy to use when inserting new imports or merging imports.
31 assist_importMergeBehaviour: MergeBehaviorDef = "\"full\"", 31 assist_importMergeBehavior |
32 assist_importMergeBehaviour: MergeBehaviorDef = "\"full\"",
32 /// The path structure for newly inserted paths to use. 33 /// The path structure for newly inserted paths to use.
33 assist_importPrefix: ImportPrefixDef = "\"plain\"", 34 assist_importPrefix: ImportPrefixDef = "\"plain\"",
34 35
@@ -530,7 +531,7 @@ impl Config {
530 } 531 }
531 } 532 }
532 fn merge_behavior(&self) -> Option<MergeBehavior> { 533 fn merge_behavior(&self) -> Option<MergeBehavior> {
533 match self.data.assist_importMergeBehaviour { 534 match self.data.assist_importMergeBehavior {
534 MergeBehaviorDef::None => None, 535 MergeBehaviorDef::None => None,
535 MergeBehaviorDef::Full => Some(MergeBehavior::Full), 536 MergeBehaviorDef::Full => Some(MergeBehavior::Full),
536 MergeBehaviorDef::Last => Some(MergeBehavior::Last), 537 MergeBehaviorDef::Last => Some(MergeBehavior::Last),
@@ -639,7 +640,7 @@ macro_rules! _config_data {
639 (struct $name:ident { 640 (struct $name:ident {
640 $( 641 $(
641 $(#[doc=$doc:literal])* 642 $(#[doc=$doc:literal])*
642 $field:ident: $ty:ty = $default:expr, 643 $field:ident $(| $alias:ident)?: $ty:ty = $default:expr,
643 )* 644 )*
644 }) => { 645 }) => {
645 #[allow(non_snake_case)] 646 #[allow(non_snake_case)]
@@ -648,7 +649,12 @@ macro_rules! _config_data {
648 impl $name { 649 impl $name {
649 fn from_json(mut json: serde_json::Value) -> $name { 650 fn from_json(mut json: serde_json::Value) -> $name {
650 $name {$( 651 $name {$(
651 $field: get_field(&mut json, stringify!($field), $default), 652 $field: get_field(
653 &mut json,
654 stringify!($field),
655 None$(.or(Some(stringify!($alias))))?,
656 $default,
657 ),
652 )*} 658 )*}
653 } 659 }
654 660
@@ -680,14 +686,21 @@ use _config_data as config_data;
680fn get_field<T: DeserializeOwned>( 686fn get_field<T: DeserializeOwned>(
681 json: &mut serde_json::Value, 687 json: &mut serde_json::Value,
682 field: &'static str, 688 field: &'static str,
689 alias: Option<&'static str>,
683 default: &str, 690 default: &str,
684) -> T { 691) -> T {
685 let default = serde_json::from_str(default).unwrap(); 692 let default = serde_json::from_str(default).unwrap();
686 693
687 let mut pointer = field.replace('_', "/"); 694 // XXX: check alias first, to work-around the VS Code where it pre-fills the
688 pointer.insert(0, '/'); 695 // defaults instead of sending an empty object.
689 json.pointer_mut(&pointer) 696 alias
690 .and_then(|it| serde_json::from_value(it.take()).ok()) 697 .into_iter()
698 .chain(iter::once(field))
699 .find_map(move |field| {
700 let mut pointer = field.replace('_', "/");
701 pointer.insert(0, '/');
702 json.pointer_mut(&pointer).and_then(|it| serde_json::from_value(it.take()).ok())
703 })
691 .unwrap_or(default) 704 .unwrap_or(default)
692} 705}
693 706
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index e45ea5c35..a76c99d1e 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -1,4 +1,4 @@
1[[rust-analyzer.assist.importMergeBehaviour]]rust-analyzer.assist.importMergeBehaviour (default: `"full"`):: 1[[rust-analyzer.assist.importMergeBehavior]]rust-analyzer.assist.importMergeBehavior (default: `"full"`)::
2 The strategy to use when inserting new imports or merging imports. 2 The strategy to use when inserting new imports or merging imports.
3[[rust-analyzer.assist.importPrefix]]rust-analyzer.assist.importPrefix (default: `"plain"`):: 3[[rust-analyzer.assist.importPrefix]]rust-analyzer.assist.importPrefix (default: `"plain"`)::
4 The path structure for newly inserted paths to use. 4 The path structure for newly inserted paths to use.
diff --git a/editors/code/package.json b/editors/code/package.json
index ea7f0990c..3e6ebd7ed 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -349,7 +349,7 @@
349 "default": {}, 349 "default": {},
350 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`" 350 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`"
351 }, 351 },
352 "rust-analyzer.assist.importMergeBehaviour": { 352 "rust-analyzer.assist.importMergeBehavior": {
353 "markdownDescription": "The strategy to use when inserting new imports or merging imports.", 353 "markdownDescription": "The strategy to use when inserting new imports or merging imports.",
354 "default": "full", 354 "default": "full",
355 "type": "string", 355 "type": "string",