aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-07 12:07:49 +0000
committerGitHub <[email protected]>2021-01-07 12:07:49 +0000
commitc3e9fb183bc287d83b97b776edc87c54d18d1a73 (patch)
treed81cef123586950822b88581454f3bf1a86f8349 /crates
parent171c3c08fe245938fb25321394233de5fe2abc7c (diff)
parent037caec62c881e11325f93627d9bfd44fb374d51 (diff)
Merge #7192
7192: Use american spelling for config r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/config.rs31
1 files changed, 22 insertions, 9 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