Skip to content

Commit 1fe5f04

Browse files
committed
[SourceKit] Use req options instead of compiler arguments for controlling index-to-store behavior
1 parent 4c7e02d commit 1fe5f04

File tree

4 files changed

+66
-29
lines changed

4 files changed

+66
-29
lines changed

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ struct RenameLocations {
881881
struct IndexStoreOptions {
882882
std::string IndexStorePath;
883883
std::string IndexUnitOutputPath;
884+
bool IgnoreClangModules = false;
885+
bool IncludeSystemModules = false;
886+
bool IgnoreStdlib = false;
887+
bool DisableImplicitModules = false;
884888
bool IncludeLocals = false;
885889
};
886890

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,11 @@ void SwiftLangSupport::indexSource(StringRef InputFile,
370370
}
371371

372372
static void emitIndexDataForSourceFile(SourceFile &PrimarySourceFile,
373-
StringRef IndexStorePath,
374-
StringRef IndexUnitOutputPath,
375-
bool IncludeLocals,
373+
IndexStoreOptions IndexOpts,
376374
const CompilerInstance &Instance) {
377375
const auto &Invocation = Instance.getInvocation();
378-
const auto &Opts = Invocation.getFrontendOptions();
376+
// FIXME: Compiler arguments should be the default for setting options, but this is currently broken (see PR #69076)
377+
// const auto &Opts = Invocation.getFrontendOptions();
379378

380379
bool isDebugCompilation;
381380
switch (Invocation.getSILOptions().OptMode) {
@@ -389,14 +388,15 @@ static void emitIndexDataForSourceFile(SourceFile &PrimarySourceFile,
389388
break;
390389
}
391390

392-
(void) index::indexAndRecord(&PrimarySourceFile, IndexUnitOutputPath,
393-
IndexStorePath,
394-
!Opts.IndexIgnoreClangModules,
395-
Opts.IndexSystemModules,
396-
Opts.IndexIgnoreStdlib,
397-
IncludeLocals,
391+
(void) index::indexAndRecord(&PrimarySourceFile,
392+
IndexOpts.IndexUnitOutputPath,
393+
IndexOpts.IndexStorePath,
394+
!IndexOpts.IgnoreClangModules,
395+
IndexOpts.IncludeSystemModules,
396+
IndexOpts.IgnoreStdlib,
397+
IndexOpts.IncludeLocals,
398398
isDebugCompilation,
399-
Opts.DisableImplicitModules,
399+
IndexOpts.DisableImplicitModules,
400400
Invocation.getTargetTriple(),
401401
*Instance.getDependencyTracker(),
402402
Invocation.getIRGenOptions().FilePrefixMap);
@@ -426,9 +426,7 @@ void SwiftLangSupport::indexToStore(
426426
void handlePrimaryAST(ASTUnitRef AstUnit) override {
427427
auto &SF = AstUnit->getPrimarySourceFile();
428428
auto &CI = AstUnit->getCompilerInstance();
429-
emitIndexDataForSourceFile(SF, Opts.IndexStorePath,
430-
Opts.IndexUnitOutputPath, Opts.IncludeLocals,
431-
CI);
429+
emitIndexDataForSourceFile(SF, Opts, CI);
432430
Receiver(RequestResult<IndexStoreInfo>::fromResult(IndexStoreInfo{}));
433431
}
434432

tools/SourceKit/tools/sourcekitd/lib/Service/Requests.cpp

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,48 @@ static void handleRequestIndex(const RequestDict &Req,
14211421
});
14221422
}
14231423
1424+
static std::optional<IndexStoreOptions>
1425+
getIndexStoreOpts(const RequestDict &Req, ResponseReceiver Rec) {
1426+
IndexStoreOptions Opts;
1427+
if (auto IndexStorePath = Req.getString(KeyIndexStorePath))
1428+
Opts.IndexStorePath = IndexStorePath->str();
1429+
else {
1430+
Rec(createErrorRequestInvalid("'key.index_store_path' is required"));
1431+
return std::nullopt;
1432+
}
1433+
1434+
if (auto IndexUnitOutputPath = Req.getString(KeyIndexUnitOutputPath))
1435+
Opts.IndexUnitOutputPath = IndexUnitOutputPath->str();
1436+
else {
1437+
Rec(createErrorRequestInvalid("'key.index_unit_output_path' is required"));
1438+
return std::nullopt;
1439+
}
1440+
1441+
if (auto IncludeLocals = Req.getOptionalInt64(KeyIncludeLocals)) {
1442+
Opts.IncludeLocals = IncludeLocals.value() > 0;
1443+
}
1444+
1445+
if (auto IgnoreClangModules = Req.getOptionalInt64(KeyIgnoreClangModules)) {
1446+
Opts.IgnoreClangModules = IgnoreClangModules.value() > 0;
1447+
}
1448+
1449+
if (auto IncludeSystemModules =
1450+
Req.getOptionalInt64(KeyIncludeSystemModules)) {
1451+
Opts.IncludeSystemModules = IncludeSystemModules.value() > 0;
1452+
}
1453+
1454+
if (auto IgnoreStdlib = Req.getOptionalInt64(KeyIgnoreStdlib)) {
1455+
Opts.IgnoreStdlib = IgnoreStdlib.value() > 0;
1456+
}
1457+
1458+
if (auto DisableImplicitModules =
1459+
Req.getOptionalInt64(KeyDisableImplicitModules)) {
1460+
Opts.DisableImplicitModules = DisableImplicitModules.value() > 0;
1461+
}
1462+
1463+
return Opts;
1464+
}
1465+
14241466
static void handleRequestIndexToStore(
14251467
const RequestDict &Req, SourceKitCancellationToken CancellationToken,
14261468
ResponseReceiver Rec) {
@@ -1433,26 +1475,15 @@ static void handleRequestIndexToStore(
14331475
if (!PrimaryFilePath)
14341476
return;
14351477
1436-
IndexStoreOptions Opts;
1437-
if (auto IndexStorePath = Req.getString(KeyIndexStorePath))
1438-
Opts.IndexStorePath = IndexStorePath->str();
1439-
else
1440-
return Rec(createErrorRequestInvalid("'key.index_store_path' is required"));
1441-
1442-
if (auto IndexUnitOutputPath = Req.getString(KeyIndexUnitOutputPath))
1443-
Opts.IndexUnitOutputPath = IndexUnitOutputPath->str();
1444-
else
1445-
return Rec(createErrorRequestInvalid("'key.index_unit_output_path' is required"));
1446-
1447-
if (auto IncludeLocals = Req.getOptionalInt64(KeyIncludeLocals)) {
1448-
Opts.IncludeLocals = IncludeLocals.value() > 0;
1449-
}
1478+
std::optional<IndexStoreOptions> Opts = getIndexStoreOpts(Req, Rec);
1479+
if (!Opts)
1480+
return;
14501481
14511482
SmallVector<const char *, 0> Args;
14521483
if (getCompilerArgumentsForRequestOrEmitError(Req, Args, Rec))
14531484
return;
14541485
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();
1455-
Lang.indexToStore(*PrimaryFilePath, Args, std::move(Opts),
1486+
Lang.indexToStore(*PrimaryFilePath, Args, std::move(*Opts),
14561487
CancellationToken,
14571488
[Rec](const RequestResult<IndexStoreInfo> &Result) {
14581489
if (Result.isCancelled())

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def __init__(self, internal_name, external_name):
215215
KEY('IndexStorePath', 'key.index_store_path'),
216216
KEY('IndexUnitOutputPath', 'key.index_unit_output_path'),
217217
KEY('IncludeLocals', 'key.include_locals'),
218+
KEY('IgnoreClangModules', 'key.ignore_clang_modules'),
219+
KEY('IncludeSystemModules', 'key.include_system_modules'),
220+
KEY('IgnoreStdlib', 'key.ignore_stdlib'),
221+
KEY('DisableImplicitModules', 'key.disable_implicit_modules'),
218222
]
219223

220224

0 commit comments

Comments
 (0)