Skip to content

Commit

Permalink
[CodeCompletion] Add _ColorLiteralConvertible completion
Browse files Browse the repository at this point in the history
For rdar://problem/21923069

Swift SVN r32891
  • Loading branch information
benlangmuir committed Oct 26, 2015
1 parent 7fda896 commit 880ef5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,26 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
builder.addRightBracket();
});

auto floatType = context.getFloatDecl()->getDeclaredType();
addFromProto(KPK::_ColorLiteralConvertible, "", [&](Builder &builder) {
builder.addLeftBracket();
builder.addTextChunk("#Color");
builder.addLeftParen();
builder.addCallParameter(context.getIdentifier("colorLiteralRed"),
floatType, false);
builder.addComma();
builder.addCallParameter(context.getIdentifier("green"), floatType,
false);
builder.addComma();
builder.addCallParameter(context.getIdentifier("blue"), floatType, false);
builder.addComma();
builder.addCallParameter(context.getIdentifier("alpha"), floatType,
false);
builder.addRightParen();
builder.addTextChunk("#");
builder.addRightBracket();
});

// Add tuple completion (item, item).
{
CodeCompletionResultBuilder builder(Sink, CodeCompletionResult::Pattern,
Expand Down
15 changes: 15 additions & 0 deletions test/IDE/complete_value_literals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=TUPLE_0 | FileCheck %s -check-prefix=TUPLE_0
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=TUPLE_1 | FileCheck %s -check-prefix=TUPLE_1
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=TUPLE_2 | FileCheck %s -check-prefix=TUPLE_2
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=COLOR_0 | FileCheck %s -check-prefix=COLOR_0
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=COLOR_1 | FileCheck %s -check-prefix=COLOR_1

struct MyNil1: NilLiteralConvertible {
init(nilLiteral: ()) {}
Expand Down Expand Up @@ -175,3 +177,16 @@ func testTuple2() {
}
// FIXME: should we extend the tuple to have the right number of elements?
// TUPLE_2: Pattern/None/TypeRelation[Identical]: ({#item#}, {#item#})[#(MyInt1, MyString1, MyDouble1)#];

struct MyColor1: _ColorLiteralConvertible {
init(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {}
}
func testColor0() {
let x: Int = #^COLOR_0^#
}
// COLOR_0: Pattern/None: [#Color({#colorLiteralRed: Float#}, {#green: Float#}, {#blue: Float#}, {#alpha: Float#})#];

func testColor1() {
let x: MyColor1 = #^COLOR_1^#
}
// COLOR_1: Pattern/None/TypeRelation[Identical]: [#Color({#colorLiteralRed: Float#}, {#green: Float#}, {#blue: Float#}, {#alpha: Float#})#][#MyColor1#];

0 comments on commit 880ef5e

Please sign in to comment.