1313#include " ParsedAST.h"
1414#include " Selection.h"
1515#include " SourceCode.h"
16+ #include " Trace.h"
1617#include " index/SymbolCollector.h"
1718#include " clang/AST/DeclCXX.h"
1819#include " clang/AST/DeclTemplate.h"
@@ -124,6 +125,7 @@ llvm::Optional<ReasonToReject> renameable(const NamedDecl &RenameDecl,
124125 StringRef MainFilePath,
125126 const SymbolIndex *Index,
126127 bool CrossFile) {
128+ trace::Span Tracer (" Renameable" );
127129 // Filter out symbols that are unsupported in both rename modes.
128130 if (llvm::isa<NamespaceDecl>(&RenameDecl))
129131 return ReasonToReject::UnsupportedSymbol;
@@ -225,6 +227,7 @@ llvm::Error makeError(ReasonToReject Reason) {
225227// Return all rename occurrences in the main file.
226228std::vector<SourceLocation> findOccurrencesWithinFile (ParsedAST &AST,
227229 const NamedDecl &ND) {
230+ trace::Span Tracer (" FindOccurrenceeWithinFile" );
228231 // If the cursor is at the underlying CXXRecordDecl of the
229232 // ClassTemplateDecl, ND will be the CXXRecordDecl. In this case, we need to
230233 // get the primary template maunally.
@@ -260,6 +263,7 @@ std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
260263llvm::Expected<tooling::Replacements>
261264renameWithinFile (ParsedAST &AST, const NamedDecl &RenameDecl,
262265 llvm::StringRef NewName) {
266+ trace::Span Tracer (" RenameWithinFile" );
263267 const SourceManager &SM = AST.getSourceManager ();
264268
265269 tooling::Replacements FilteredChanges;
@@ -319,6 +323,7 @@ std::vector<const CXXConstructorDecl *> getConstructors(const NamedDecl *ND) {
319323llvm::Expected<llvm::StringMap<std::vector<Range>>>
320324findOccurrencesOutsideFile (const NamedDecl &RenameDecl,
321325 llvm::StringRef MainFile, const SymbolIndex &Index) {
326+ trace::Span Tracer (" FindOccurrencesOutsideFile" );
322327 RefsRequest RQuest;
323328 RQuest.IDs .insert (*getSymbolID (&RenameDecl));
324329 // Classes and their constructors are different symbols, and have different
@@ -361,6 +366,9 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
361366 auto &Ranges = FileAndOccurrences.getValue ();
362367 llvm::sort (Ranges);
363368 Ranges.erase (std::unique (Ranges.begin (), Ranges.end ()), Ranges.end ());
369+
370+ SPAN_ATTACH (Tracer, FileAndOccurrences.first (),
371+ static_cast <int64_t >(Ranges.size ()));
364372 }
365373 return AffectedFiles;
366374}
@@ -381,6 +389,7 @@ llvm::Expected<FileEdits> renameOutsideFile(
381389 const NamedDecl &RenameDecl, llvm::StringRef MainFilePath,
382390 llvm::StringRef NewName, const SymbolIndex &Index,
383391 llvm::function_ref<llvm::Expected<std::string>(PathRef)> GetFileContent) {
392+ trace::Span Tracer (" RenameOutsideFile" );
384393 auto AffectedFiles =
385394 findOccurrencesOutsideFile (RenameDecl, MainFilePath, Index);
386395 if (!AffectedFiles)
@@ -463,6 +472,7 @@ void findNearMiss(
463472} // namespace
464473
465474llvm::Expected<FileEdits> rename (const RenameInputs &RInputs) {
475+ trace::Span Tracer (" Rename flow" );
466476 ParsedAST &AST = RInputs.AST ;
467477 const SourceManager &SM = AST.getSourceManager ();
468478 llvm::StringRef MainFileCode = SM.getBufferData (SM.getMainFileID ());
@@ -555,6 +565,11 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
555565 llvm::StringRef InitialCode,
556566 std::vector<Range> Occurrences,
557567 llvm::StringRef NewName) {
568+ trace::Span Tracer (" BuildRenameEdit" );
569+ SPAN_ATTACH (Tracer, " file_path" , AbsFilePath);
570+ SPAN_ATTACH (Tracer, " rename_occurrences" ,
571+ static_cast <int64_t >(Occurrences.size ()));
572+
558573 assert (std::is_sorted (Occurrences.begin (), Occurrences.end ()));
559574 assert (std::unique (Occurrences.begin (), Occurrences.end ()) ==
560575 Occurrences.end () &&
@@ -618,6 +633,7 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
618633llvm::Optional<std::vector<Range>>
619634adjustRenameRanges (llvm::StringRef DraftCode, llvm::StringRef Identifier,
620635 std::vector<Range> Indexed, const LangOptions &LangOpts) {
636+ trace::Span Tracer (" AdjustRenameRanges" );
621637 assert (!Indexed.empty ());
622638 assert (std::is_sorted (Indexed.begin (), Indexed.end ()));
623639 std::vector<Range> Lexed =
@@ -628,12 +644,16 @@ adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,
628644
629645llvm::Optional<std::vector<Range>> getMappedRanges (ArrayRef<Range> Indexed,
630646 ArrayRef<Range> Lexed) {
647+ trace::Span Tracer (" GetMappedRanges" );
631648 assert (!Indexed.empty ());
632649 assert (std::is_sorted (Indexed.begin (), Indexed.end ()));
633650 assert (std::is_sorted (Lexed.begin (), Lexed.end ()));
634651
635652 if (Indexed.size () > Lexed.size ()) {
636653 vlog (" The number of lexed occurrences is less than indexed occurrences" );
654+ SPAN_ATTACH (
655+ Tracer, " error" ,
656+ " The number of lexed occurrences is less than indexed occurrences" );
637657 return llvm::None;
638658 }
639659 // Fast check for the special subset case.
@@ -660,15 +680,18 @@ llvm::Optional<std::vector<Range>> getMappedRanges(ArrayRef<Range> Indexed,
660680 });
661681 if (HasMultiple) {
662682 vlog (" The best near miss is not unique." );
683+ SPAN_ATTACH (Tracer, " error" , " The best near miss is not unique" );
663684 return llvm::None;
664685 }
665686 if (Best.empty ()) {
666687 vlog (" Didn't find a near miss." );
688+ SPAN_ATTACH (Tracer, " error" , " Didn't find a near miss" );
667689 return llvm::None;
668690 }
669691 std::vector<Range> Mapped;
670692 for (auto I : Best)
671693 Mapped.push_back (Lexed[I]);
694+ SPAN_ATTACH (Tracer, " mapped_ranges" , static_cast <int64_t >(Mapped.size ()));
672695 return Mapped;
673696}
674697
0 commit comments