mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Use american spelling for config
As per
171c3c08fe/docs/dev/style.md (variable-naming)
Also implement config aliasing, for pain-free settings migrations in the future
This commit is contained in:
parent
c8ace3a295
commit
037caec62c
3 changed files with 24 additions and 11 deletions
|
@ -7,7 +7,7 @@
|
||||||
//! configure the server itself, feature flags are passed into analysis, and
|
//! configure the server itself, feature flags are passed into analysis, and
|
||||||
//! tweak things like automatic insertion of `()` in completions.
|
//! tweak things like automatic insertion of `()` in completions.
|
||||||
|
|
||||||
use std::{convert::TryFrom, ffi::OsString, path::PathBuf};
|
use std::{convert::TryFrom, ffi::OsString, iter, path::PathBuf};
|
||||||
|
|
||||||
use flycheck::FlycheckConfig;
|
use flycheck::FlycheckConfig;
|
||||||
use hir::PrefixKind;
|
use hir::PrefixKind;
|
||||||
|
@ -28,6 +28,7 @@ use crate::{caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfi
|
||||||
config_data! {
|
config_data! {
|
||||||
struct ConfigData {
|
struct ConfigData {
|
||||||
/// The strategy to use when inserting new imports or merging imports.
|
/// The strategy to use when inserting new imports or merging imports.
|
||||||
|
assist_importMergeBehavior |
|
||||||
assist_importMergeBehaviour: MergeBehaviorDef = "\"full\"",
|
assist_importMergeBehaviour: MergeBehaviorDef = "\"full\"",
|
||||||
/// The path structure for newly inserted paths to use.
|
/// The path structure for newly inserted paths to use.
|
||||||
assist_importPrefix: ImportPrefixDef = "\"plain\"",
|
assist_importPrefix: ImportPrefixDef = "\"plain\"",
|
||||||
|
@ -530,7 +531,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn merge_behavior(&self) -> Option<MergeBehavior> {
|
fn merge_behavior(&self) -> Option<MergeBehavior> {
|
||||||
match self.data.assist_importMergeBehaviour {
|
match self.data.assist_importMergeBehavior {
|
||||||
MergeBehaviorDef::None => None,
|
MergeBehaviorDef::None => None,
|
||||||
MergeBehaviorDef::Full => Some(MergeBehavior::Full),
|
MergeBehaviorDef::Full => Some(MergeBehavior::Full),
|
||||||
MergeBehaviorDef::Last => Some(MergeBehavior::Last),
|
MergeBehaviorDef::Last => Some(MergeBehavior::Last),
|
||||||
|
@ -639,7 +640,7 @@ macro_rules! _config_data {
|
||||||
(struct $name:ident {
|
(struct $name:ident {
|
||||||
$(
|
$(
|
||||||
$(#[doc=$doc:literal])*
|
$(#[doc=$doc:literal])*
|
||||||
$field:ident: $ty:ty = $default:expr,
|
$field:ident $(| $alias:ident)?: $ty:ty = $default:expr,
|
||||||
)*
|
)*
|
||||||
}) => {
|
}) => {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
@ -648,7 +649,12 @@ macro_rules! _config_data {
|
||||||
impl $name {
|
impl $name {
|
||||||
fn from_json(mut json: serde_json::Value) -> $name {
|
fn from_json(mut json: serde_json::Value) -> $name {
|
||||||
$name {$(
|
$name {$(
|
||||||
$field: get_field(&mut json, stringify!($field), $default),
|
$field: get_field(
|
||||||
|
&mut json,
|
||||||
|
stringify!($field),
|
||||||
|
None$(.or(Some(stringify!($alias))))?,
|
||||||
|
$default,
|
||||||
|
),
|
||||||
)*}
|
)*}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,14 +686,21 @@ use _config_data as config_data;
|
||||||
fn get_field<T: DeserializeOwned>(
|
fn get_field<T: DeserializeOwned>(
|
||||||
json: &mut serde_json::Value,
|
json: &mut serde_json::Value,
|
||||||
field: &'static str,
|
field: &'static str,
|
||||||
|
alias: Option<&'static str>,
|
||||||
default: &str,
|
default: &str,
|
||||||
) -> T {
|
) -> T {
|
||||||
let default = serde_json::from_str(default).unwrap();
|
let default = serde_json::from_str(default).unwrap();
|
||||||
|
|
||||||
|
// XXX: check alias first, to work-around the VS Code where it pre-fills the
|
||||||
|
// defaults instead of sending an empty object.
|
||||||
|
alias
|
||||||
|
.into_iter()
|
||||||
|
.chain(iter::once(field))
|
||||||
|
.find_map(move |field| {
|
||||||
let mut pointer = field.replace('_', "/");
|
let mut pointer = field.replace('_', "/");
|
||||||
pointer.insert(0, '/');
|
pointer.insert(0, '/');
|
||||||
json.pointer_mut(&pointer)
|
json.pointer_mut(&pointer).and_then(|it| serde_json::from_value(it.take()).ok())
|
||||||
.and_then(|it| serde_json::from_value(it.take()).ok())
|
})
|
||||||
.unwrap_or(default)
|
.unwrap_or(default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[[rust-analyzer.assist.importMergeBehaviour]]rust-analyzer.assist.importMergeBehaviour (default: `"full"`)::
|
[[rust-analyzer.assist.importMergeBehavior]]rust-analyzer.assist.importMergeBehavior (default: `"full"`)::
|
||||||
The strategy to use when inserting new imports or merging imports.
|
The strategy to use when inserting new imports or merging imports.
|
||||||
[[rust-analyzer.assist.importPrefix]]rust-analyzer.assist.importPrefix (default: `"plain"`)::
|
[[rust-analyzer.assist.importPrefix]]rust-analyzer.assist.importPrefix (default: `"plain"`)::
|
||||||
The path structure for newly inserted paths to use.
|
The path structure for newly inserted paths to use.
|
||||||
|
|
|
@ -349,7 +349,7 @@
|
||||||
"default": {},
|
"default": {},
|
||||||
"markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`"
|
"markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`"
|
||||||
},
|
},
|
||||||
"rust-analyzer.assist.importMergeBehaviour": {
|
"rust-analyzer.assist.importMergeBehavior": {
|
||||||
"markdownDescription": "The strategy to use when inserting new imports or merging imports.",
|
"markdownDescription": "The strategy to use when inserting new imports or merging imports.",
|
||||||
"default": "full",
|
"default": "full",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
Loading…
Reference in a new issue