Skip to content

Commit 1a196e9

Browse files
committed
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
1 parent 8dfac29 commit 1a196e9

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ std::string summarizeExpr(const Expr *E) {
266266
return getSimpleName(*E->getFoundDecl()).str();
267267
}
268268
std::string VisitCallExpr(const CallExpr *E) {
269-
return Visit(E->getCallee());
269+
std::string Result = Visit(E->getCallee());
270+
Result += E->getNumArgs() == 0 ? "()" : "(...)";
271+
return Result;
270272
}
271273
std::string
272274
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -301,6 +303,9 @@ std::string summarizeExpr(const Expr *E) {
301303
}
302304

303305
// Literals are just printed
306+
std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
307+
return "nullptr";
308+
}
304309
std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
305310
return E->getValue() ? "true" : "false";
306311
}
@@ -319,12 +324,14 @@ std::string summarizeExpr(const Expr *E) {
319324
std::string Result = "\"";
320325
if (E->containsNonAscii()) {
321326
Result += "...";
322-
} else if (E->getLength() > 10) {
323-
Result += E->getString().take_front(7);
324-
Result += "...";
325327
} else {
326328
llvm::raw_string_ostream OS(Result);
327-
llvm::printEscapedString(E->getString(), OS);
329+
if (E->getLength() > 10) {
330+
llvm::printEscapedString(E->getString().take_front(7), OS);
331+
Result += "...";
332+
} else {
333+
llvm::printEscapedString(E->getString(), OS);
334+
}
328335
}
329336
Result.push_back('"');
330337
return Result;
@@ -1193,7 +1200,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
11931200
// Otherwise, the hint shouldn't be shown.
11941201
std::optional<Range> computeBlockEndHintRange(SourceRange BraceRange,
11951202
StringRef OptionalPunctuation) {
1196-
constexpr unsigned HintMinLineLimit = 2;
1203+
constexpr unsigned HintMinLineLimit = 10;
11971204

11981205
auto &SM = AST.getSourceManager();
11991206
auto [BlockBeginFileId, BlockBeginOffset] =

0 commit comments

Comments
 (0)