mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
feat: add inlay hints for generic parameters
fixes #11091 By default, only hints for const generic parameters are shown.
This commit is contained in:
parent
a5b21ea0aa
commit
35b4957b80
10 changed files with 443 additions and 14 deletions
|
@ -1008,6 +1008,11 @@ impl flags::AnalysisStats {
|
|||
type_hints: true,
|
||||
discriminant_hints: ide::DiscriminantHints::Always,
|
||||
parameter_hints: true,
|
||||
generic_parameter_hints: ide::GenericParameterHints {
|
||||
type_hints: true,
|
||||
lifetime_hints: true,
|
||||
const_hints: true,
|
||||
},
|
||||
chaining_hints: true,
|
||||
adjustment_hints: ide::AdjustmentHints::Always,
|
||||
adjustment_hints_mode: ide::AdjustmentHintsMode::Postfix,
|
||||
|
|
|
@ -10,9 +10,9 @@ use dirs::config_dir;
|
|||
use flycheck::{CargoOptions, FlycheckConfig};
|
||||
use ide::{
|
||||
AssistConfig, CallableSnippets, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode,
|
||||
HighlightConfig, HighlightRelatedConfig, HoverConfig, HoverDocFormat, InlayFieldsToResolve,
|
||||
InlayHintsConfig, JoinLinesConfig, MemoryLayoutHoverConfig, MemoryLayoutHoverRenderKind,
|
||||
Snippet, SnippetScope, SourceRootId,
|
||||
GenericParameterHints, HighlightConfig, HighlightRelatedConfig, HoverConfig, HoverDocFormat,
|
||||
InlayFieldsToResolve, InlayHintsConfig, JoinLinesConfig, MemoryLayoutHoverConfig,
|
||||
MemoryLayoutHoverRenderKind, Snippet, SnippetScope, SourceRootId,
|
||||
};
|
||||
use ide_db::{
|
||||
imports::insert_use::{ImportGranularity, InsertUseConfig, PrefixKind},
|
||||
|
@ -509,6 +509,12 @@ config_data! {
|
|||
inlayHints_expressionAdjustmentHints_hideOutsideUnsafe: bool = false,
|
||||
/// Whether to show inlay hints as postfix ops (`.*` instead of `*`, etc).
|
||||
inlayHints_expressionAdjustmentHints_mode: AdjustmentHintsModeDef = AdjustmentHintsModeDef::Prefix,
|
||||
/// Whether to show const generic parameter name inlay hints.
|
||||
inlayHints_genericParameterHints_const_enable: bool= false,
|
||||
/// Whether to show generic lifetime parameter name inlay hints.
|
||||
inlayHints_genericParameterHints_lifetime_enable: bool = true,
|
||||
/// Whether to show generic type parameter name inlay hints.
|
||||
inlayHints_genericParameterHints_type_enable: bool = false,
|
||||
/// Whether to show implicit drop hints.
|
||||
inlayHints_implicitDrops_enable: bool = false,
|
||||
/// Whether to show inlay type hints for elided lifetimes in function signatures.
|
||||
|
@ -1391,6 +1397,11 @@ impl Config {
|
|||
render_colons: self.inlayHints_renderColons().to_owned(),
|
||||
type_hints: self.inlayHints_typeHints_enable().to_owned(),
|
||||
parameter_hints: self.inlayHints_parameterHints_enable().to_owned(),
|
||||
generic_parameter_hints: GenericParameterHints {
|
||||
type_hints: self.inlayHints_genericParameterHints_type_enable().to_owned(),
|
||||
lifetime_hints: self.inlayHints_genericParameterHints_lifetime_enable().to_owned(),
|
||||
const_hints: self.inlayHints_genericParameterHints_const_enable().to_owned(),
|
||||
},
|
||||
chaining_hints: self.inlayHints_chainingHints_enable().to_owned(),
|
||||
discriminant_hints: match self.inlayHints_discriminantHints_enable() {
|
||||
DiscriminantHintsDef::Always => ide::DiscriminantHints::Always,
|
||||
|
@ -2874,6 +2885,19 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
|
|||
"Only show discriminant hints on fieldless enum variants."
|
||||
]
|
||||
},
|
||||
"GenericParameterHintsDef" => set! {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"always",
|
||||
"never",
|
||||
"const_only"
|
||||
],
|
||||
"enumDescriptions": [
|
||||
"Always show generic parameter hints.",
|
||||
"Never show generic parameter hints.",
|
||||
"Only show const generic parameter hints."
|
||||
]
|
||||
},
|
||||
"AdjustmentHintsModeDef" => set! {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
|
|
@ -501,7 +501,9 @@ pub(crate) fn inlay_hint(
|
|||
padding_left: Some(inlay_hint.pad_left),
|
||||
padding_right: Some(inlay_hint.pad_right),
|
||||
kind: match inlay_hint.kind {
|
||||
InlayKind::Parameter => Some(lsp_types::InlayHintKind::PARAMETER),
|
||||
InlayKind::Parameter | InlayKind::GenericParameter => {
|
||||
Some(lsp_types::InlayHintKind::PARAMETER)
|
||||
}
|
||||
InlayKind::Type | InlayKind::Chaining => Some(lsp_types::InlayHintKind::TYPE),
|
||||
_ => None,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue