Skip to content

[CodeCompletion] Check if stdlib decls exist #70704

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
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
4 changes: 4 additions & 0 deletions lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ static Type defaultTypeLiteralKind(CodeCompletionLiteralKind kind,
case CodeCompletionLiteralKind::StringLiteral:
return Ctx.getStringType();
case CodeCompletionLiteralKind::ArrayLiteral:
if (!Ctx.getArrayDecl())
return Type();
return Ctx.getArrayDecl()->getDeclaredType();
case CodeCompletionLiteralKind::DictionaryLiteral:
if (!Ctx.getDictionaryDecl())
return Type();
return Ctx.getDictionaryDecl()->getDeclaredType();
case CodeCompletionLiteralKind::NilLiteral:
case CodeCompletionLiteralKind::ColorLiteral:
Expand Down
14 changes: 14 additions & 0 deletions test/IDE/complete_embedded.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// REQUIRES: asserts
// REQUIRES: swift_in_compiler
// RUN: %batch-code-completion -enable-experimental-feature Embedded

func test() {
#^GLOBAL^#
// GLOBAL: Literal[Integer]/None: 0[#Int#];
// GLOBAL: Literal[Boolean]/None: true[#Bool#];
// GLOBAL: Literal[Boolean]/None: false[#Bool#];
// GLOBAL: Literal[Nil]/None: nil;
// GLOBAL: Literal[String]/None: "{#(abc)#}"[#String#];
// GLOBAL: Literal[Array]/None: [{#(values)#}][#Array#];
// GLOBAL: Literal[Dictionary]/None: [{#(key)#}: {#(value)#}];
}
26 changes: 14 additions & 12 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,20 @@ int main(int argc, char *argv[]) {
for (auto &File : options::InputFilenames)
InitInvok.getFrontendOptions().InputsAndOutputs.addInputFile(File);

for (const auto &featureArg : options::EnableExperimentalFeatures) {
if (auto feature = getExperimentalFeature(featureArg)) {
InitInvok.getLangOptions().Features.insert(*feature);
}
}

for (const auto &featureArg : options::EnableUpcomingFeatures) {
if (auto feature = getUpcomingFeature(featureArg)) {
InitInvok.getLangOptions().Features.insert(*feature);
}
}

// NOTE: 'setMainExecutablePath' must be after 'Features' because
// 'setRuntimeResourcePath()' called from here depends on 'Features'.
InitInvok.setMainExecutablePath(mainExecutablePath);
InitInvok.setModuleName(options::ModuleName);

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

for (const auto &featureArg : options::EnableExperimentalFeatures) {
if (auto feature = getExperimentalFeature(featureArg)) {
InitInvok.getLangOptions().Features.insert(*feature);
}
}

for (const auto &featureArg : options::EnableUpcomingFeatures) {
if (auto feature = getUpcomingFeature(featureArg)) {
InitInvok.getLangOptions().Features.insert(*feature);
}
}

if (!options::Triple.empty())
InitInvok.setTargetTriple(options::Triple);
if (!options::SwiftVersion.empty()) {
Expand Down