Skip to content

Commit 64410e0

Browse files
daiyousei-qzMythreyaK
authored andcommitted
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 5e834b9 commit 64410e0

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
@@ -112,7 +112,9 @@ std::string summarizeExpr(const Expr *E) {
112112
return getSimpleName(*E->getFoundDecl()).str();
113113
}
114114
std::string VisitCallExpr(const CallExpr *E) {
115-
return Visit(E->getCallee());
115+
std::string Result = Visit(E->getCallee());
116+
Result += E->getNumArgs() == 0 ? "()" : "(...)";
117+
return Result;
116118
}
117119
std::string
118120
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -147,6 +149,9 @@ std::string summarizeExpr(const Expr *E) {
147149
}
148150

149151
// Literals are just printed
152+
std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
153+
return "nullptr";
154+
}
150155
std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
151156
return E->getValue() ? "true" : "false";
152157
}
@@ -165,12 +170,14 @@ std::string summarizeExpr(const Expr *E) {
165170
std::string Result = "\"";
166171
if (E->containsNonAscii()) {
167172
Result += "...";
168-
} else if (E->getLength() > 10) {
169-
Result += E->getString().take_front(7);
170-
Result += "...";
171173
} else {
172174
llvm::raw_string_ostream OS(Result);
173-
llvm::printEscapedString(E->getString(), OS);
175+
if (E->getLength() > 10) {
176+
llvm::printEscapedString(E->getString().take_front(7), OS);
177+
Result += "...";
178+
} else {
179+
llvm::printEscapedString(E->getString(), OS);
180+
}
174181
}
175182
Result.push_back('"');
176183
return Result;
@@ -1120,7 +1127,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
11201127
// Otherwise, the hint shouldn't be shown.
11211128
std::optional<Range> computeBlockEndHintRange(SourceRange BraceRange,
11221129
StringRef OptionalPunctuation) {
1123-
constexpr unsigned HintMinLineLimit = 2;
1130+
constexpr unsigned HintMinLineLimit = 10;
11241131

11251132
auto &SM = AST.getSourceManager();
11261133
auto [BlockBeginFileId, BlockBeginOffset] =

0 commit comments

Comments
 (0)