Merge #11684
11684: fix: Allow configuration of colons in inlay-hints r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
71f7e67dcf
@ -12,6 +12,7 @@
|
||||
|
||||
#[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 @@ fn check(ra_fixture: &str) {
|
||||
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 @@ fn check_params(ra_fixture: &str) {
|
||||
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 @@ fn check_types(ra_fixture: &str) {
|
||||
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 @@ fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) {
|
||||
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 generic<T: Clone>(t: T) {
|
||||
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 @@ fn add_file(&mut self, file_id: FileId) {
|
||||
.analysis
|
||||
.inlay_hints(
|
||||
&InlayHintsConfig {
|
||||
render_colons: true,
|
||||
type_hints: true,
|
||||
parameter_hints: true,
|
||||
chaining_hints: true,
|
||||
|
@ -242,6 +242,8 @@ struct ConfigData {
|
||||
/// `#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 @@ pub fn runnables(&self) -> RunnablesConfig {
|
||||
}
|
||||
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())
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ impl InlayHintKind {
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct InlayHint {
|
||||
pub label: String,
|
||||
pub label: InlayHintLabel,
|
||||
pub position: Position,
|
||||
pub kind: Option<InlayHintKind>,
|
||||
pub tooltip: Option<String>,
|
||||
@ -263,6 +263,24 @@ pub struct InlayHint {
|
||||
pub padding_right: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum InlayHintLabel {
|
||||
String(String),
|
||||
Parts(Vec<InlayHintLabelPart>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct InlayHintLabelPart {
|
||||
pub value: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tooltip: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub location: Option<lsp_types::LocationLink>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub command: Option<lsp_types::Command>,
|
||||
}
|
||||
pub enum Ssr {}
|
||||
|
||||
impl Request for Ssr {
|
||||
|
@ -413,13 +413,17 @@ 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(),
|
||||
},
|
||||
label: lsp_ext::InlayHintLabel::String(match inlay_hint.kind {
|
||||
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()),
|
||||
InlayKind::TypeHint | InlayKind::ChainingHint => {
|
||||
@ -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 @@ fn drop(&mut self) {
|
||||
|
||||
/// 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");
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!---
|
||||
lsp_ext.rs hash: e32fdde032ff6ebc
|
||||
lsp_ext.rs hash: 854109e98d02a780
|
||||
|
||||
If you need to change the above hash to make the test pass, please check if you
|
||||
need to adjust this doc as well and ping this issue:
|
||||
|
@ -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 New Issue
Block a user