Skip to content

[SourceKit] Force print '!' for optional method call in code completion. #16910

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 1 commit into from
May 31, 2018
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
1 change: 1 addition & 0 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ void CodeCompletionString::getName(raw_ostream &OS) const {
case ChunkKind::TypeAnnotation:
case ChunkKind::CallParameterClosureType:
case ChunkKind::DeclAttrParamColon:
case ChunkKind::OptionalMethodCallTail:
continue;
case ChunkKind::ThrowsKeyword:
case ChunkKind::RethrowsKeyword:
Expand Down
3 changes: 1 addition & 2 deletions lib/IDE/CodeCompletionResultBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,7 @@ class CodeCompletionResultBuilder {

void addOptionalMethodCallTail() {
addChunkWithTextNoCopy(
CodeCompletionString::Chunk::ChunkKind::OptionalMethodCallTail, "!");
getLastChunk().setIsAnnotation();
CodeCompletionString::Chunk::ChunkKind::OptionalMethodCallTail, "?");
}

void addTypeAnnotation(StringRef Type) {
Expand Down
6 changes: 3 additions & 3 deletions test/IDE/complete_members_optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func optionalMembers1(_ a: HasOptionalMembers1) {
a.#^OPTIONAL_MEMBERS_1^#
}
// OPTIONAL_MEMBERS_1: Begin completions, 3 items
// OPTIONAL_MEMBERS_1-DAG: Decl[InstanceMethod]/CurrNominal: optionalInstanceFunc!()[#Int#]{{; name=.+$}}
// OPTIONAL_MEMBERS_1-DAG: Decl[InstanceMethod]/CurrNominal: optionalInstanceFunc?()[#Int#]{{; name=.+$}}
// OPTIONAL_MEMBERS_1-DAG: Decl[InstanceVar]/CurrNominal: optionalInstanceProperty[#Int?#]{{; name=.+$}}
// OPTIONAL_MEMBERS_1-DAG: Keyword[self]/CurrNominal: self[#HasOptionalMembers1#]; name=self
// OPTIONAL_MEMBERS_1: End completions
Expand All @@ -38,8 +38,8 @@ func optionalMembers2<T : HasOptionalMembers1>(_ a: T) {
T.#^OPTIONAL_MEMBERS_2^#
}
// OPTIONAL_MEMBERS_2: Begin completions, 4 items
// OPTIONAL_MEMBERS_2-DAG: Decl[InstanceMethod]/Super: optionalInstanceFunc!({#self: HasOptionalMembers1#})[#() -> Int#]{{; name=.+$}}
// OPTIONAL_MEMBERS_2-DAG: Decl[StaticMethod]/Super: optionalClassFunc!()[#Int#]{{; name=.+$}}
// OPTIONAL_MEMBERS_2-DAG: Decl[InstanceMethod]/Super: optionalInstanceFunc?({#self: HasOptionalMembers1#})[#() -> Int#]{{; name=.+$}}
// OPTIONAL_MEMBERS_2-DAG: Decl[StaticMethod]/Super: optionalClassFunc?()[#Int#]{{; name=.+$}}
// OPTIONAL_MEMBERS_2-DAG: Decl[StaticVar]/Super: optionalClassProperty[#Int?#]{{; name=.+$}}
// OPTIONAL_MEMBERS_2-DAG: Keyword[self]/CurrNominal: self[#T.Type#]; name=self
// OPTIONAL_MEMBERS_2: End completions
11 changes: 11 additions & 0 deletions test/SourceKit/CodeComplete/complete_optionalmethod.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@objc protocol Proto {
@objc optional func optionalMethod() -> Int
}

func test<T : Proto>(obj: T) {
let _ = obj.
}

// RUN: %sourcekitd-test -req=complete -pos=6:15 %s -- %s > %t.response
// RUN: diff -u %s.response %t.response
// REQUIRES: objc_interop
24 changes: 24 additions & 0 deletions test/SourceKit/CodeComplete/complete_optionalmethod.swift.response
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
key.results: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "optionalMethod()",
key.sourcetext: "optionalMethod?()",
key.description: "optionalMethod?()",
key.typename: "Int",
key.context: source.codecompletion.context.superclass,
key.num_bytes_to_erase: 0,
key.associated_usrs: "c:@M@complete_optionalmethod@objc(pl)Proto(im)optionalMethod",
key.modulename: "complete_optionalmethod"
},
{
key.kind: source.lang.swift.keyword,
key.name: "self",
key.sourcetext: "self",
key.description: "self",
key.typename: "T",
key.context: source.codecompletion.context.thisclass,
key.num_bytes_to_erase: 0
}
]
}
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ void CompletionBuilder::getFilterName(CodeCompletionString *str,
case ChunkKind::Whitespace:
case ChunkKind::Ellipsis:
case ChunkKind::Ampersand:
case ChunkKind::OptionalMethodCallTail:
continue;
case ChunkKind::CallParameterColon:
// Since we don't add the type, also don't add the space after ':'.
Expand Down