Skip to content

[CodeCompletion] Enable SwiftParser parsing for code completion #65078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
// Perform round-trip and/or validation checking.
if ((Context.LangOpts.hasFeature(Feature::ParserRoundTrip) ||
Context.LangOpts.hasFeature(Feature::ParserValidation)) &&
SF.exportedSourceFile) {
SF.exportedSourceFile &&
!SourceMgr.hasIDEInspectionTargetBuffer()) {
if (Context.LangOpts.hasFeature(Feature::ParserRoundTrip) &&
swift_ASTGen_roundTripCheck(SF.exportedSourceFile)) {
SourceLoc loc;
Expand Down Expand Up @@ -305,8 +306,7 @@ Parser::parseSourceFileViaASTGen(SmallVectorImpl<ASTNode> &items,
bool suppressDiagnostics) {
#if SWIFT_SWIFT_PARSER
Optional<DiagnosticTransaction> existingParsingTransaction;
if (!SourceMgr.hasIDEInspectionTargetBuffer() &&
SF.Kind != SourceFileKind::SIL) {
if (SF.Kind != SourceFileKind::SIL) {
StringRef contents =
SourceMgr.extractText(SourceMgr.getRangeForBuffer(L->getBufferID()));

Expand Down
29 changes: 29 additions & 0 deletions test/IDE/complete_optionset.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// REQUIRES: swift_swift_parser
// RUN: %empty-directory(%t)
// 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

@OptionSet<UInt8>
struct ShippingOptions {
private enum Options: Int {
case nextDay
case secondDay
case priority
case standard
}
}

func foo() {
ShippingOptions.#^MEMBER_STATIC^#
}

// MEMBER_STATIC: Keyword[self]/CurrNominal: self[#ShippingOptions.Type#]; name=self
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: RawValue[#UInt8#]; name=RawValue
// MEMBER_STATIC: Decl[Constructor]/CurrNominal: init({#rawValue: ShippingOptions.RawValue#})[#ShippingOptions#]; name=init(rawValue:)
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: nextDay[#ShippingOptions#]; name=nextDay
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: secondDay[#ShippingOptions#]; name=secondDay
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: priority[#ShippingOptions#]; name=priority
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: standard[#ShippingOptions#]; name=standard
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: Element[#ShippingOptions#]; name=Element
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: ArrayLiteralElement[#ShippingOptions#]; name=ArrayLiteralElement
// MEMBER_STATIC: Decl[Constructor]/Super/IsSystem: init()[#ShippingOptions#]; name=init()
// MEMBER_STATIC: Decl[Constructor]/Super/IsSystem: init({#(sequence): Sequence#})[#ShippingOptions#]; name=init(:)
42 changes: 42 additions & 0 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,22 @@ ImportObjCHeader("import-objc-header",
llvm::cl::desc("header to implicitly import"),
llvm::cl::cat(Category));

static llvm::cl::list<std::string>
PluginPath("plugin-path",
llvm::cl::desc("plugin-path"),
llvm::cl::cat(Category));

static llvm::cl::list<std::string>
LoadPluginLibrary("load-plugin-library",
llvm::cl::desc("load plugin library"),
llvm::cl::cat(Category));

static llvm::cl::list<std::string>
LoadPluginExecutable("load-plugin-executable",
llvm::cl::desc("load plugin executable"),
llvm::cl::cat(Category));


static llvm::cl::opt<bool>
EnableSourceImport("enable-source-import", llvm::cl::Hidden,
llvm::cl::cat(Category), llvm::cl::init(false));
Expand Down Expand Up @@ -4473,6 +4489,32 @@ int main(int argc, char *argv[]) {
}
}

for (auto path : options::PluginPath) {
InitInvok.getSearchPathOptions().PluginSearchPaths.push_back(path);
}
if (!options::LoadPluginLibrary.empty()) {
std::vector<std::string> paths;
for (auto path: options::LoadPluginLibrary) {
paths.push_back(path);
}
InitInvok.getSearchPathOptions().setCompilerPluginLibraryPaths(paths);
}
if (!options::LoadPluginExecutable.empty()) {
std::vector<PluginExecutablePathAndModuleNames> pairs;
for (auto arg: options::LoadPluginExecutable) {
StringRef path;
StringRef modulesStr;
std::tie(path, modulesStr) = StringRef(arg).rsplit('#');
std::vector<std::string> moduleNames;
for (auto name : llvm::split(modulesStr, ',')) {
moduleNames.emplace_back(name);
}
pairs.push_back({std::string(path), std::move(moduleNames)});
}

InitInvok.getSearchPathOptions().setCompilerPluginExecutablePaths(std::move(pairs));
}

// Process the clang arguments last and allow them to override previously
// set options.
if (!CCArgs.empty()) {
Expand Down