fix: Allow configuration of colons in inlay-hints
This commit is contained in:
@@ -242,6 +242,8 @@ config_data! {
|
||||
/// `#rust-analyzer.hoverActions.enable#` is set.
|
||||
hoverActions_run: bool = "true",
|
||||
|
||||
/// Whether to render trailing colons for parameter hints, and trailing colons for parameter hints.
|
||||
inlayHints_renderColons: bool = "true",
|
||||
/// Whether to show inlay type hints for method chains.
|
||||
inlayHints_chainingHints: bool = "true",
|
||||
/// Maximum length for inlay hints. Set to null to have an unlimited length.
|
||||
@@ -846,6 +848,7 @@ impl Config {
|
||||
}
|
||||
pub fn inlay_hints(&self) -> InlayHintsConfig {
|
||||
InlayHintsConfig {
|
||||
render_colons: self.data.inlayHints_renderColons,
|
||||
type_hints: self.data.inlayHints_typeHints,
|
||||
parameter_hints: self.data.inlayHints_parameterHints,
|
||||
chaining_hints: self.data.inlayHints_chainingHints,
|
||||
|
||||
@@ -1331,11 +1331,12 @@ pub(crate) fn handle_inlay_hints(
|
||||
)
|
||||
})
|
||||
.transpose()?;
|
||||
let inlay_hints_config = snap.config.inlay_hints();
|
||||
Ok(snap
|
||||
.analysis
|
||||
.inlay_hints(&snap.config.inlay_hints(), file_id, range)?
|
||||
.inlay_hints(&inlay_hints_config, file_id, range)?
|
||||
.into_iter()
|
||||
.map(|it| to_proto::inlay_hint(&line_index, it))
|
||||
.map(|it| to_proto::inlay_hint(inlay_hints_config.render_colons, &line_index, it))
|
||||
.collect())
|
||||
}
|
||||
|
||||
|
||||
@@ -413,12 +413,16 @@ pub(crate) fn signature_help(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ext::InlayHint {
|
||||
pub(crate) fn inlay_hint(
|
||||
render_colons: bool,
|
||||
line_index: &LineIndex,
|
||||
inlay_hint: InlayHint,
|
||||
) -> lsp_ext::InlayHint {
|
||||
lsp_ext::InlayHint {
|
||||
label: match inlay_hint.kind {
|
||||
InlayKind::ParameterHint => format!("{}:", inlay_hint.label),
|
||||
InlayKind::TypeHint => format!(": {}", inlay_hint.label),
|
||||
InlayKind::ChainingHint => inlay_hint.label.to_string(),
|
||||
InlayKind::ParameterHint if render_colons => format!("{}:", inlay_hint.label),
|
||||
InlayKind::TypeHint if render_colons => format!(": {}", inlay_hint.label),
|
||||
_ => inlay_hint.label.to_string(),
|
||||
},
|
||||
position: match inlay_hint.kind {
|
||||
InlayKind::ParameterHint => position(line_index, inlay_hint.range.start()),
|
||||
@@ -433,14 +437,12 @@ pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_e
|
||||
},
|
||||
tooltip: None,
|
||||
padding_left: Some(match inlay_hint.kind {
|
||||
InlayKind::TypeHint => false,
|
||||
InlayKind::ParameterHint => false,
|
||||
InlayKind::TypeHint | InlayKind::ParameterHint => false,
|
||||
InlayKind::ChainingHint => true,
|
||||
}),
|
||||
padding_right: Some(match inlay_hint.kind {
|
||||
InlayKind::TypeHint => false,
|
||||
InlayKind::TypeHint | InlayKind::ChainingHint => false,
|
||||
InlayKind::ParameterHint => true,
|
||||
InlayKind::ChainingHint => false,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user