@@ -61,12 +61,12 @@ struct SwiftToSourceKitCompletionAdapter {
61
61
62
62
Completion extended (*result, name, description);
63
63
return handleResult (consumer, &extended, /* leadingPunctuation=*/ false ,
64
- /* includeLiterals =*/ false );
64
+ /* legacyLiteralToKeyword =*/ true );
65
65
}
66
66
67
67
static bool handleResult (SourceKit::CodeCompletionConsumer &consumer,
68
68
Completion *result, bool leadingPunctuation,
69
- bool includeLiterals );
69
+ bool legacyLiteralToKeyword );
70
70
71
71
static void getResultSourceText (const CodeCompletionString *CCStr,
72
72
raw_ostream &OS);
@@ -219,9 +219,29 @@ void SwiftLangSupport::codeComplete(llvm::MemoryBuffer *UnresolvedInputFile,
219
219
SourceKit::CodeCompletionConsumer &SKConsumer,
220
220
ArrayRef<const char *> Args) {
221
221
SwiftCodeCompletionConsumer SwiftConsumer ([&](
222
- MutableArrayRef<CodeCompletionResult *> Results, SwiftCompletionInfo &) {
222
+ MutableArrayRef<CodeCompletionResult *> Results,
223
+ SwiftCompletionInfo &info) {
224
+ bool hasExpectedType = info.completionContext ->HasExpectedTypeRelation ;
223
225
CodeCompletionContext::sortCompletionResults (Results);
226
+ // FIXME: this adhoc filtering should be configurable like it is in the
227
+ // codeCompleteOpen path.
224
228
for (auto *Result : Results) {
229
+ if (Result->getKind () == CodeCompletionResult::Literal) {
230
+ switch (Result->getLiteralKind ()) {
231
+ case CodeCompletionLiteralKind::NilLiteral:
232
+ case CodeCompletionLiteralKind::BooleanLiteral:
233
+ break ;
234
+ case CodeCompletionLiteralKind::ImageLiteral:
235
+ case CodeCompletionLiteralKind::ColorLiteral:
236
+ if (hasExpectedType &&
237
+ Result->getExpectedTypeRelation () <
238
+ CodeCompletionResult::Convertible)
239
+ continue ;
240
+ break ;
241
+ default :
242
+ continue ;
243
+ }
244
+ }
225
245
if (!SwiftToSourceKitCompletionAdapter::handleResult (SKConsumer, Result))
226
246
break ;
227
247
}
@@ -410,7 +430,7 @@ static UIdent KeywordFuncUID("source.lang.swift.keyword.func");
410
430
411
431
bool SwiftToSourceKitCompletionAdapter::handleResult (
412
432
SourceKit::CodeCompletionConsumer &Consumer, Completion *Result,
413
- bool leadingPunctuation, bool includeLiterals ) {
433
+ bool leadingPunctuation, bool legacyLiteralToKeyword ) {
414
434
415
435
static UIdent KeywordUID (" source.lang.swift.keyword" );
416
436
static UIdent PatternUID (" source.lang.swift.pattern" );
@@ -428,14 +448,14 @@ bool SwiftToSourceKitCompletionAdapter::handleResult(
428
448
Info.Kind = SwiftLangSupport::getUIDForCodeCompletionDeclKind (
429
449
Result->getAssociatedDeclKind ());
430
450
} else if (Result->getKind () == CodeCompletionResult::Literal) {
431
- if (includeLiterals) {
432
- Info.Kind = getUIDForCodeCompletionLiteralKind (Result->getLiteralKind ());
433
- } else if (Result->getLiteralKind () ==
434
- CodeCompletionLiteralKind::BooleanLiteral ||
435
- Result->getLiteralKind () ==
436
- CodeCompletionLiteralKind::NilLiteral) {
437
- // If we're not including literals, fallback to keywords as appropriate.
451
+ auto literalKind = Result->getLiteralKind ();
452
+ if (legacyLiteralToKeyword &&
453
+ (literalKind == CodeCompletionLiteralKind::BooleanLiteral ||
454
+ literalKind == CodeCompletionLiteralKind::NilLiteral)) {
455
+ // Fallback to keywords as appropriate.
438
456
Info.Kind = KeywordUID;
457
+ } else {
458
+ Info.Kind = getUIDForCodeCompletionLiteralKind (literalKind);
439
459
}
440
460
}
441
461
@@ -761,7 +781,7 @@ class SwiftGroupedCodeCompletionConsumer : public CodeCompletionView::Walker {
761
781
bool handleResult (Completion *result) override {
762
782
return SwiftToSourceKitCompletionAdapter::handleResult (
763
783
consumer, result, /* leadingPunctuation=*/ true ,
764
- /* includeLiterals =*/ true );
784
+ /* legacyLiteralToKeyword =*/ false );
765
785
}
766
786
void startGroup (StringRef name) override {
767
787
static UIdent GroupUID (" source.lang.swift.codecomplete.group" );
0 commit comments