@@ -112,7 +112,9 @@ std::string summarizeExpr(const Expr *E) {
112
112
return getSimpleName (*E->getFoundDecl ()).str ();
113
113
}
114
114
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;
116
118
}
117
119
std::string
118
120
VisitCXXDependentScopeMemberExpr (const CXXDependentScopeMemberExpr *E) {
@@ -147,6 +149,9 @@ std::string summarizeExpr(const Expr *E) {
147
149
}
148
150
149
151
// Literals are just printed
152
+ std::string VisitCXXNullPtrLiteralExpr (const CXXNullPtrLiteralExpr *E) {
153
+ return " nullptr" ;
154
+ }
150
155
std::string VisitCXXBoolLiteralExpr (const CXXBoolLiteralExpr *E) {
151
156
return E->getValue () ? " true" : " false" ;
152
157
}
@@ -165,12 +170,14 @@ std::string summarizeExpr(const Expr *E) {
165
170
std::string Result = " \" " ;
166
171
if (E->containsNonAscii ()) {
167
172
Result += " ..." ;
168
- } else if (E->getLength () > 10 ) {
169
- Result += E->getString ().take_front (7 );
170
- Result += " ..." ;
171
173
} else {
172
174
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
+ }
174
181
}
175
182
Result.push_back (' "' );
176
183
return Result;
@@ -408,12 +415,14 @@ struct Callee {
408
415
class InlayHintVisitor : public RecursiveASTVisitor <InlayHintVisitor> {
409
416
public:
410
417
InlayHintVisitor (std::vector<InlayHint> &Results, ParsedAST &AST,
411
- const Config &Cfg, std::optional<Range> RestrictRange)
418
+ const Config &Cfg, std::optional<Range> RestrictRange,
419
+ InlayHintOptions HintOptions)
412
420
: Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()),
413
421
Cfg (Cfg), RestrictRange(std::move(RestrictRange)),
414
422
MainFileID(AST.getSourceManager().getMainFileID()),
415
423
Resolver(AST.getHeuristicResolver()),
416
- TypeHintPolicy(this ->AST.getPrintingPolicy()) {
424
+ TypeHintPolicy(this ->AST.getPrintingPolicy()),
425
+ HintOptions(HintOptions) {
417
426
bool Invalid = false ;
418
427
llvm::StringRef Buf =
419
428
AST.getSourceManager ().getBufferData (MainFileID, &Invalid);
@@ -1120,7 +1129,6 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
1120
1129
// Otherwise, the hint shouldn't be shown.
1121
1130
std::optional<Range> computeBlockEndHintRange (SourceRange BraceRange,
1122
1131
StringRef OptionalPunctuation) {
1123
- constexpr unsigned HintMinLineLimit = 2 ;
1124
1132
1125
1133
auto &SM = AST.getSourceManager ();
1126
1134
auto [BlockBeginFileId, BlockBeginOffset] =
@@ -1148,7 +1156,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
1148
1156
auto RBraceLine = SM.getLineNumber (RBraceFileId, RBraceOffset);
1149
1157
1150
1158
// Don't show hint on trivial blocks like `class X {};`
1151
- if (BlockBeginLine + HintMinLineLimit - 1 > RBraceLine)
1159
+ if (BlockBeginLine + HintOptions. HintMinLineLimit - 1 > RBraceLine)
1152
1160
return std::nullopt;
1153
1161
1154
1162
// This is what we attach the hint to, usually "}" or "};".
@@ -1178,17 +1186,20 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
1178
1186
StringRef MainFileBuf;
1179
1187
const HeuristicResolver *Resolver;
1180
1188
PrintingPolicy TypeHintPolicy;
1189
+ InlayHintOptions HintOptions;
1181
1190
};
1182
1191
1183
1192
} // namespace
1184
1193
1185
1194
std::vector<InlayHint> inlayHints (ParsedAST &AST,
1186
- std::optional<Range> RestrictRange) {
1195
+ std::optional<Range> RestrictRange,
1196
+ InlayHintOptions HintOptions) {
1187
1197
std::vector<InlayHint> Results;
1188
1198
const auto &Cfg = Config::current ();
1189
1199
if (!Cfg.InlayHints .Enabled )
1190
1200
return Results;
1191
- InlayHintVisitor Visitor (Results, AST, Cfg, std::move (RestrictRange));
1201
+ InlayHintVisitor Visitor (Results, AST, Cfg, std::move (RestrictRange),
1202
+ HintOptions);
1192
1203
Visitor.TraverseAST (AST.getASTContext ());
1193
1204
1194
1205
// De-duplicate hints. Duplicates can sometimes occur due to e.g. explicit
0 commit comments