Skip to content

Commit 2019e93

Browse files
committed
hover: the prose prints its types the way the card does
`kind_words` wrote `fact.type_of` and `fact.returns` as the file spelled them, so a popup said `std::vector<std::string> &` in the sentence and `std::vector<std::string>&` in the card above it — two spellings of one type in one place. Both now go through `render::a_type`, the renderer every other type in the card already used. Measured on `std::vector<std::string>& names();` with `inspect hover`: before `names` — a function returning `std::vector<std::string> &` after `names` — a function returning `std::vector<std::string>&` `docs/hover-render.md` §3 and `docs/next.md` §6 mark the item done; the rest of §6 is untouched and still listed there: `std::less<>`, a template-id callee, `the_type_the_macros_leave`, the declarator's own `const`, operator hovers, a constructor's name resolving to its type, and base access.
1 parent 114b8c7 commit 2019e93

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎crates/cpp_ls/src/handlers/hover/mod.rs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,9 +1755,23 @@ fn kind_words(fact: &DeclFact) -> String {
17551755
words.push_str(&format!(" template over `{}`", named.join("`, `")));
17561756
}
17571757

1758+
// **The prose's types go through the same renderer as the card's** — `docs/hover-render.md`'s contract, and the
1759+
// reason it is not a style choice: a fact records the spelling the *file* wrote (`std::vector<std::string> &`, with
1760+
// the space the declarator needed), and the prose printed it as-is while the card below it printed
1761+
// `std::vector<std::string>&`. Two spellings of one type in one popup is a reader asking which is the type.
1762+
//
1763+
// `a_type` parses the spelling and prints it from the model, so the qualifiers, the references and the arguments
1764+
// come out the way every other type in the card does. `const char * const` → `const char*` is the same normalization
1765+
// the card has had since the renderer landed.
17581766
match (&fact.type_of, &fact.returns) {
1759-
(Some(written), _) => words.push_str(&format!(" of type `{written}`")),
1760-
(None, Some(written)) => words.push_str(&format!(" returning `{written}`")),
1767+
(Some(written), _) => words.push_str(&format!(
1768+
" of type `{}`",
1769+
cpp_code_analysis::sema::render::a_type(written)
1770+
)),
1771+
(None, Some(written)) => words.push_str(&format!(
1772+
" returning `{}`",
1773+
cpp_code_analysis::sema::render::a_type(written)
1774+
)),
17611775
(None, None) => {}
17621776
}
17631777

‎docs/hover-render.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ query reads the reading that produced the fact it started from.
7171
means. `Type::Named` needs to keep "had an empty list" (or the name keeps `<>`).
7272
* **A hover on a template-id callee answers nothing.** `std::make_shared<Resource>(2)` — the callee is a template-id, not
7373
a plain name, and the name lookup at that offset finds neither. (Measured on `test_cpp/src/smart_pointers.cpp:50`.)
74-
* **The prose around the card still prints raw fact strings** — ``returning `std::vector<std::string> &` `` in
75-
`kind_words`. Route those through `render::a_type` too.
74+
* **~~The prose around the card still prints raw fact strings~~ — done.** `kind_words` routes `type_of` and `returns`
75+
through `render::a_type`, so the sentence and the card below it print one type. Measured on
76+
`std::vector<std::string>& names();`: the card said `std::vector<std::string>&` while the prose said
77+
``returning `std::vector<std::string> &` ``; now both say the former. (`tests/hover-latency`-style measurement:
78+
`inspect hover`, before and after.)
7679
* **`the_type_the_macros_leave` is a fact-level repair still in hover.** It rebuilds a return type that a macro's name
7780
swallowed (`WINBASEAPI WINBOOL WINAPI SetConsoleOutputCP`). It should live where facts are built; hover should not
7881
own a text repair at all.

‎docs/next.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ From `docs/hover-render.md` §3, in the order they are likely to be met:
155155

156156
* **`std::less<>` renders `std::less`** — `parse_type_spelling` drops an empty argument list, which changes the name.
157157
* **A template-id callee answers nothing** (`std::make_shared<Resource>(2)`): the callee is not a plain name.
158-
* **The prose still prints raw fact strings** (`returning \`std::vector<std::string> &\``) — route `kind_words` through
159-
`render::a_type`.
158+
* ~~**The prose still prints raw fact strings**~~ — **done**: `kind_words` goes through `render::a_type`, measured on
159+
`std::vector<std::string>& names();` (the card and the prose now agree). The rest of this list is untouched.
160160
* **`the_type_the_macros_leave`** is a fact-level repair living in hover; move it to the fact builder.
161161
* **Operator hovers hit the keyword vocabulary** (`operator bool`): the card should be the declaration.
162162
* **Base access is not printed** (`: Base` where the clause says `public`).

0 commit comments

Comments
 (0)