[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)
Tor Shepherd via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 14 16:28:22 PDT 2024
torshepherd wrote:
Ok I found a couple of nontrivial issues that I took care of in the latest commit.
1. Using `DefaultArguments` required having parameter names set to true as well. I separated them so that both have a modality that works with or without the other. See screenshot for defaults w/out parameter names:
![image](https://github.com/user-attachments/assets/fb5a9608-33aa-41bb-bf2e-1fc4361ca0da)
2. Having newlines in the default definition caused `LF` to be displayed in the hints. I fixed this by just displaying `...` any time a default definition contains `\n`.
3. I was getting `Property DefaultArguments` is not allowed in `config.yaml`. Is this a schema issue? I wasn't able to find where to update this
Also, a couple of follow-up things I should do:
- Add support for default `Designators`. For instance,
```cpp
struct Foo { int a; int b = 2 };
Foo f{1}; // Currently shows 'Foo f{.a=1}', should show 'Foo f{.a=1, .b=2}'
```
- Add support for template args? such as `std::vector<int, std::allocator<int>>` when user types `std::vector<int>`. This could also fall under "add InlayHints for FTAD and CTAD", which may be a nongoal, idk
- Add a link to the source location of the definition (leveraging https://github.com/llvm/llvm-project/pull/85497)
- Do the formatting better. Basically, in some cases, collapsing newlines preserves the meaning of the code and therefore we should do that. However in other cases (comments for example), collapsing newlines makes the code gibberish (`3 // + 2` from the test case for example), and we should just show `...` instead.
https://github.com/llvm/llvm-project/pull/95712
More information about the cfe-commits
mailing list