Skip to content

Commit e7c92f7

Browse files
authored
Merge pull request #70704 from rintaro/ide-completion-embedded-rdar119691781
[CodeCompletion] Check if stdlib decls exist
2 parents bea5b52 + a8ae8e4 commit e7c92f7

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

lib/IDE/CompletionLookup.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ static Type defaultTypeLiteralKind(CodeCompletionLiteralKind kind,
8383
case CodeCompletionLiteralKind::StringLiteral:
8484
return Ctx.getStringType();
8585
case CodeCompletionLiteralKind::ArrayLiteral:
86+
if (!Ctx.getArrayDecl())
87+
return Type();
8688
return Ctx.getArrayDecl()->getDeclaredType();
8789
case CodeCompletionLiteralKind::DictionaryLiteral:
90+
if (!Ctx.getDictionaryDecl())
91+
return Type();
8892
return Ctx.getDictionaryDecl()->getDeclaredType();
8993
case CodeCompletionLiteralKind::NilLiteral:
9094
case CodeCompletionLiteralKind::ColorLiteral:

test/IDE/complete_embedded.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// REQUIRES: asserts
2+
// REQUIRES: swift_in_compiler
3+
// RUN: %batch-code-completion -enable-experimental-feature Embedded
4+
5+
func test() {
6+
#^GLOBAL^#
7+
// GLOBAL: Literal[Integer]/None: 0[#Int#];
8+
// GLOBAL: Literal[Boolean]/None: true[#Bool#];
9+
// GLOBAL: Literal[Boolean]/None: false[#Bool#];
10+
// GLOBAL: Literal[Nil]/None: nil;
11+
// GLOBAL: Literal[String]/None: "{#(abc)#}"[#String#];
12+
// GLOBAL: Literal[Array]/None: [{#(values)#}][#Array#];
13+
// GLOBAL: Literal[Dictionary]/None: [{#(key)#}: {#(value)#}];
14+
}

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4359,6 +4359,20 @@ int main(int argc, char *argv[]) {
43594359
for (auto &File : options::InputFilenames)
43604360
InitInvok.getFrontendOptions().InputsAndOutputs.addInputFile(File);
43614361

4362+
for (const auto &featureArg : options::EnableExperimentalFeatures) {
4363+
if (auto feature = getExperimentalFeature(featureArg)) {
4364+
InitInvok.getLangOptions().Features.insert(*feature);
4365+
}
4366+
}
4367+
4368+
for (const auto &featureArg : options::EnableUpcomingFeatures) {
4369+
if (auto feature = getUpcomingFeature(featureArg)) {
4370+
InitInvok.getLangOptions().Features.insert(*feature);
4371+
}
4372+
}
4373+
4374+
// NOTE: 'setMainExecutablePath' must be after 'Features' because
4375+
// 'setRuntimeResourcePath()' called from here depends on 'Features'.
43624376
InitInvok.setMainExecutablePath(mainExecutablePath);
43634377
InitInvok.setModuleName(options::ModuleName);
43644378

@@ -4428,18 +4442,6 @@ int main(int argc, char *argv[]) {
44284442
InitInvok.getLangOptions().EnableExperimentalStringProcessing = true;
44294443
}
44304444

4431-
for (const auto &featureArg : options::EnableExperimentalFeatures) {
4432-
if (auto feature = getExperimentalFeature(featureArg)) {
4433-
InitInvok.getLangOptions().Features.insert(*feature);
4434-
}
4435-
}
4436-
4437-
for (const auto &featureArg : options::EnableUpcomingFeatures) {
4438-
if (auto feature = getUpcomingFeature(featureArg)) {
4439-
InitInvok.getLangOptions().Features.insert(*feature);
4440-
}
4441-
}
4442-
44434445
if (!options::Triple.empty())
44444446
InitInvok.setTargetTriple(options::Triple);
44454447
if (!options::SwiftVersion.empty()) {

0 commit comments

Comments
 (0)