clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.49k stars 60 forks source link

Make the type hint length limit configurable #1357

Closed lingege32 closed 1 week ago

lingege32 commented 1 year ago

Please describe the problem. For hints on what information is helpful, see: https://clangd.llvm.org/troubleshooting.html

If you can, provide a minimal chunk of code that shows the problem (either inline, or attach it if larger).

Like the following picture, Inlay hint works correctly for std::map<size_t, int> but wrong in std::map<size_t, double> How can I get the inlay hint for the second type?

image

System information clangd version 15.0.3 (https://github.com/llvm/llvm-project 4a2c05b05ed07f1f620e94f6524a8b4b2760a0b1) Features: linux+grpc Platform: x86_64-unknown-linux-gnu

Editor/LSP plugin: vscode 1.72.2 / clangd v0.1.23

Operating system: $ lsb_release -a

LSB Version: :core-4.1-amd64:core-4.1-ia32:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-ia32:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-ia32:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.3.1611 (Core) Release: 7.3.1611 Codename: Core

HighCommander4 commented 1 year ago

We have a length threshold of 32 characters for type hints, to avoid making lines unreadably long. (There is basically no limit how long C++ typenames can get, especially with metaprogramming.)

pair<const unsigned long, int> happens to be just under the 32-character limit, and pair<const unsigned long, double> is just over.

See https://github.com/clangd/clangd/issues/824 for some previous discussion on this topic.

lingege32 commented 1 year ago

Do we have method to change the length threshold?

HighCommander4 commented 1 year ago

Not currently, but one could be added.

zhangyi1357 commented 1 year ago

I'm interested in this issue, and I've downloaded the source code to read through it. I understand that the type hint limit is controlled by a static member variable named 'TypeNameLimit' with a default value of 32 in the 'InlayHintVisitor' class. However, I'm not sure how to add it to the configuration.

Can someone give me some hints? I would also appreciate any other advice, as this is my first time participating in an open-source community. Thank you!

HighCommander4 commented 1 week ago

This has been fixed since clangd 17.