mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Add a field NotRecommendedReason to code completion result to indicate why an item is not recommended, NFC. rdar://25415947
As implied in rdar://24818863, striking through a module name may be an overkill to suggest the module is redundant to import. We try to fine-grain not-recommended-reason so that proper UI cue can be adopted in the future.
This commit is contained in:
@@ -899,12 +899,14 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
|
||||
typeRelation =
|
||||
calculateMaxTypeRelationForDecl(AssociatedDecl, ExpectedDeclTypes);
|
||||
|
||||
if (typeRelation == CodeCompletionResult::Invalid)
|
||||
if (typeRelation == CodeCompletionResult::Invalid) {
|
||||
IsNotRecommended = true;
|
||||
NotRecReason = CodeCompletionResult::NotRecommendedReason::TypeMismatch;
|
||||
}
|
||||
|
||||
return new (*Sink.Allocator) CodeCompletionResult(
|
||||
SemanticContext, NumBytesToErase, CCS, AssociatedDecl, ModuleName,
|
||||
/*NotRecommended=*/IsNotRecommended,
|
||||
/*NotRecommended=*/IsNotRecommended, NotRecReason,
|
||||
copyString(*Sink.Allocator, BriefComment),
|
||||
copyAssociatedUSRs(*Sink.Allocator, AssociatedDecl),
|
||||
copyStringPairArray(*Sink.Allocator, CommentWords), typeRelation);
|
||||
@@ -1603,7 +1605,9 @@ public:
|
||||
Builder.setAssociatedDecl(MD);
|
||||
Builder.addTextChunk(MD->getNameStr());
|
||||
Builder.addTypeAnnotation("Module");
|
||||
Builder.setNotRecommended(Pair.second);
|
||||
if (Pair.second)
|
||||
Builder.setNotRecommended(CodeCompletionResult::NotRecommendedReason::
|
||||
Redundant);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1654,7 +1658,9 @@ public:
|
||||
Builder.addTypeAnnotation("Module");
|
||||
|
||||
// Imported modules are not recommended.
|
||||
Builder.setNotRecommended(ImportedModules.count(MD->getNameStr()) != 0);
|
||||
if (ImportedModules.count(MD->getNameStr()) != 0)
|
||||
Builder.setNotRecommended(CodeCompletionResult::NotRecommendedReason::
|
||||
Redundant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user