@@ -88,15 +88,15 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
88
88
indexStdlib (CI, std::move (*Loc));
89
89
90
90
// FIndex outlives the UpdateIndexCallbacks.
91
- auto Task = [FIndex (FIndex), Path (Path.str ()), Version (Version.str ()),
91
+ auto Task = [FIndex (FIndex), Path (Path.owned ()), Version (Version.str ()),
92
92
ASTCtx (std::move (ASTCtx)), PI (std::move (PI))]() mutable {
93
93
trace::Span Tracer (" PreambleIndexing" );
94
- FIndex->updatePreamble (Path, Version, ASTCtx.getASTContext (),
94
+ FIndex->updatePreamble (Path. raw () , Version, ASTCtx.getASTContext (),
95
95
ASTCtx.getPreprocessor (), *PI);
96
96
};
97
97
98
98
if (Tasks) {
99
- Tasks->runAsync (" Preamble indexing for:" + Path + Version,
99
+ Tasks->runAsync (" Preamble indexing for:" + Path. raw () + Version,
100
100
std::move (Task));
101
101
} else
102
102
Task ();
@@ -262,7 +262,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
262
262
BackgroundIdx = std::make_unique<BackgroundIndex>(
263
263
TFS, CDB,
264
264
BackgroundIndexStorage::createDiskBackedStorageFactory (
265
- [&CDB](llvm::StringRef File) { return CDB.getProjectInfo (File); }),
265
+ [&CDB](PathRef File) { return CDB.getProjectInfo (File); }),
266
266
std::move (BGOpts));
267
267
AddIndex (BackgroundIdx.get ());
268
268
}
@@ -316,14 +316,14 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
316
316
bool NewFile = WorkScheduler->update (File, Inputs, WantDiags);
317
317
// If we loaded Foo.h, we want to make sure Foo.cpp is indexed.
318
318
if (NewFile && BackgroundIdx)
319
- BackgroundIdx->boostRelated (File);
319
+ BackgroundIdx->boostRelated (File. raw () );
320
320
}
321
321
322
322
void ClangdServer::reparseOpenFilesIfNeeded (
323
323
llvm::function_ref<bool (llvm::StringRef File)> Filter) {
324
324
// Reparse only opened files that were modified.
325
325
for (const Path &FilePath : DraftMgr.getActiveFiles ())
326
- if (Filter (FilePath))
326
+ if (Filter (FilePath. raw () ))
327
327
if (auto Draft = DraftMgr.getDraft (FilePath)) // else disappeared in race?
328
328
addDocument (FilePath, *Draft->Contents , Draft->Version ,
329
329
WantDiagnostics::Auto);
@@ -340,7 +340,7 @@ std::function<Context(PathRef)>
340
340
ClangdServer::createConfiguredContextProvider (const config::Provider *Provider,
341
341
Callbacks *Publish) {
342
342
if (!Provider)
343
- return [](llvm::StringRef ) { return Context::current ().clone (); };
343
+ return [](PathRef ) { return Context::current ().clone (); };
344
344
345
345
struct Impl {
346
346
const config::Provider *Provider;
@@ -408,8 +408,8 @@ ClangdServer::createConfiguredContextProvider(const config::Provider *Provider,
408
408
};
409
409
410
410
// Copyable wrapper.
411
- return [I (std::make_shared<Impl>(Provider, Publish))](llvm::StringRef Path) {
412
- return (*I)(Path);
411
+ return [I (std::make_shared<Impl>(Provider, Publish))](PathRef Path) {
412
+ return (*I)(Path. raw () );
413
413
};
414
414
}
415
415
@@ -426,7 +426,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
426
426
if (!CodeCompleteOpts.Index ) // Respect overridden index.
427
427
CodeCompleteOpts.Index = Index;
428
428
429
- auto Task = [Pos, CodeCompleteOpts, File = File.str (), CB = std::move (CB),
429
+ auto Task = [Pos, CodeCompleteOpts, File = File.owned (), CB = std::move (CB),
430
430
this ](llvm::Expected<InputsAndPreamble> IP) mutable {
431
431
if (!IP)
432
432
return CB (IP.takeError ());
@@ -442,7 +442,8 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
442
442
SpecFuzzyFind.emplace ();
443
443
{
444
444
std::lock_guard<std::mutex> Lock (CachedCompletionFuzzyFindRequestMutex);
445
- SpecFuzzyFind->CachedReq = CachedCompletionFuzzyFindRequestByFile[File];
445
+ SpecFuzzyFind->CachedReq =
446
+ CachedCompletionFuzzyFindRequestByFile[File.raw ()];
446
447
}
447
448
}
448
449
ParseInputs ParseInput{IP->Command , &getHeaderFS (), IP->Contents .str ()};
@@ -473,7 +474,8 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
473
474
return ;
474
475
if (SpecFuzzyFind->NewReq ) {
475
476
std::lock_guard<std::mutex> Lock (CachedCompletionFuzzyFindRequestMutex);
476
- CachedCompletionFuzzyFindRequestByFile[File] = *SpecFuzzyFind->NewReq ;
477
+ CachedCompletionFuzzyFindRequestByFile[File.raw ()] =
478
+ *SpecFuzzyFind->NewReq ;
477
479
}
478
480
// Explicitly block until async task completes, this is fine as we've
479
481
// already provided reply to the client and running as a preamble task
@@ -495,7 +497,7 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
495
497
MarkupKind DocumentationFormat,
496
498
Callback<SignatureHelp> CB) {
497
499
498
- auto Action = [Pos, File = File.str (), CB = std::move (CB),
500
+ auto Action = [Pos, File = File.owned (), CB = std::move (CB),
499
501
DocumentationFormat,
500
502
this ](llvm::Expected<InputsAndPreamble> IP) mutable {
501
503
if (!IP)
@@ -540,22 +542,23 @@ void ClangdServer::formatFile(PathRef File, std::optional<Range> Rng,
540
542
}
541
543
542
544
// Call clang-format.
543
- auto Action = [File = File.str (), Code = std::move (*Code),
545
+ auto Action = [File = File.owned (), Code = std::move (*Code),
544
546
Ranges = std::vector<tooling::Range>{RequestedRange},
545
547
CB = std::move (CB), this ]() mutable {
546
- format::FormatStyle Style = getFormatStyleForFile (File, Code, TFS, true );
548
+ format::FormatStyle Style =
549
+ getFormatStyleForFile (File.raw (), Code, TFS, true );
547
550
tooling::Replacements IncludeReplaces =
548
- format::sortIncludes (Style , Code, Ranges, File);
551
+ format::sortIncludes (Style , Code, Ranges, File. raw () );
549
552
auto Changed = tooling::applyAllReplacements (Code, IncludeReplaces);
550
553
if (!Changed)
551
554
return CB (Changed.takeError ());
552
555
553
556
CB (IncludeReplaces.merge (format::reformat (
554
557
Style , *Changed,
555
558
tooling::calculateRangesAfterReplacements (IncludeReplaces, Ranges),
556
- File)));
559
+ File. raw () )));
557
560
};
558
- WorkScheduler->runQuick (" Format" , File, std::move (Action));
561
+ WorkScheduler->runQuick (" Format" , File. raw () , std::move (Action));
559
562
}
560
563
561
564
void ClangdServer::formatOnType (PathRef File, Position Pos,
@@ -568,24 +571,24 @@ void ClangdServer::formatOnType(PathRef File, Position Pos,
568
571
llvm::Expected<size_t > CursorPos = positionToOffset (*Code, Pos);
569
572
if (!CursorPos)
570
573
return CB (CursorPos.takeError ());
571
- auto Action = [File = File.str (), Code = std::move (*Code),
574
+ auto Action = [File = File.owned (), Code = std::move (*Code),
572
575
TriggerText = TriggerText.str (), CursorPos = *CursorPos,
573
576
CB = std::move (CB), this ]() mutable {
574
- auto Style = getFormatStyleForFile (File, Code, TFS, false );
577
+ auto Style = getFormatStyleForFile (File. raw () , Code, TFS, false );
575
578
std::vector<TextEdit> Result;
576
579
for (const tooling::Replacement &R :
577
580
formatIncremental (Code, CursorPos, TriggerText, Style ))
578
581
Result.push_back (replacementToEdit (Code, R));
579
582
return CB (Result);
580
583
};
581
- WorkScheduler->runQuick (" FormatOnType" , File, std::move (Action));
584
+ WorkScheduler->runQuick (" FormatOnType" , File. raw () , std::move (Action));
582
585
}
583
586
584
587
void ClangdServer::prepareRename (PathRef File, Position Pos,
585
588
std::optional<std::string> NewName,
586
589
const RenameOptions &RenameOpts,
587
590
Callback<RenameResult> CB) {
588
- auto Action = [Pos, File = File.str (), CB = std::move (CB),
591
+ auto Action = [Pos, File = File.owned (), CB = std::move (CB),
589
592
NewName = std::move (NewName),
590
593
RenameOpts](llvm::Expected<InputsAndAST> InpAST) mutable {
591
594
if (!InpAST)
@@ -594,7 +597,7 @@ void ClangdServer::prepareRename(PathRef File, Position Pos,
594
597
// only need main-file references
595
598
auto Results =
596
599
clangd::rename ({Pos, NewName.value_or (" __clangd_rename_placeholder" ),
597
- InpAST->AST , File, /* FS=*/ nullptr ,
600
+ InpAST->AST , File. raw () , /* FS=*/ nullptr ,
598
601
/* Index=*/ nullptr , RenameOpts});
599
602
if (!Results) {
600
603
// LSP says to return null on failure, but that will result in a generic
@@ -610,21 +613,21 @@ void ClangdServer::prepareRename(PathRef File, Position Pos,
610
613
void ClangdServer::rename (PathRef File, Position Pos, llvm::StringRef NewName,
611
614
const RenameOptions &Opts,
612
615
Callback<RenameResult> CB) {
613
- auto Action = [File = File.str (), NewName = NewName.str (), Pos, Opts,
616
+ auto Action = [File = File.owned (), NewName = NewName.str (), Pos, Opts,
614
617
CB = std::move (CB),
615
618
this ](llvm::Expected<InputsAndAST> InpAST) mutable {
616
619
// Tracks number of files edited per invocation.
617
620
static constexpr trace::Metric RenameFiles (" rename_files" ,
618
621
trace::Metric::Distribution);
619
622
if (!InpAST)
620
623
return CB (InpAST.takeError ());
621
- auto R = clangd::rename ({Pos, NewName, InpAST->AST , File,
624
+ auto R = clangd::rename ({Pos, NewName, InpAST->AST , File. raw () ,
622
625
DirtyFS->view (std::nullopt), Index, Opts});
623
626
if (!R)
624
627
return CB (R.takeError ());
625
628
626
629
if (Opts.WantFormat ) {
627
- auto Style = getFormatStyleForFile (File, InpAST->Inputs .Contents ,
630
+ auto Style = getFormatStyleForFile (File. raw () , InpAST->Inputs .Contents ,
628
631
*InpAST->Inputs .TFS , false );
629
632
llvm::Error Err = llvm::Error::success ();
630
633
for (auto &E : R->GlobalChanges )
@@ -756,7 +759,7 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
756
759
static constexpr trace::Metric TweakFailed (
757
760
" tweak_failed" , trace::Metric::Counter, " tweak_id" );
758
761
TweakAttempt.record (1 , TweakID);
759
- auto Action = [File = File.str (), Sel, TweakID = TweakID.str (),
762
+ auto Action = [File = File.owned (), Sel, TweakID = TweakID.str (),
760
763
CB = std::move (CB),
761
764
this ](Expected<InputsAndAST> InpAST) mutable {
762
765
if (!InpAST)
@@ -782,7 +785,7 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
782
785
for (auto &It : (*Effect)->ApplyEdits ) {
783
786
Edit &E = It.second ;
784
787
format::FormatStyle Style =
785
- getFormatStyleForFile (File, E.InitialCode , TFS, false );
788
+ getFormatStyleForFile (File. raw () , E.InitialCode , TFS, false );
786
789
if (llvm::Error Err = reformatEdit (E, Style ))
787
790
elog (" Failed to format {0}: {1}" , It.first (), std::move (Err));
788
791
}
@@ -817,7 +820,7 @@ void ClangdServer::switchSourceHeader(
817
820
if (auto CorrespondingFile =
818
821
getCorrespondingHeaderOrSource (Path, TFS.view (std::nullopt)))
819
822
return CB (std::move (CorrespondingFile));
820
- auto Action = [Path = Path.str (), CB = std::move (CB),
823
+ auto Action = [Path = Path.owned (), CB = std::move (CB),
821
824
this ](llvm::Expected<InputsAndAST> InpAST) mutable {
822
825
if (!InpAST)
823
826
return CB (InpAST.takeError ());
@@ -840,12 +843,12 @@ void ClangdServer::findDocumentHighlights(
840
843
841
844
void ClangdServer::findHover (PathRef File, Position Pos,
842
845
Callback<std::optional<HoverInfo>> CB) {
843
- auto Action = [File = File.str (), Pos, CB = std::move (CB),
846
+ auto Action = [File = File.owned (), Pos, CB = std::move (CB),
844
847
this ](llvm::Expected<InputsAndAST> InpAST) mutable {
845
848
if (!InpAST)
846
849
return CB (InpAST.takeError ());
847
850
format::FormatStyle Style = getFormatStyleForFile (
848
- File, InpAST->Inputs .Contents , *InpAST->Inputs .TFS , false );
851
+ File. raw () , InpAST->Inputs .Contents , *InpAST->Inputs .TFS , false );
849
852
CB (clangd::getHover (InpAST->AST , Pos, std::move (Style ), Index));
850
853
};
851
854
@@ -855,7 +858,8 @@ void ClangdServer::findHover(PathRef File, Position Pos,
855
858
void ClangdServer::typeHierarchy (PathRef File, Position Pos, int Resolve,
856
859
TypeHierarchyDirection Direction,
857
860
Callback<std::vector<TypeHierarchyItem>> CB) {
858
- auto Action = [File = File.str (), Pos, Resolve, Direction, CB = std::move (CB),
861
+ auto Action = [File = File.owned (), Pos, Resolve, Direction,
862
+ CB = std::move (CB),
859
863
this ](Expected<InputsAndAST> InpAST) mutable {
860
864
if (!InpAST)
861
865
return CB (InpAST.takeError ());
@@ -894,7 +898,7 @@ void ClangdServer::resolveTypeHierarchy(
894
898
895
899
void ClangdServer::prepareCallHierarchy (
896
900
PathRef File, Position Pos, Callback<std::vector<CallHierarchyItem>> CB) {
897
- auto Action = [File = File.str (), Pos,
901
+ auto Action = [File = File.owned (), Pos,
898
902
CB = std::move (CB)](Expected<InputsAndAST> InpAST) mutable {
899
903
if (!InpAST)
900
904
return CB (InpAST.takeError ());
@@ -976,7 +980,7 @@ void ClangdServer::foldingRanges(llvm::StringRef File,
976
980
WorkScheduler->runQuick (" FoldingRanges" , File, std::move (Action));
977
981
}
978
982
979
- void ClangdServer::findType (llvm::StringRef File, Position Pos,
983
+ void ClangdServer::findType (PathRef File, Position Pos,
980
984
Callback<std::vector<LocatedSymbol>> CB) {
981
985
auto Action = [Pos, CB = std::move (CB),
982
986
this ](llvm::Expected<InputsAndAST> InpAST) mutable {
0 commit comments