mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Fix up adjustment hints configurations
This commit is contained in:
parent
95d20fccd7
commit
d841ad116a
4 changed files with 79 additions and 18 deletions
|
@ -53,7 +53,7 @@ pub enum LifetimeElisionHints {
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum AdjustmentHints {
|
pub enum AdjustmentHints {
|
||||||
Always,
|
Always,
|
||||||
MutableOnly,
|
ReborrowOnly,
|
||||||
Never,
|
Never,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,7 +675,9 @@ fn adjustment_hints(
|
||||||
for adjustment in adjustments.into_iter().rev() {
|
for adjustment in adjustments.into_iter().rev() {
|
||||||
// FIXME: Add some nicer tooltips to each of these
|
// FIXME: Add some nicer tooltips to each of these
|
||||||
let text = match adjustment {
|
let text = match adjustment {
|
||||||
Adjust::NeverToAny => "<never-to-any>",
|
Adjust::NeverToAny if config.adjustment_hints == AdjustmentHints::Always => {
|
||||||
|
"<never-to-any>"
|
||||||
|
}
|
||||||
Adjust::Deref(None) => "*",
|
Adjust::Deref(None) => "*",
|
||||||
Adjust::Deref(Some(OverloadedDeref(Mutability::Mut))) => "*",
|
Adjust::Deref(Some(OverloadedDeref(Mutability::Mut))) => "*",
|
||||||
Adjust::Deref(Some(OverloadedDeref(Mutability::Shared))) => "*",
|
Adjust::Deref(Some(OverloadedDeref(Mutability::Shared))) => "*",
|
||||||
|
@ -685,15 +687,20 @@ fn adjustment_hints(
|
||||||
Adjust::Borrow(AutoBorrow::RawPtr(Mutability::Mut)) => "&raw mut ",
|
Adjust::Borrow(AutoBorrow::RawPtr(Mutability::Mut)) => "&raw mut ",
|
||||||
// some of these could be represented via `as` casts, but that's not too nice and
|
// some of these could be represented via `as` casts, but that's not too nice and
|
||||||
// handling everything as a prefix expr makes the `(` and `)` insertion easier
|
// handling everything as a prefix expr makes the `(` and `)` insertion easier
|
||||||
Adjust::Pointer(cast) => match cast {
|
Adjust::Pointer(cast) if config.adjustment_hints == AdjustmentHints::Always => {
|
||||||
PointerCast::ReifyFnPointer => "<fn-item-to-fn-pointer>",
|
match cast {
|
||||||
PointerCast::UnsafeFnPointer => "<safe-fn-pointer-to-unsafe-fn-pointer>",
|
PointerCast::ReifyFnPointer => "<fn-item-to-fn-pointer>",
|
||||||
PointerCast::ClosureFnPointer(Safety::Unsafe) => "<closure-to-unsafe-fn-pointer>",
|
PointerCast::UnsafeFnPointer => "<safe-fn-pointer-to-unsafe-fn-pointer>",
|
||||||
PointerCast::ClosureFnPointer(Safety::Safe) => "<closure-to-fn-pointer>",
|
PointerCast::ClosureFnPointer(Safety::Unsafe) => {
|
||||||
PointerCast::MutToConstPointer => "<mut-ptr-to-const-ptr>",
|
"<closure-to-unsafe-fn-pointer>"
|
||||||
PointerCast::ArrayToPointer => "<array-ptr-to-element-ptr>",
|
}
|
||||||
PointerCast::Unsize => "<unsize>",
|
PointerCast::ClosureFnPointer(Safety::Safe) => "<closure-to-fn-pointer>",
|
||||||
},
|
PointerCast::MutToConstPointer => "<mut-ptr-to-const-ptr>",
|
||||||
|
PointerCast::ArrayToPointer => "<array-ptr-to-element-ptr>",
|
||||||
|
PointerCast::Unsize => "<unsize>",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => continue,
|
||||||
};
|
};
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
|
|
|
@ -321,6 +321,8 @@ config_data! {
|
||||||
inlayHints_closingBraceHints_minLines: usize = "25",
|
inlayHints_closingBraceHints_minLines: usize = "25",
|
||||||
/// Whether to show inlay type hints for return types of closures.
|
/// Whether to show inlay type hints for return types of closures.
|
||||||
inlayHints_closureReturnTypeHints_enable: ClosureReturnTypeHintsDef = "\"never\"",
|
inlayHints_closureReturnTypeHints_enable: ClosureReturnTypeHintsDef = "\"never\"",
|
||||||
|
/// Whether to show inlay hints for type adjustments.
|
||||||
|
inlayHints_expressionAdjustmentHints_enable: AdjustmentHintsDef = "\"never\"",
|
||||||
/// Whether to show inlay type hints for elided lifetimes in function signatures.
|
/// Whether to show inlay type hints for elided lifetimes in function signatures.
|
||||||
inlayHints_lifetimeElisionHints_enable: LifetimeElisionDef = "\"never\"",
|
inlayHints_lifetimeElisionHints_enable: LifetimeElisionDef = "\"never\"",
|
||||||
/// Whether to prefer using parameter names as the name for elided lifetime hints if possible.
|
/// Whether to prefer using parameter names as the name for elided lifetime hints if possible.
|
||||||
|
@ -330,7 +332,8 @@ config_data! {
|
||||||
/// Whether to show function parameter name inlay hints at the call
|
/// Whether to show function parameter name inlay hints at the call
|
||||||
/// site.
|
/// site.
|
||||||
inlayHints_parameterHints_enable: bool = "true",
|
inlayHints_parameterHints_enable: bool = "true",
|
||||||
/// Whether to show inlay type hints for compiler inserted reborrows.
|
/// Whether to show inlay hints for compiler inserted reborrows.
|
||||||
|
/// This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjustmentHints.enable#.
|
||||||
inlayHints_reborrowHints_enable: ReborrowHintsDef = "\"never\"",
|
inlayHints_reborrowHints_enable: ReborrowHintsDef = "\"never\"",
|
||||||
/// Whether to render leading colons for type hints, and trailing colons for parameter hints.
|
/// Whether to render leading colons for type hints, and trailing colons for parameter hints.
|
||||||
inlayHints_renderColons: bool = "true",
|
inlayHints_renderColons: bool = "true",
|
||||||
|
@ -1201,10 +1204,15 @@ impl Config {
|
||||||
hide_closure_initialization_hints: self
|
hide_closure_initialization_hints: self
|
||||||
.data
|
.data
|
||||||
.inlayHints_typeHints_hideClosureInitialization,
|
.inlayHints_typeHints_hideClosureInitialization,
|
||||||
adjustment_hints: match self.data.inlayHints_reborrowHints_enable {
|
adjustment_hints: match self.data.inlayHints_expressionAdjustmentHints_enable {
|
||||||
ReborrowHintsDef::Always => ide::AdjustmentHints::Always,
|
AdjustmentHintsDef::Always => ide::AdjustmentHints::Always,
|
||||||
ReborrowHintsDef::Never => ide::AdjustmentHints::Never,
|
AdjustmentHintsDef::Never => match self.data.inlayHints_reborrowHints_enable {
|
||||||
ReborrowHintsDef::Mutable => ide::AdjustmentHints::MutableOnly,
|
ReborrowHintsDef::Always | ReborrowHintsDef::Mutable => {
|
||||||
|
ide::AdjustmentHints::ReborrowOnly
|
||||||
|
}
|
||||||
|
ReborrowHintsDef::Never => ide::AdjustmentHints::Never,
|
||||||
|
},
|
||||||
|
AdjustmentHintsDef::Reborrow => ide::AdjustmentHints::ReborrowOnly,
|
||||||
},
|
},
|
||||||
binding_mode_hints: self.data.inlayHints_bindingModeHints_enable,
|
binding_mode_hints: self.data.inlayHints_bindingModeHints_enable,
|
||||||
param_names_for_lifetime_elision_hints: self
|
param_names_for_lifetime_elision_hints: self
|
||||||
|
@ -1539,6 +1547,7 @@ mod de_unit_v {
|
||||||
named_unit_variant!(all);
|
named_unit_variant!(all);
|
||||||
named_unit_variant!(skip_trivial);
|
named_unit_variant!(skip_trivial);
|
||||||
named_unit_variant!(mutable);
|
named_unit_variant!(mutable);
|
||||||
|
named_unit_variant!(reborrow);
|
||||||
named_unit_variant!(with_block);
|
named_unit_variant!(with_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1688,6 +1697,17 @@ enum ReborrowHintsDef {
|
||||||
Mutable,
|
Mutable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum AdjustmentHintsDef {
|
||||||
|
#[serde(deserialize_with = "true_or_always")]
|
||||||
|
Always,
|
||||||
|
#[serde(deserialize_with = "false_or_never")]
|
||||||
|
Never,
|
||||||
|
#[serde(deserialize_with = "de_unit_v::reborrow")]
|
||||||
|
Reborrow,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
enum FilesWatcherDef {
|
enum FilesWatcherDef {
|
||||||
|
@ -1997,6 +2017,19 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
|
||||||
"Only show mutable reborrow hints."
|
"Only show mutable reborrow hints."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"AdjustmentHintsDef" => set! {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"always",
|
||||||
|
"never",
|
||||||
|
"reborrow"
|
||||||
|
],
|
||||||
|
"enumDescriptions": [
|
||||||
|
"Always show all adjustment hints.",
|
||||||
|
"Never show adjustment hints.",
|
||||||
|
"Only show auto borrow and dereference adjustment hints."
|
||||||
|
]
|
||||||
|
},
|
||||||
"CargoFeaturesDef" => set! {
|
"CargoFeaturesDef" => set! {
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -450,6 +450,11 @@ to always show them).
|
||||||
--
|
--
|
||||||
Whether to show inlay type hints for return types of closures.
|
Whether to show inlay type hints for return types of closures.
|
||||||
--
|
--
|
||||||
|
[[rust-analyzer.inlayHints.expressionAdjustmentHints.enable]]rust-analyzer.inlayHints.expressionAdjustmentHints.enable (default: `"never"`)::
|
||||||
|
+
|
||||||
|
--
|
||||||
|
Whether to show inlay hints for type adjustments.
|
||||||
|
--
|
||||||
[[rust-analyzer.inlayHints.lifetimeElisionHints.enable]]rust-analyzer.inlayHints.lifetimeElisionHints.enable (default: `"never"`)::
|
[[rust-analyzer.inlayHints.lifetimeElisionHints.enable]]rust-analyzer.inlayHints.lifetimeElisionHints.enable (default: `"never"`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
|
@ -474,7 +479,8 @@ site.
|
||||||
[[rust-analyzer.inlayHints.reborrowHints.enable]]rust-analyzer.inlayHints.reborrowHints.enable (default: `"never"`)::
|
[[rust-analyzer.inlayHints.reborrowHints.enable]]rust-analyzer.inlayHints.reborrowHints.enable (default: `"never"`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
Whether to show inlay type hints for compiler inserted reborrows.
|
Whether to show inlay hints for compiler inserted reborrows.
|
||||||
|
This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjustmentHints.enable#.
|
||||||
--
|
--
|
||||||
[[rust-analyzer.inlayHints.renderColons]]rust-analyzer.inlayHints.renderColons (default: `true`)::
|
[[rust-analyzer.inlayHints.renderColons]]rust-analyzer.inlayHints.renderColons (default: `true`)::
|
||||||
+
|
+
|
||||||
|
|
|
@ -935,6 +935,21 @@
|
||||||
"Only show type hints for return types of closures with blocks."
|
"Only show type hints for return types of closures with blocks."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.inlayHints.expressionAdjustmentHints.enable": {
|
||||||
|
"markdownDescription": "Whether to show inlay hints for type adjustments.",
|
||||||
|
"default": "never",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"always",
|
||||||
|
"never",
|
||||||
|
"reborrow"
|
||||||
|
],
|
||||||
|
"enumDescriptions": [
|
||||||
|
"Always show all adjustment hints.",
|
||||||
|
"Never show adjustment hints.",
|
||||||
|
"Only show auto borrow and dereference adjustment hints."
|
||||||
|
]
|
||||||
|
},
|
||||||
"rust-analyzer.inlayHints.lifetimeElisionHints.enable": {
|
"rust-analyzer.inlayHints.lifetimeElisionHints.enable": {
|
||||||
"markdownDescription": "Whether to show inlay type hints for elided lifetimes in function signatures.",
|
"markdownDescription": "Whether to show inlay type hints for elided lifetimes in function signatures.",
|
||||||
"default": "never",
|
"default": "never",
|
||||||
|
@ -970,7 +985,7 @@
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"rust-analyzer.inlayHints.reborrowHints.enable": {
|
"rust-analyzer.inlayHints.reborrowHints.enable": {
|
||||||
"markdownDescription": "Whether to show inlay type hints for compiler inserted reborrows.",
|
"markdownDescription": "Whether to show inlay hints for compiler inserted reborrows.\nThis setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjustmentHints.enable#.",
|
||||||
"default": "never",
|
"default": "never",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
|
Loading…
Reference in a new issue