diff --git a/include/swift/IDE/CodeCompletion.h b/include/swift/IDE/CodeCompletion.h index 186add43a42..3515e6b74d4 100644 --- a/include/swift/IDE/CodeCompletion.h +++ b/include/swift/IDE/CodeCompletion.h @@ -527,6 +527,8 @@ public: /// Describes the relationship between the type of the completion results and /// the expected type at the code completion position. enum ExpectedTypeRelation { + /// The result does not have a type (e.g. keyword). + NotApplicable, /// The relationship of the result's type to the expected type is not /// invalid, not convertible, and not identical. diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index c1b1e4c0d32..a99164714bc 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -4308,6 +4308,8 @@ public: CodeCompletionResultBuilder Builder( Sink, CodeCompletionResult::ResultKind::Declaration, SemanticContextKind::Super, {}); + Builder.setExpectedTypeRelation( + CodeCompletionResult::ExpectedTypeRelation::NotApplicable); Builder.setAssociatedDecl(FD); addValueOverride(FD, Reason, dynamicLookupInfo, Builder, hasFuncIntroducer); Builder.addBraceStmtWithCursor(); @@ -4335,6 +4337,8 @@ public: CodeCompletionResultBuilder Builder( Sink, CodeCompletionResult::ResultKind::Declaration, SemanticContextKind::Super, {}); + Builder.setExpectedTypeRelation( + CodeCompletionResult::ExpectedTypeRelation::NotApplicable); Builder.setAssociatedDecl(SD); addValueOverride(SD, Reason, dynamicLookupInfo, Builder, false); Builder.addBraceStmtWithCursor(); @@ -4345,6 +4349,8 @@ public: CodeCompletionResultBuilder Builder(Sink, CodeCompletionResult::ResultKind::Declaration, SemanticContextKind::Super, {}); + Builder.setExpectedTypeRelation( + CodeCompletionResult::ExpectedTypeRelation::NotApplicable); Builder.setAssociatedDecl(ATD); if (!hasTypealiasIntroducer && !hasAccessModifier) addAccessControl(ATD, Builder); @@ -4361,6 +4367,8 @@ public: Sink, CodeCompletionResult::ResultKind::Declaration, SemanticContextKind::Super, {}); + Builder.setExpectedTypeRelation( + CodeCompletionResult::ExpectedTypeRelation::NotApplicable); Builder.setAssociatedDecl(CD); if (!hasAccessModifier) @@ -4845,16 +4853,19 @@ static bool isClangSubModule(ModuleDecl *TheModule) { return false; } -static void addKeyword(CodeCompletionResultSink &Sink, StringRef Name, - CodeCompletionKeywordKind Kind, - StringRef TypeAnnotation = "") { - CodeCompletionResultBuilder Builder( - Sink, CodeCompletionResult::ResultKind::Keyword, - SemanticContextKind::None, {}); - Builder.setKeywordKind(Kind); - Builder.addTextChunk(Name); - if (!TypeAnnotation.empty()) - Builder.addTypeAnnotation(TypeAnnotation); +static void +addKeyword(CodeCompletionResultSink &Sink, StringRef Name, + CodeCompletionKeywordKind Kind, StringRef TypeAnnotation = "", + CodeCompletionResult::ExpectedTypeRelation TypeRelation = + CodeCompletionResult::ExpectedTypeRelation::NotApplicable) { + CodeCompletionResultBuilder Builder(Sink, + CodeCompletionResult::ResultKind::Keyword, + SemanticContextKind::None, {}); + Builder.setKeywordKind(Kind); + Builder.addTextChunk(Name); + if (!TypeAnnotation.empty()) + Builder.addTypeAnnotation(TypeAnnotation); + Builder.setExpectedTypeRelation(TypeRelation); } static void addDeclKeywords(CodeCompletionResultSink &Sink) { diff --git a/test/SourceKit/CodeComplete/complete_override.swift.response b/test/SourceKit/CodeComplete/complete_override.swift.response index d25002ef739..e1dd6fbdff8 100644 --- a/test/SourceKit/CodeComplete/complete_override.swift.response +++ b/test/SourceKit/CodeComplete/complete_override.swift.response @@ -7,7 +7,7 @@ key.description: "associatedtype", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -17,7 +17,7 @@ key.description: "class", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -27,7 +27,7 @@ key.description: "convenience", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -37,7 +37,7 @@ key.description: "deinit", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -47,7 +47,7 @@ key.description: "dynamic", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -57,7 +57,7 @@ key.description: "enum", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -67,7 +67,7 @@ key.description: "extension", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -77,7 +77,7 @@ key.description: "f(getMe a: Int, b: Double)", key.typename: "", key.context: source.codecompletion.context.superclass, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0, key.associated_usrs: "s:17complete_override4BaseC1f5getMe1bySi_SdtF", key.modulename: "complete_override" @@ -89,7 +89,7 @@ key.description: "fileprivate", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -99,7 +99,7 @@ key.description: "final", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -109,7 +109,7 @@ key.description: "func", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -119,7 +119,7 @@ key.description: "import", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -129,7 +129,7 @@ key.description: "indirect", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -139,7 +139,7 @@ key.description: "infix", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -149,7 +149,7 @@ key.description: "init", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -159,7 +159,7 @@ key.description: "init()", key.typename: "", key.context: source.codecompletion.context.superclass, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0, key.associated_usrs: "s:17complete_override4BaseCACycfc", key.modulename: "complete_override" @@ -171,7 +171,7 @@ key.description: "inout", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -181,7 +181,7 @@ key.description: "internal", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -191,7 +191,7 @@ key.description: "lazy", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -201,7 +201,7 @@ key.description: "let", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -211,7 +211,7 @@ key.description: "mutating", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -221,7 +221,7 @@ key.description: "nonmutating", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -231,7 +231,7 @@ key.description: "open", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -241,7 +241,7 @@ key.description: "operator", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -251,7 +251,7 @@ key.description: "optional", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -261,7 +261,7 @@ key.description: "override", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -271,7 +271,7 @@ key.description: "postfix", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -281,7 +281,7 @@ key.description: "precedencegroup", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -291,7 +291,7 @@ key.description: "prefix", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -301,7 +301,7 @@ key.description: "private", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -311,7 +311,7 @@ key.description: "protocol", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -321,7 +321,7 @@ key.description: "public", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -331,7 +331,7 @@ key.description: "required", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -341,7 +341,7 @@ key.description: "static", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -351,7 +351,7 @@ key.description: "struct", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -361,7 +361,7 @@ key.description: "subscript", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -371,7 +371,7 @@ key.description: "typealias", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -381,7 +381,7 @@ key.description: "unowned", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -391,7 +391,7 @@ key.description: "var", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 }, { @@ -401,7 +401,7 @@ key.description: "weak", key.typename: "", key.context: source.codecompletion.context.none, - key.typerelation: source.codecompletion.typerelation.unrelated, + key.typerelation: source.codecompletion.typerelation.notapplicable, key.num_bytes_to_erase: 0 } ] diff --git a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp index 9d070b0620d..88ff9ade008 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp @@ -502,12 +502,15 @@ bool SwiftToSourceKitCompletionAdapter::handleResult( Info.SemanticContext = CCCtxOtherModule; break; } + static UIdent CCTypeRelNotApplicable("source.codecompletion.typerelation.notapplicable"); static UIdent CCTypeRelUnrelated("source.codecompletion.typerelation.unrelated"); static UIdent CCTypeRelInvalid("source.codecompletion.typerelation.invalid"); static UIdent CCTypeRelConvertible("source.codecompletion.typerelation.convertible"); static UIdent CCTypeRelIdentical("source.codecompletion.typerelation.identical"); switch (Result->getExpectedTypeRelation()) { + case CodeCompletionResult::NotApplicable: + Info.TypeRelation = CCTypeRelNotApplicable; break; case CodeCompletionResult::Unrelated: Info.TypeRelation = CCTypeRelUnrelated; break; case CodeCompletionResult::Invalid: