Skip to content

Commit bd294be

Browse files
committed
comment
1 parent 3830a49 commit bd294be

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "llvm/ADT/StringRef.h"
3737
#include "llvm/ADT/Twine.h"
3838
#include "llvm/Support/Casting.h"
39+
#include "llvm/Support/ErrorHandling.h"
3940
#include "llvm/Support/FormatVariadic.h"
4041
#include "llvm/Support/SaveAndRestore.h"
4142
#include "llvm/Support/ScopedPrinter.h"
@@ -383,30 +384,34 @@ maybeDropCxxExplicitObjectParameters(ArrayRef<const ParmVarDecl *> Params) {
383384
}
384385

385386
llvm::StringRef getLambdaCaptureName(const LambdaCapture &Capture) {
386-
if (Capture.capturesVariable())
387-
return Capture.getCapturedVar()->getName();
388-
if (Capture.capturesThis())
387+
switch (Capture.getCaptureKind()) {
388+
case LCK_This:
389+
case LCK_StarThis:
389390
return llvm::StringRef{"this"};
390-
return llvm::StringRef{"unknown"};
391+
case LCK_ByCopy:
392+
case LCK_ByRef:
393+
case LCK_VLAType:
394+
return Capture.getCapturedVar()->getName();
395+
}
396+
llvm_unreachable("unhandled capture kind");
391397
}
392398

393399
template <typename R, typename P>
394400
std::string joinAndTruncate(R &&Range, size_t MaxLength,
395401
P &&GetAsStringFunction) {
396402
std::string Out;
397-
bool IsFirst = true;
403+
llvm::raw_string_ostream OS(Out);
404+
llvm::ListSeparator Sep(", ");
398405
for (auto &&Element : Range) {
399-
if (!IsFirst)
400-
Out.append(", ");
401-
else
402-
IsFirst = false;
406+
OS << Sep;
403407
auto AsString = GetAsStringFunction(Element);
404408
if (Out.size() + AsString.size() >= MaxLength) {
405-
Out.append("...");
409+
OS << "...";
406410
break;
407411
}
408-
Out.append(AsString);
412+
OS << AsString;
409413
}
414+
OS.flush();
410415
return Out;
411416
}
412417

@@ -812,8 +817,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
812817
if (Cfg.InlayHints.DefaultArguments && IsDefault) {
813818
auto SourceText = Lexer::getSourceText(
814819
CharSourceRange::getTokenRange(Params[I]->getDefaultArgRange()),
815-
Callee.Decl->getASTContext().getSourceManager(),
816-
Callee.Decl->getASTContext().getLangOpts());
820+
AST.getSourceManager(), AST.getLangOpts());
817821
FormattedDefaultArgs.emplace_back(llvm::formatv(
818822
"{0} = {1}", Name,
819823
SourceText.size() > Cfg.InlayHints.TypeNameLimit ? "..."

0 commit comments

Comments
 (0)