Skip to content

Commit 4a33c0f

Browse files
committed
fixes
1 parent 99c78ce commit 4a33c0f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -785,19 +785,24 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
785785
}
786786

787787
StringRef Name = ParameterNames[I];
788-
bool NameHint = shouldHintName(Args[I], Name);
789-
bool ReferenceHint = shouldHintReference(Params[I], ForwardedParams[I]);
788+
const bool NameHint = shouldHintName(Args[I], Name);
789+
const bool ReferenceHint =
790+
shouldHintReference(Params[I], ForwardedParams[I]);
790791

791-
bool IsDefault = isa<CXXDefaultArgExpr>(Args[I]);
792+
const bool IsDefault = isa<CXXDefaultArgExpr>(Args[I]);
792793
HasNonDefaultArgs |= !IsDefault;
793794
if (Cfg.InlayHints.DefaultArguments && IsDefault) {
794-
auto SourceText = Lexer::getSourceText(
795+
const auto SourceText = Lexer::getSourceText(
795796
CharSourceRange::getTokenRange(Params[I]->getDefaultArgRange()),
796797
AST.getSourceManager(), AST.getLangOpts());
797-
FormattedDefaultArgs.emplace_back(llvm::formatv(
798-
"{0}: {1}", Name.empty() ? "/*unused*/" : Name,
799-
SourceText.size() > Cfg.InlayHints.TypeNameLimit ? "..."
800-
: SourceText));
798+
const auto Abbrev = SourceText.size() > Cfg.InlayHints.TypeNameLimit
799+
? "..."
800+
: SourceText;
801+
if (NameHint)
802+
FormattedDefaultArgs.emplace_back(
803+
llvm::formatv("{0}: {1}", Name, Abbrev));
804+
else
805+
FormattedDefaultArgs.emplace_back(llvm::formatv("{0}", Abbrev));
801806
}
802807

803808
if (NameHint || ReferenceHint) {

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,11 +1484,14 @@ TEST(DefaultArguments, Smoke) {
14841484
int foo(int A = 4) { return A; }
14851485
int bar(int A, int B = 1, bool C = foo($default1[[)]]) { return A; }
14861486
int A = bar($explicit[[2]]$default2[[)]];
1487+
1488+
void baz(int = 5) { if (false) baz($unnamed[[)]]; };
14871489
)cpp";
14881490

14891491
assertHints(InlayHintKind::DefaultArgument, Code,
14901492
ExpectedHint{"A: 4", "default1", Left},
1491-
ExpectedHint{", B: 1, C: foo()", "default2", Left});
1493+
ExpectedHint{", B: 1, C: foo()", "default2", Left},
1494+
ExpectedHint{"5", "unnamed", Left});
14921495

14931496
assertHints(InlayHintKind::Parameter, Code,
14941497
ExpectedHint{"A: ", "explicit", Left});

0 commit comments

Comments
 (0)