@@ -1029,12 +1029,10 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
1029
1029
1030
1030
struct SemaCompleteInput {
1031
1031
PathRef FileName;
1032
- const tooling::CompileCommand &Command ;
1032
+ size_t Offset ;
1033
1033
const PreambleData &Preamble;
1034
1034
const llvm::Optional<PreamblePatch> Patch;
1035
- llvm::StringRef Contents;
1036
- size_t Offset;
1037
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
1035
+ const ParseInputs &ParseInput;
1038
1036
};
1039
1037
1040
1038
void loadMainFilePreambleMacros (const Preprocessor &PP,
@@ -1062,17 +1060,12 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
1062
1060
const SemaCompleteInput &Input,
1063
1061
IncludeStructure *Includes = nullptr ) {
1064
1062
trace::Span Tracer (" Sema completion" );
1065
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = Input.VFS ;
1063
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = Input.ParseInput . FS ;
1066
1064
if (Input.Preamble .StatCache )
1067
1065
VFS = Input.Preamble .StatCache ->getConsumingFS (std::move (VFS));
1068
- ParseInputs ParseInput;
1069
- ParseInput.CompileCommand = Input.Command ;
1070
- ParseInput.FS = VFS;
1071
- ParseInput.Contents = std::string (Input.Contents );
1072
- // FIXME: setup the recoveryAST and recoveryASTType in ParseInput properly.
1073
1066
1074
1067
IgnoreDiagnostics IgnoreDiags;
1075
- auto CI = buildCompilerInvocation (ParseInput, IgnoreDiags);
1068
+ auto CI = buildCompilerInvocation (Input. ParseInput , IgnoreDiags);
1076
1069
if (!CI) {
1077
1070
elog (" Couldn't create CompilerInvocation" );
1078
1071
return false ;
@@ -1090,10 +1083,11 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
1090
1083
FrontendOpts.CodeCompletionAt .FileName = std::string (Input.FileName );
1091
1084
std::tie (FrontendOpts.CodeCompletionAt .Line ,
1092
1085
FrontendOpts.CodeCompletionAt .Column ) =
1093
- offsetToClangLineColumn (Input.Contents , Input.Offset );
1086
+ offsetToClangLineColumn (Input.ParseInput . Contents , Input.Offset );
1094
1087
1095
1088
std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer =
1096
- llvm::MemoryBuffer::getMemBufferCopy (Input.Contents , Input.FileName );
1089
+ llvm::MemoryBuffer::getMemBufferCopy (Input.ParseInput .Contents ,
1090
+ Input.FileName );
1097
1091
// The diagnostic options must be set before creating a CompilerInstance.
1098
1092
CI->getDiagnosticOpts ().IgnoreWarnings = true ;
1099
1093
// We reuse the preamble whether it's valid or not. This is a
@@ -1260,9 +1254,9 @@ class CodeCompleteFlow {
1260
1254
1261
1255
CodeCompleteResult run (const SemaCompleteInput &SemaCCInput) && {
1262
1256
trace::Span Tracer (" CodeCompleteFlow" );
1263
- HeuristicPrefix =
1264
- guessCompletionPrefix (SemaCCInput. Contents , SemaCCInput.Offset );
1265
- populateContextWords (SemaCCInput.Contents );
1257
+ HeuristicPrefix = guessCompletionPrefix (SemaCCInput. ParseInput . Contents ,
1258
+ SemaCCInput.Offset );
1259
+ populateContextWords (SemaCCInput.ParseInput . Contents );
1266
1260
if (Opts.Index && SpecFuzzyFind && SpecFuzzyFind->CachedReq .hasValue ()) {
1267
1261
assert (!SpecFuzzyFind->Result .valid ());
1268
1262
SpecReq = speculativeFuzzyFindRequestForCompletion (
@@ -1278,13 +1272,14 @@ class CodeCompleteFlow {
1278
1272
assert (Recorder && " Recorder is not set" );
1279
1273
CCContextKind = Recorder->CCContext .getKind ();
1280
1274
IsUsingDeclaration = Recorder->CCContext .isUsingDeclaration ();
1281
- auto Style = getFormatStyleForFile (
1282
- SemaCCInput.FileName , SemaCCInput.Contents , SemaCCInput.VFS .get ());
1275
+ auto Style = getFormatStyleForFile (SemaCCInput.FileName ,
1276
+ SemaCCInput.ParseInput .Contents ,
1277
+ SemaCCInput.ParseInput .FS .get ());
1283
1278
// If preprocessor was run, inclusions from preprocessor callback should
1284
1279
// already be added to Includes.
1285
1280
Inserter.emplace (
1286
- SemaCCInput.FileName , SemaCCInput.Contents , Style ,
1287
- SemaCCInput.Command .Directory ,
1281
+ SemaCCInput.FileName , SemaCCInput.ParseInput . Contents , Style ,
1282
+ SemaCCInput.ParseInput . CompileCommand .Directory ,
1288
1283
&Recorder->CCSema ->getPreprocessor ().getHeaderSearchInfo ());
1289
1284
for (const auto &Inc : Includes.MainFileIncludes )
1290
1285
Inserter->addExisting (Inc);
@@ -1750,12 +1745,12 @@ CompletionPrefix guessCompletionPrefix(llvm::StringRef Content,
1750
1745
return Result;
1751
1746
}
1752
1747
1753
- CodeCompleteResult
1754
- codeComplete (PathRef FileName, const tooling::CompileCommand &Command ,
1755
- const PreambleData *Preamble, llvm::StringRef Contents ,
1756
- Position Pos, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS ,
1757
- CodeCompleteOptions Opts, SpeculativeFuzzyFind *SpecFuzzyFind) {
1758
- auto Offset = positionToOffset (Contents, Pos);
1748
+ CodeCompleteResult codeComplete (PathRef FileName, Position Pos,
1749
+ const PreambleData *Preamble ,
1750
+ const ParseInputs &ParseInput ,
1751
+ CodeCompleteOptions Opts ,
1752
+ SpeculativeFuzzyFind *SpecFuzzyFind) {
1753
+ auto Offset = positionToOffset (ParseInput. Contents , Pos);
1759
1754
if (!Offset) {
1760
1755
elog (" Code completion position was invalid {0}" , Offset.takeError ());
1761
1756
return CodeCompleteResult ();
@@ -1764,21 +1759,18 @@ codeComplete(PathRef FileName, const tooling::CompileCommand &Command,
1764
1759
FileName, Preamble ? Preamble->Includes : IncludeStructure (),
1765
1760
SpecFuzzyFind, Opts);
1766
1761
return (!Preamble || Opts.RunParser == CodeCompleteOptions::NeverParse)
1767
- ? std::move (Flow).runWithoutSema (Contents, *Offset, VFS)
1768
- : std::move (Flow).run ({FileName, Command, *Preamble,
1762
+ ? std::move (Flow).runWithoutSema (ParseInput.Contents , *Offset,
1763
+ ParseInput.FS )
1764
+ : std::move (Flow).run ({FileName, *Offset, *Preamble,
1769
1765
// We want to serve code completions with
1770
1766
// low latency, so don't bother patching.
1771
- /* PreamblePatch=*/ llvm::None, Contents,
1772
- *Offset, VFS});
1767
+ /* PreamblePatch=*/ llvm::None, ParseInput});
1773
1768
}
1774
1769
1775
- SignatureHelp signatureHelp (PathRef FileName,
1776
- const tooling::CompileCommand &Command,
1770
+ SignatureHelp signatureHelp (PathRef FileName, Position Pos,
1777
1771
const PreambleData &Preamble,
1778
- llvm::StringRef Contents, Position Pos,
1779
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
1780
- const SymbolIndex *Index) {
1781
- auto Offset = positionToOffset (Contents, Pos);
1772
+ const ParseInputs &ParseInput) {
1773
+ auto Offset = positionToOffset (ParseInput.Contents , Pos);
1782
1774
if (!Offset) {
1783
1775
elog (" Signature help position was invalid {0}" , Offset.takeError ());
1784
1776
return SignatureHelp ();
@@ -1789,16 +1781,12 @@ SignatureHelp signatureHelp(PathRef FileName,
1789
1781
Options.IncludeMacros = false ;
1790
1782
Options.IncludeCodePatterns = false ;
1791
1783
Options.IncludeBriefComments = false ;
1792
-
1793
- ParseInputs PI;
1794
- PI.CompileCommand = Command;
1795
- PI.Contents = Contents.str ();
1796
- PI.FS = std::move (VFS);
1797
1784
semaCodeComplete (
1798
- std::make_unique<SignatureHelpCollector>(Options, Index, Result), Options,
1799
- {FileName, Command, Preamble,
1800
- PreamblePatch::create (FileName, PI, Preamble), Contents, *Offset,
1801
- std::move (PI.FS )});
1785
+ std::make_unique<SignatureHelpCollector>(Options, ParseInput.Index ,
1786
+ Result),
1787
+ Options,
1788
+ {FileName, *Offset, Preamble,
1789
+ PreamblePatch::create (FileName, ParseInput, Preamble), ParseInput});
1802
1790
return Result;
1803
1791
}
1804
1792
0 commit comments