[clangd] Omit type hints that are too long

Differential Revision: https://reviews.llvm.org/D108972
This commit is contained in:
Nathan Ridge 2021-08-31 03:42:16 -04:00
parent c3aecf87d5
commit c2810f2c16
2 changed files with 16 additions and 2 deletions

View File

@ -331,8 +331,9 @@ private:
if (!T.getTypePtrOrNull())
return;
addInlayHint(R, InlayHintKind::TypeHint,
std::string(Prefix) + T.getAsString(TypeHintPolicy));
std::string TypeName = T.getAsString(TypeHintPolicy);
if (TypeName.length() < TypeNameLimit)
addInlayHint(R, InlayHintKind::TypeHint, std::string(Prefix) + TypeName);
}
std::vector<InlayHint> &Results;
@ -341,6 +342,8 @@ private:
StringRef MainFileBuf;
const HeuristicResolver *Resolver;
PrintingPolicy TypeHintPolicy;
static const size_t TypeNameLimit = 32;
};
std::vector<InlayHint> inlayHints(ParsedAST &AST) {

View File

@ -591,6 +591,17 @@ TEST(TypeHints, DependentType) {
)cpp");
}
TEST(TypeHints, LongTypeName) {
assertTypeHints(R"cpp(
template <typename, typename, typename>
struct A {};
struct MultipleWords {};
A<MultipleWords, MultipleWords, MultipleWords> foo();
// Omit type hint past a certain length (currently 32)
auto var = foo();
)cpp");
}
// FIXME: Low-hanging fruit where we could omit a type hint:
// - auto x = TypeName(...);
// - auto x = (TypeName) (...);