mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Re-order literal suggestions
Move compound types (almost) to the end, put string just behind int and fix the order of true/false. Part of rdar://problem/23865118
This commit is contained in:
@@ -5,9 +5,9 @@
|
|||||||
// KEYWORDS-NOT: source.lang.swift.literal
|
// KEYWORDS-NOT: source.lang.swift.literal
|
||||||
// KEYWORDS: key.name: "nil"
|
// KEYWORDS: key.name: "nil"
|
||||||
// KEYWORDS-NOT: source.lang.swift.literal
|
// KEYWORDS-NOT: source.lang.swift.literal
|
||||||
// LITERALS: key.kind: source.lang.swift.literal.boolean
|
|
||||||
// LITERALS: key.kind: source.lang.swift.literal.string
|
// LITERALS: key.kind: source.lang.swift.literal.string
|
||||||
// LITERALS: key.sourcetext: "\"<#{{.*}}#>\""
|
// LITERALS: key.sourcetext: "\"<#{{.*}}#>\""
|
||||||
|
// LITERALS: key.kind: source.lang.swift.literal.boolean
|
||||||
// LITERALS: key.kind: source.lang.swift.literal.array
|
// LITERALS: key.kind: source.lang.swift.literal.array
|
||||||
// LITERALS: key.sourcetext: "[<#{{.*}}#>]"
|
// LITERALS: key.sourcetext: "[<#{{.*}}#>]"
|
||||||
// LITERALS: key.kind: source.lang.swift.literal.dictionary
|
// LITERALS: key.kind: source.lang.swift.literal.dictionary
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ func test2() {
|
|||||||
(#^EXPR_0^#)
|
(#^EXPR_0^#)
|
||||||
}
|
}
|
||||||
// EXPR: 0
|
// EXPR: 0
|
||||||
// EXPR: false
|
|
||||||
// EXPR: true
|
|
||||||
// EXPR: "abc"
|
// EXPR: "abc"
|
||||||
|
// EXPR: true
|
||||||
|
// EXPR: false
|
||||||
|
// EXPR: [#Color(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float)#]
|
||||||
|
// EXPR: [#Image(imageLiteral: String)#]
|
||||||
// EXPR: [values]
|
// EXPR: [values]
|
||||||
// EXPR: [key: value]
|
// EXPR: [key: value]
|
||||||
// EXPR: (values)
|
// EXPR: (values)
|
||||||
// EXPR: nil
|
// EXPR: nil
|
||||||
// EXPR: [#Color(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float)#]
|
|
||||||
// EXPR: [#Image(imageLiteral: String)#]
|
|
||||||
// EXPR: foo(a: Int)
|
// EXPR: foo(a: Int)
|
||||||
|
|||||||
@@ -691,14 +691,14 @@ static int compareHighPriorityKeywords(Item &a_, Item &b_) {
|
|||||||
static int compareLiterals(Item &a_, Item &b_) {
|
static int compareLiterals(Item &a_, Item &b_) {
|
||||||
static CodeCompletionLiteralKind order[] = {
|
static CodeCompletionLiteralKind order[] = {
|
||||||
CodeCompletionLiteralKind::IntegerLiteral,
|
CodeCompletionLiteralKind::IntegerLiteral,
|
||||||
CodeCompletionLiteralKind::BooleanLiteral,
|
|
||||||
CodeCompletionLiteralKind::StringLiteral,
|
CodeCompletionLiteralKind::StringLiteral,
|
||||||
|
CodeCompletionLiteralKind::BooleanLiteral,
|
||||||
|
CodeCompletionLiteralKind::ColorLiteral,
|
||||||
|
CodeCompletionLiteralKind::ImageLiteral,
|
||||||
CodeCompletionLiteralKind::ArrayLiteral,
|
CodeCompletionLiteralKind::ArrayLiteral,
|
||||||
CodeCompletionLiteralKind::DictionaryLiteral,
|
CodeCompletionLiteralKind::DictionaryLiteral,
|
||||||
CodeCompletionLiteralKind::Tuple,
|
CodeCompletionLiteralKind::Tuple,
|
||||||
CodeCompletionLiteralKind::NilLiteral,
|
CodeCompletionLiteralKind::NilLiteral,
|
||||||
CodeCompletionLiteralKind::ColorLiteral,
|
|
||||||
CodeCompletionLiteralKind::ImageLiteral,
|
|
||||||
};
|
};
|
||||||
auto size = sizeof(order) / sizeof(order[0]);
|
auto size = sizeof(order) / sizeof(order[0]);
|
||||||
|
|
||||||
@@ -710,7 +710,15 @@ static int compareLiterals(Item &a_, Item &b_) {
|
|||||||
|
|
||||||
auto a = getIndex(a_);
|
auto a = getIndex(a_);
|
||||||
auto b = getIndex(b_);
|
auto b = getIndex(b_);
|
||||||
return a < b ? -1 : (b < a ? 1 : 0);
|
|
||||||
|
if (a != b)
|
||||||
|
return a < b ? -1 : 1;
|
||||||
|
|
||||||
|
// Sort true before false instead of alphabetically.
|
||||||
|
if (cast<Result>(a_).value->getLiteralKind() == CodeCompletionLiteralKind::BooleanLiteral)
|
||||||
|
return a_.name > b_.name;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortRecursive(const Options &options, Group *group) {
|
static void sortRecursive(const Options &options, Group *group) {
|
||||||
|
|||||||
Reference in New Issue
Block a user