13
13
#include " ParsedAST.h"
14
14
#include " Selection.h"
15
15
#include " SourceCode.h"
16
+ #include " Trace.h"
16
17
#include " index/SymbolCollector.h"
17
18
#include " clang/AST/DeclCXX.h"
18
19
#include " clang/AST/DeclTemplate.h"
@@ -124,6 +125,7 @@ llvm::Optional<ReasonToReject> renameable(const NamedDecl &RenameDecl,
124
125
StringRef MainFilePath,
125
126
const SymbolIndex *Index,
126
127
bool CrossFile) {
128
+ trace::Span Tracer (" Renameable" );
127
129
// Filter out symbols that are unsupported in both rename modes.
128
130
if (llvm::isa<NamespaceDecl>(&RenameDecl))
129
131
return ReasonToReject::UnsupportedSymbol;
@@ -225,6 +227,7 @@ llvm::Error makeError(ReasonToReject Reason) {
225
227
// Return all rename occurrences in the main file.
226
228
std::vector<SourceLocation> findOccurrencesWithinFile (ParsedAST &AST,
227
229
const NamedDecl &ND) {
230
+ trace::Span Tracer (" FindOccurrenceeWithinFile" );
228
231
// If the cursor is at the underlying CXXRecordDecl of the
229
232
// ClassTemplateDecl, ND will be the CXXRecordDecl. In this case, we need to
230
233
// get the primary template maunally.
@@ -260,6 +263,7 @@ std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
260
263
llvm::Expected<tooling::Replacements>
261
264
renameWithinFile (ParsedAST &AST, const NamedDecl &RenameDecl,
262
265
llvm::StringRef NewName) {
266
+ trace::Span Tracer (" RenameWithinFile" );
263
267
const SourceManager &SM = AST.getSourceManager ();
264
268
265
269
tooling::Replacements FilteredChanges;
@@ -319,6 +323,7 @@ std::vector<const CXXConstructorDecl *> getConstructors(const NamedDecl *ND) {
319
323
llvm::Expected<llvm::StringMap<std::vector<Range>>>
320
324
findOccurrencesOutsideFile (const NamedDecl &RenameDecl,
321
325
llvm::StringRef MainFile, const SymbolIndex &Index) {
326
+ trace::Span Tracer (" FindOccurrencesOutsideFile" );
322
327
RefsRequest RQuest;
323
328
RQuest.IDs .insert (*getSymbolID (&RenameDecl));
324
329
// Classes and their constructors are different symbols, and have different
@@ -361,6 +366,9 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
361
366
auto &Ranges = FileAndOccurrences.getValue ();
362
367
llvm::sort (Ranges);
363
368
Ranges.erase (std::unique (Ranges.begin (), Ranges.end ()), Ranges.end ());
369
+
370
+ SPAN_ATTACH (Tracer, FileAndOccurrences.first (),
371
+ static_cast <int64_t >(Ranges.size ()));
364
372
}
365
373
return AffectedFiles;
366
374
}
@@ -381,6 +389,7 @@ llvm::Expected<FileEdits> renameOutsideFile(
381
389
const NamedDecl &RenameDecl, llvm::StringRef MainFilePath,
382
390
llvm::StringRef NewName, const SymbolIndex &Index,
383
391
llvm::function_ref<llvm::Expected<std::string>(PathRef)> GetFileContent) {
392
+ trace::Span Tracer (" RenameOutsideFile" );
384
393
auto AffectedFiles =
385
394
findOccurrencesOutsideFile (RenameDecl, MainFilePath, Index);
386
395
if (!AffectedFiles)
@@ -463,6 +472,7 @@ void findNearMiss(
463
472
} // namespace
464
473
465
474
llvm::Expected<FileEdits> rename (const RenameInputs &RInputs) {
475
+ trace::Span Tracer (" Rename flow" );
466
476
ParsedAST &AST = RInputs.AST ;
467
477
const SourceManager &SM = AST.getSourceManager ();
468
478
llvm::StringRef MainFileCode = SM.getBufferData (SM.getMainFileID ());
@@ -555,6 +565,11 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
555
565
llvm::StringRef InitialCode,
556
566
std::vector<Range> Occurrences,
557
567
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
+
558
573
assert (std::is_sorted (Occurrences.begin (), Occurrences.end ()));
559
574
assert (std::unique (Occurrences.begin (), Occurrences.end ()) ==
560
575
Occurrences.end () &&
@@ -618,6 +633,7 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
618
633
llvm::Optional<std::vector<Range>>
619
634
adjustRenameRanges (llvm::StringRef DraftCode, llvm::StringRef Identifier,
620
635
std::vector<Range> Indexed, const LangOptions &LangOpts) {
636
+ trace::Span Tracer (" AdjustRenameRanges" );
621
637
assert (!Indexed.empty ());
622
638
assert (std::is_sorted (Indexed.begin (), Indexed.end ()));
623
639
std::vector<Range> Lexed =
@@ -628,12 +644,16 @@ adjustRenameRanges(llvm::StringRef DraftCode, llvm::StringRef Identifier,
628
644
629
645
llvm::Optional<std::vector<Range>> getMappedRanges (ArrayRef<Range> Indexed,
630
646
ArrayRef<Range> Lexed) {
647
+ trace::Span Tracer (" GetMappedRanges" );
631
648
assert (!Indexed.empty ());
632
649
assert (std::is_sorted (Indexed.begin (), Indexed.end ()));
633
650
assert (std::is_sorted (Lexed.begin (), Lexed.end ()));
634
651
635
652
if (Indexed.size () > Lexed.size ()) {
636
653
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" );
637
657
return llvm::None;
638
658
}
639
659
// Fast check for the special subset case.
@@ -660,15 +680,18 @@ llvm::Optional<std::vector<Range>> getMappedRanges(ArrayRef<Range> Indexed,
660
680
});
661
681
if (HasMultiple) {
662
682
vlog (" The best near miss is not unique." );
683
+ SPAN_ATTACH (Tracer, " error" , " The best near miss is not unique" );
663
684
return llvm::None;
664
685
}
665
686
if (Best.empty ()) {
666
687
vlog (" Didn't find a near miss." );
688
+ SPAN_ATTACH (Tracer, " error" , " Didn't find a near miss" );
667
689
return llvm::None;
668
690
}
669
691
std::vector<Range> Mapped;
670
692
for (auto I : Best)
671
693
Mapped.push_back (Lexed[I]);
694
+ SPAN_ATTACH (Tracer, " mapped_ranges" , static_cast <int64_t >(Mapped.size ()));
672
695
return Mapped;
673
696
}
674
697
0 commit comments