@@ -100,9 +100,24 @@ std::vector<Completion *> SourceKit::CodeCompletion::extendCompletions(
100
100
std::vector<Completion *> results;
101
101
for (auto *result : swiftResults) {
102
102
CompletionBuilder builder (sink, *result);
103
- if (result->getSemanticContext () == SemanticContextKind::OtherModule)
103
+ if (result->getSemanticContext () == SemanticContextKind::OtherModule) {
104
104
builder.setModuleImportDepth (depth.lookup (result->getModuleName ()));
105
105
106
+ if (info.completionContext ->HasExpectedTypeRelation &&
107
+ result->getKind () == Completion::Declaration) {
108
+ // FIXME: because other-module results are cached, they will not be
109
+ // given a type-relation of invalid. As a hack, we look at the text of
110
+ // the result type and look for 'Void'.
111
+ for (auto &chunk : result->getCompletionString ()->getChunks ()) {
112
+ using ChunkKind = ide::CodeCompletionString::Chunk::ChunkKind;
113
+ if (chunk.is (ChunkKind::TypeAnnotation) && chunk.hasText () &&
114
+ chunk.getText () == " Void" ) {
115
+ builder.setNotRecommended (Completion::TypeMismatch);
116
+ }
117
+ }
118
+ }
119
+ }
120
+
106
121
if (prefix) {
107
122
builder.setPrefix (prefix->getCompletionString ());
108
123
builder.setSemanticContext (prefix->getSemanticContext ());
@@ -1116,6 +1131,8 @@ void CompletionBuilder::getDescription(SwiftResult *result, raw_ostream &OS,
1116
1131
1117
1132
CompletionBuilder::CompletionBuilder (CompletionSink &sink, SwiftResult &base)
1118
1133
: sink(sink), current(base) {
1134
+ isNotRecommended = current.isNotRecommended ();
1135
+ notRecommendedReason = current.getNotRecommendedReason ();
1119
1136
semanticContext = current.getSemanticContext ();
1120
1137
completionString =
1121
1138
const_cast <CodeCompletionString *>(current.getCompletionString ());
@@ -1158,8 +1175,8 @@ Completion *CompletionBuilder::finish() {
1158
1175
if (current.getKind () == SwiftResult::Declaration) {
1159
1176
base = SwiftResult (semanticContext, current.getNumBytesToErase (),
1160
1177
completionString, current.getAssociatedDeclKind (),
1161
- current.getModuleName (), current. isNotRecommended () ,
1162
- current. getNotRecommendedReason () ,
1178
+ current.getModuleName (), isNotRecommended,
1179
+ notRecommendedReason ,
1163
1180
current.getBriefDocComment (),
1164
1181
current.getAssociatedUSRs (),
1165
1182
current.getDeclKeywords ());
0 commit comments