Skip to content

Commit

Permalink
Do not show caption in label inlay hints
Browse files Browse the repository at this point in the history
See #858.
  • Loading branch information
pfoerster committed Mar 9, 2023
1 parent ccaaec5 commit dd85dce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 19 additions & 2 deletions src/features/inlay_hint/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use rowan::TextRange;

use crate::{
db::{analysis::label, Document},
util, Db,
util::{self, label::LabeledObject},
Db,
};

use super::InlayHintBuilder;
Expand All @@ -23,7 +24,23 @@ pub(super) fn find_hints(
.filter(|label| label.range(db).intersect(range).is_some())
{
if let Some(rendered) = util::label::render(db, document, label) {
builder.push(label.range(db).end(), rendered.reference(db));
if let Some(number) = &rendered.number {
let text = match &rendered.object {
LabeledObject::Section { prefix, .. } => {
format!("{} {}", prefix, number.text(db))
}
LabeledObject::Float { kind, .. } => {
format!("{} {}", kind.as_str(), number.text(db))
}
LabeledObject::Theorem { kind, .. } => {
format!("{} {}", kind.text(db), number.text(db))
}
LabeledObject::Equation => format!("Equation ({})", number.text(db)),
LabeledObject::EnumItem => format!("Item {}", number.text(db)),
};

builder.push(label.range(db).end(), text);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ expression: "find_hints(r#\"\n%! main.tex\n\\documentclass{article}\n\\usepackag
"line": 3,
"character": 27
},
"label": "Section 1 (Foo)",
"label": "Section 1",
"paddingLeft": true
},
{
"position": {
"line": 4,
"character": 27
},
"label": "Section 2 (Bar)",
"label": "Section 2",
"paddingLeft": true
},
{
"position": {
"line": 5,
"character": 30
},
"label": "Subsection 2.1 (Baz)",
"label": "Subsection 2.1",
"paddingLeft": true
},
{
"position": {
"line": 8,
"character": 18
},
"label": "Figure fig:qux: Qux",
"label": "Figure fig:qux",
"paddingLeft": true
}
]

0 comments on commit dd85dce

Please sign in to comment.