Skip to content

Commit 153c9d2

Browse files
authored
Merge pull request swiftlang#65078 from rintaro/ide-completion-rdar107900870
[CodeCompletion] Enable SwiftParser parsing for code completion
2 parents 252cc1e + f9feee6 commit 153c9d2

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

lib/Parse/ParseDecl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
269269
// Perform round-trip and/or validation checking.
270270
if ((Context.LangOpts.hasFeature(Feature::ParserRoundTrip) ||
271271
Context.LangOpts.hasFeature(Feature::ParserValidation)) &&
272-
SF.exportedSourceFile) {
272+
SF.exportedSourceFile &&
273+
!SourceMgr.hasIDEInspectionTargetBuffer()) {
273274
if (Context.LangOpts.hasFeature(Feature::ParserRoundTrip) &&
274275
swift_ASTGen_roundTripCheck(SF.exportedSourceFile)) {
275276
SourceLoc loc;
@@ -305,8 +306,7 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
305306
bool suppressDiagnostics) {
306307
#if SWIFT_SWIFT_PARSER
307308
Optional<DiagnosticTransaction> existingParsingTransaction;
308-
if (!SourceMgr.hasIDEInspectionTargetBuffer() &&
309-
SF.Kind != SourceFileKind::SIL) {
309+
if (SF.Kind != SourceFileKind::SIL) {
310310
StringRef contents =
311311
SourceMgr.extractText(SourceMgr.getRangeForBuffer(L->getBufferID()));
312312

test/IDE/complete_optionset.swift

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// REQUIRES: swift_swift_parser
2+
// RUN: %empty-directory(%t)
3+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -plugin-path %swift-host-lib-dir/plugins
4+
5+
@OptionSet<UInt8>
6+
struct ShippingOptions {
7+
private enum Options: Int {
8+
case nextDay
9+
case secondDay
10+
case priority
11+
case standard
12+
}
13+
}
14+
15+
func foo() {
16+
ShippingOptions.#^MEMBER_STATIC^#
17+
}
18+
19+
// MEMBER_STATIC: Keyword[self]/CurrNominal: self[#ShippingOptions.Type#]; name=self
20+
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: RawValue[#UInt8#]; name=RawValue
21+
// MEMBER_STATIC: Decl[Constructor]/CurrNominal: init({#rawValue: ShippingOptions.RawValue#})[#ShippingOptions#]; name=init(rawValue:)
22+
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: nextDay[#ShippingOptions#]; name=nextDay
23+
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: secondDay[#ShippingOptions#]; name=secondDay
24+
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: priority[#ShippingOptions#]; name=priority
25+
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: standard[#ShippingOptions#]; name=standard
26+
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: Element[#ShippingOptions#]; name=Element
27+
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: ArrayLiteralElement[#ShippingOptions#]; name=ArrayLiteralElement
28+
// MEMBER_STATIC: Decl[Constructor]/Super/IsSystem: init()[#ShippingOptions#]; name=init()
29+
// MEMBER_STATIC: Decl[Constructor]/Super/IsSystem: init({#(sequence): Sequence#})[#ShippingOptions#]; name=init(:)

tools/swift-ide-test/swift-ide-test.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,22 @@ ImportObjCHeader("import-objc-header",
332332
llvm::cl::desc("header to implicitly import"),
333333
llvm::cl::cat(Category));
334334

335+
static llvm::cl::list<std::string>
336+
PluginPath("plugin-path",
337+
llvm::cl::desc("plugin-path"),
338+
llvm::cl::cat(Category));
339+
340+
static llvm::cl::list<std::string>
341+
LoadPluginLibrary("load-plugin-library",
342+
llvm::cl::desc("load plugin library"),
343+
llvm::cl::cat(Category));
344+
345+
static llvm::cl::list<std::string>
346+
LoadPluginExecutable("load-plugin-executable",
347+
llvm::cl::desc("load plugin executable"),
348+
llvm::cl::cat(Category));
349+
350+
335351
static llvm::cl::opt<bool>
336352
EnableSourceImport("enable-source-import", llvm::cl::Hidden,
337353
llvm::cl::cat(Category), llvm::cl::init(false));
@@ -4473,6 +4489,32 @@ int main(int argc, char *argv[]) {
44734489
}
44744490
}
44754491

4492+
for (auto path : options::PluginPath) {
4493+
InitInvok.getSearchPathOptions().PluginSearchPaths.push_back(path);
4494+
}
4495+
if (!options::LoadPluginLibrary.empty()) {
4496+
std::vector<std::string> paths;
4497+
for (auto path: options::LoadPluginLibrary) {
4498+
paths.push_back(path);
4499+
}
4500+
InitInvok.getSearchPathOptions().setCompilerPluginLibraryPaths(paths);
4501+
}
4502+
if (!options::LoadPluginExecutable.empty()) {
4503+
std::vector<PluginExecutablePathAndModuleNames> pairs;
4504+
for (auto arg: options::LoadPluginExecutable) {
4505+
StringRef path;
4506+
StringRef modulesStr;
4507+
std::tie(path, modulesStr) = StringRef(arg).rsplit('#');
4508+
std::vector<std::string> moduleNames;
4509+
for (auto name : llvm::split(modulesStr, ',')) {
4510+
moduleNames.emplace_back(name);
4511+
}
4512+
pairs.push_back({std::string(path), std::move(moduleNames)});
4513+
}
4514+
4515+
InitInvok.getSearchPathOptions().setCompilerPluginExecutablePaths(std::move(pairs));
4516+
}
4517+
44764518
// Process the clang arguments last and allow them to override previously
44774519
// set options.
44784520
if (!CCArgs.empty()) {

0 commit comments

Comments
 (0)