Repository navigation
Commit 2d7d09a
committed
sema: a qualified *type* is not a qualified declaration, and a hover shows the overloads a call can reach
**The bogus declaration behind the `string`-as-a-method report.** Worked back from the two screenshots: the semantic tokens coloured
`string` in `std::map<std::string, std::string, std::less<>> &keyValues` as a `method`, and its hover read
``std::vector<std:: string()``, declared in `FormatContext.h:58:42` — the `string` token of the return type's template argument.
Both come from one fact, and `inspect facts` named it:
```text
58:42 string function in std returns `void` parameters `()`
58:51 GetIgnorePattern function in FormatContext returns `std::vector<std::string> &`
```
`qualified_declarations` was reading it as an **out-of-class definition**: `void C::f()` writes the name in the *specifier*, so a
declaration whose declarator holds no name takes the last qualified name from the specifiers. It asked
`declarator.child::<CppDeclarator>()` — the **first nested** declarator — and for `&f()` that is the `&` wrapper, which holds no
name; so the specifiers were consulted, `std::string &f();` declared a function called `string` in namespace `std`, and
`std::vector<int> &f();` one called `vector<int>`. The declarator's **own** name is the reader that answers for every spelling
(a direct token for `&f()`, a direct `NameExpr` for `C::f`), and it is what decides now. `inspect facts` on the fixtures shows the
bogus facts gone, `void C::f() {}` still files `f in C`, and the header keeps only its real declarations.
Fix measured back through the tool on the real project: `hover` on that `string` answers "none" rather than the invented function,
and there is no `string` function fact left in the file's summary.
**A hover on a call prints the declarations that call can reach.** Reported from the same session: hovering `append` in
`result_str.append(x)` drew all nine `basic_string::append` declarations. Two cannot accept one argument at all
(`append(const _StringViewIsh&, size_type, size_type = npos)`), so the card was showing declarations the call cannot mean.
The arity rule was there and too permissive: `Candidate::takes` asked only "no more arguments than parameters", on the reasoning
that a longer parameter list may have defaults — true, and it made every two- and three-parameter overload viable for a
one-argument call. The defaulted count is not in the type spellings a candidate holds, but it **is** in the declaration's
`parameter_list` spelling, which the hover has: `overload::defaults_in` counts it, `Candidate::with_required` records the required
count, and `takes` now asks both ends.
With that, the viable set is the answer. New `Session::the_declarations_a_call_means` returns one index when the resolution
decides and the whole viable set when it does not (it shares `the_candidates_of_a_call` with the older single-answer question),
and both hover paths print exactly those:
* **one** → that declaration's own card — for a member, with its details and location, as a member that is not overloaded gets;
for a free function, the single line with `→`;
* **several** → only those, with a sentence that says they fit the call and that the types do not decide between them;
* **not on a call** → the old list, which is the honest answer for a name the cursor is merely on.
Tested: `a_hover_on_a_call_shows_only_the_declarations_it_can_reach` (a chosen one-parameter overload, and both one-parameter
overloads of an unknown argument — with the two-parameter one absent); `overload`'s arity test now pins the required count
(`with_required(0)` reaches a zero-argument call, without it the call reaches nothing); the whole `cpp_ls` suite (including the
member-overload `reported_hover` tests) and `cpp_code_analysis`'s.1 parent f0ceb98 commit 2d7d09a
5 files changed
Lines changed: 360 additions & 70 deletions
File tree
- crates
- cpp_code_analysis/src
- sema
- session
- cpp_ls
- src/handlers/hover
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4239 | 4239 | | |
4240 | 4240 | | |
4241 | 4241 | | |
4242 | | - | |
4243 | | - | |
4244 | | - | |
4245 | | - | |
4246 | | - | |
4247 | | - | |
4248 | | - | |
4249 | | - | |
4250 | | - | |
| 4242 | + | |
| 4243 | + | |
| 4244 | + | |
| 4245 | + | |
| 4246 | + | |
| 4247 | + | |
| 4248 | + | |
| 4249 | + | |
| 4250 | + | |
| 4251 | + | |
| 4252 | + | |
| 4253 | + | |
| 4254 | + | |
| 4255 | + | |
4251 | 4256 | | |
4252 | 4257 | | |
4253 | 4258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| 86 | + | |
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
| |||
88 | 93 | | |
89 | 94 | | |
90 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
91 | 104 | | |
92 | 105 | | |
93 | 106 | | |
| |||
114 | 127 | | |
115 | 128 | | |
116 | 129 | | |
117 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
118 | 134 | | |
119 | 135 | | |
120 | 136 | | |
| |||
133 | 149 | | |
134 | 150 | | |
135 | 151 | | |
136 | | - | |
137 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
138 | 159 | | |
139 | 160 | | |
140 | 161 | | |
| |||
146 | 167 | | |
147 | 168 | | |
148 | 169 | | |
149 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
150 | 175 | | |
151 | 176 | | |
152 | 177 | | |
| |||
379 | 404 | | |
380 | 405 | | |
381 | 406 | | |
382 | | - | |
383 | | - | |
384 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
385 | 416 | | |
386 | 417 | | |
387 | 418 | | |
| |||
502 | 533 | | |
503 | 534 | | |
504 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
505 | 587 | | |
506 | 588 | | |
507 | 589 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8696 | 8696 | | |
8697 | 8697 | | |
8698 | 8698 | | |
8699 | | - | |
| 8699 | + | |
8700 | 8700 | | |
8701 | | - | |
8702 | | - | |
8703 | | - | |
| 8701 | + | |
| 8702 | + | |
8704 | 8703 | | |
8705 | | - | |
8706 | | - | |
| 8704 | + | |
| 8705 | + | |
| 8706 | + | |
| 8707 | + | |
| 8708 | + | |
| 8709 | + | |
| 8710 | + | |
| 8711 | + | |
| 8712 | + | |
| 8713 | + | |
| 8714 | + | |
| 8715 | + | |
| 8716 | + | |
| 8717 | + | |
| 8718 | + | |
| 8719 | + | |
| 8720 | + | |
| 8721 | + | |
| 8722 | + | |
| 8723 | + | |
| 8724 | + | |
| 8725 | + | |
| 8726 | + | |
| 8727 | + | |
| 8728 | + | |
| 8729 | + | |
| 8730 | + | |
| 8731 | + | |
| 8732 | + | |
| 8733 | + | |
8707 | 8734 | | |
8708 | 8735 | | |
8709 | 8736 | | |
8710 | 8737 | | |
8711 | 8738 | | |
8712 | 8739 | | |
8713 | 8740 | | |
| 8741 | + | |
| 8742 | + | |
| 8743 | + | |
| 8744 | + | |
| 8745 | + | |
| 8746 | + | |
| 8747 | + | |
| 8748 | + | |
| 8749 | + | |
| 8750 | + | |
| 8751 | + | |
| 8752 | + | |
| 8753 | + | |
| 8754 | + | |
| 8755 | + | |
| 8756 | + | |
| 8757 | + | |
| 8758 | + | |
| 8759 | + | |
8714 | 8760 | | |
8715 | 8761 | | |
8716 | 8762 | | |
| |||
8783 | 8829 | | |
8784 | 8830 | | |
8785 | 8831 | | |
8786 | | - | |
8787 | | - | |
8788 | | - | |
8789 | | - | |
| 8832 | + | |
8790 | 8833 | | |
| 8834 | + | |
8791 | 8835 | | |
8792 | 8836 | | |
8793 | 8837 | | |
| |||
0 commit comments