mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
fix: Allow configuration of colons in inlay-hints
This commit is contained in:
parent
224a255c5a
commit
62265ee9cb
8 changed files with 40 additions and 10 deletions
|
@ -12,6 +12,7 @@ use crate::FileId;
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct InlayHintsConfig {
|
||||
pub render_colons: bool,
|
||||
pub type_hints: bool,
|
||||
pub parameter_hints: bool,
|
||||
pub chaining_hints: bool,
|
||||
|
@ -574,6 +575,7 @@ mod tests {
|
|||
use crate::{fixture, inlay_hints::InlayHintsConfig};
|
||||
|
||||
const TEST_CONFIG: InlayHintsConfig = InlayHintsConfig {
|
||||
render_colons: true,
|
||||
type_hints: true,
|
||||
parameter_hints: true,
|
||||
chaining_hints: true,
|
||||
|
@ -590,6 +592,7 @@ mod tests {
|
|||
fn check_params(ra_fixture: &str) {
|
||||
check_with_config(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: true,
|
||||
type_hints: false,
|
||||
chaining_hints: false,
|
||||
|
@ -604,6 +607,7 @@ mod tests {
|
|||
fn check_types(ra_fixture: &str) {
|
||||
check_with_config(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: false,
|
||||
type_hints: true,
|
||||
chaining_hints: false,
|
||||
|
@ -618,6 +622,7 @@ mod tests {
|
|||
fn check_chains(ra_fixture: &str) {
|
||||
check_with_config(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: false,
|
||||
type_hints: false,
|
||||
chaining_hints: true,
|
||||
|
@ -649,6 +654,7 @@ mod tests {
|
|||
fn hints_disabled() {
|
||||
check_with_config(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
type_hints: false,
|
||||
parameter_hints: false,
|
||||
chaining_hints: false,
|
||||
|
@ -1104,6 +1110,7 @@ fn main() {
|
|||
let inlay_hints = analysis
|
||||
.inlay_hints(
|
||||
&InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: false,
|
||||
type_hints: true,
|
||||
chaining_hints: false,
|
||||
|
@ -1413,6 +1420,7 @@ fn main() {
|
|||
fn skip_constructor_and_enum_type_hints() {
|
||||
check_with_config(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
type_hints: true,
|
||||
parameter_hints: true,
|
||||
chaining_hints: true,
|
||||
|
@ -1590,6 +1598,7 @@ fn main() {
|
|||
fn chaining_hints_ignore_comments() {
|
||||
check_expect(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: false,
|
||||
type_hints: false,
|
||||
chaining_hints: true,
|
||||
|
@ -1647,6 +1656,7 @@ fn main() {
|
|||
fn struct_access_chaining_hints() {
|
||||
check_expect(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: false,
|
||||
type_hints: false,
|
||||
chaining_hints: true,
|
||||
|
@ -1692,6 +1702,7 @@ fn main() {
|
|||
fn generic_chaining_hints() {
|
||||
check_expect(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: false,
|
||||
type_hints: false,
|
||||
chaining_hints: true,
|
||||
|
@ -1738,6 +1749,7 @@ fn main() {
|
|||
fn shorten_iterator_chaining_hints() {
|
||||
check_expect(
|
||||
InlayHintsConfig {
|
||||
render_colons: true,
|
||||
parameter_hints: false,
|
||||
type_hints: false,
|
||||
chaining_hints: true,
|
||||
|
|
|
@ -105,6 +105,7 @@ impl StaticIndex<'_> {
|
|||
.analysis
|
||||
.inlay_hints(
|
||||
&InlayHintsConfig {
|
||||
render_colons: true,
|
||||
type_hints: true,
|
||||
parameter_hints: true,
|
||||
chaining_hints: true,
|
||||
|
|
|
@ -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,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -440,6 +440,7 @@ pub fn bench(label: &'static str) -> impl Drop {
|
|||
|
||||
/// Checks that the `file` has the specified `contents`. If that is not the
|
||||
/// case, updates the file and then fails the test.
|
||||
#[track_caller]
|
||||
pub fn ensure_file_contents(file: &Path, contents: &str) {
|
||||
if let Err(()) = try_ensure_file_contents(file, contents) {
|
||||
panic!("Some files were not up-to-date");
|
||||
|
|
|
@ -347,6 +347,11 @@ Whether to show `References` action. Only applies when
|
|||
Whether to show `Run` action. Only applies when
|
||||
`#rust-analyzer.hoverActions.enable#` is set.
|
||||
--
|
||||
[[rust-analyzer.inlayHints.renderColons]]rust-analyzer.inlayHints.renderColons (default: `true`)::
|
||||
+
|
||||
--
|
||||
Whether to render trailing colons for parameter hints, and trailing colons for parameter hints.
|
||||
--
|
||||
[[rust-analyzer.inlayHints.chainingHints]]rust-analyzer.inlayHints.chainingHints (default: `true`)::
|
||||
+
|
||||
--
|
||||
|
|
|
@ -766,6 +766,11 @@
|
|||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rust-analyzer.inlayHints.renderColons": {
|
||||
"markdownDescription": "Whether to render trailing colons for parameter hints, and trailing colons for parameter hints.",
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rust-analyzer.inlayHints.chainingHints": {
|
||||
"markdownDescription": "Whether to show inlay type hints for method chains.",
|
||||
"default": true,
|
||||
|
|
Loading…
Reference in a new issue