[clang-tools-extra] [clangd] Improve BlockEnd inlay hints presentation (PR #72345)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 14 20:48:17 PST 2023
https://github.com/daiyousei-qz created https://github.com/llvm/llvm-project/pull/72345
Including:
1. Explicitly state a function call
2. Print literal nullptr
3. Escape for abbreviated string
4. Adjust min line limit to 10
Fixes issue [clangd/clangd#1807](https://github.com/clangd/clangd/issues/1807)
>From 1a196e908998e9ba1edf9a9c0a48877138b1a223 Mon Sep 17 00:00:00 2001
From: daiyousei-qz <qyzheng2 at outlook.com>
Date: Tue, 14 Nov 2023 20:42:10 -0800
Subject: [PATCH] Improve BlockEnd presentation including: 1. Explicitly state
a function call 2. Print literal nullptr 3. Escape for abbreviated string 4.
Adjust min line limit to 10
---
clang-tools-extra/clangd/InlayHints.cpp | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index 3da047f95421385..97b467fbb519dbd 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -266,7 +266,9 @@ std::string summarizeExpr(const Expr *E) {
return getSimpleName(*E->getFoundDecl()).str();
}
std::string VisitCallExpr(const CallExpr *E) {
- return Visit(E->getCallee());
+ std::string Result = Visit(E->getCallee());
+ Result += E->getNumArgs() == 0 ? "()" : "(...)";
+ return Result;
}
std::string
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -301,6 +303,9 @@ std::string summarizeExpr(const Expr *E) {
}
// Literals are just printed
+ std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+ return "nullptr";
+ }
std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
return E->getValue() ? "true" : "false";
}
@@ -319,12 +324,14 @@ std::string summarizeExpr(const Expr *E) {
std::string Result = "\"";
if (E->containsNonAscii()) {
Result += "...";
- } else if (E->getLength() > 10) {
- Result += E->getString().take_front(7);
- Result += "...";
} else {
llvm::raw_string_ostream OS(Result);
- llvm::printEscapedString(E->getString(), OS);
+ if (E->getLength() > 10) {
+ llvm::printEscapedString(E->getString().take_front(7), OS);
+ Result += "...";
+ } else {
+ llvm::printEscapedString(E->getString(), OS);
+ }
}
Result.push_back('"');
return Result;
@@ -1193,7 +1200,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
// Otherwise, the hint shouldn't be shown.
std::optional<Range> computeBlockEndHintRange(SourceRange BraceRange,
StringRef OptionalPunctuation) {
- constexpr unsigned HintMinLineLimit = 2;
+ constexpr unsigned HintMinLineLimit = 10;
auto &SM = AST.getSourceManager();
auto [BlockBeginFileId, BlockBeginOffset] =
More information about the cfe-commits
mailing list