mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CodeCompletion] Introduce "Flair" in code completion
To describe fine grained priorities. Introduce 'CodeCompletionFlair' that is a set of more descriptive flags for prioritizing completion items. This aims to replace ' SemanticContextKind::ExpressionSpecific' which was a "catch all" prioritization flag.
This commit is contained in:
@@ -72,9 +72,7 @@ struct CodeCompletion::Group : public Item {
|
||||
std::vector<Completion *> SourceKit::CodeCompletion::extendCompletions(
|
||||
ArrayRef<SwiftResult *> swiftResults, CompletionSink &sink,
|
||||
SwiftCompletionInfo &info, const NameToPopularityMap *nameToPopularity,
|
||||
const Options &options, Completion *prefix,
|
||||
Optional<SemanticContextKind> overrideContext,
|
||||
Optional<SemanticContextKind> overrideOperatorContext) {
|
||||
const Options &options, Completion *prefix, bool clearFlair) {
|
||||
|
||||
ImportDepth depth;
|
||||
if (info.swiftASTContext) {
|
||||
@@ -125,10 +123,9 @@ std::vector<Completion *> SourceKit::CodeCompletion::extendCompletions(
|
||||
builder.setSemanticContext(prefix->getSemanticContext());
|
||||
}
|
||||
|
||||
if (overrideOperatorContext && result->isOperator()) {
|
||||
builder.setSemanticContext(*overrideOperatorContext);
|
||||
} else if (overrideContext) {
|
||||
builder.setSemanticContext(*overrideContext);
|
||||
if (clearFlair) {
|
||||
builder.setFlair(CodeCompletionFlair());
|
||||
builder.setSemanticContext(SemanticContextKind::None);
|
||||
}
|
||||
|
||||
// If this result is not from the current module, try to get a popularity
|
||||
@@ -157,7 +154,7 @@ bool SourceKit::CodeCompletion::addCustomCompletions(
|
||||
CodeCompletionString::create(sink.allocator, chunk);
|
||||
CodeCompletion::SwiftResult swiftResult(
|
||||
CodeCompletion::SwiftResult::ResultKind::Pattern,
|
||||
SemanticContextKind::ExpressionSpecific,
|
||||
SemanticContextKind::Local, CodeCompletionFlairBit::ExpressionSpecific,
|
||||
/*IsArgumentLabels=*/false, /*NumBytesToErase=*/0, completionString,
|
||||
CodeCompletionResult::ExpectedTypeRelation::Unknown);
|
||||
|
||||
@@ -583,7 +580,6 @@ static double getSemanticContextScore(bool useImportDepth,
|
||||
Completion *completion) {
|
||||
double order = -1.0;
|
||||
switch (completion->getSemanticContext()) {
|
||||
case SemanticContextKind::ExpressionSpecific: order = 0; break;
|
||||
case SemanticContextKind::Local: order = 1; break;
|
||||
case SemanticContextKind::CurrentNominal: order = 2; break;
|
||||
case SemanticContextKind::Super: order = 3; break;
|
||||
@@ -661,10 +657,12 @@ static ResultBucket getResultBucket(Item &item, bool hasRequiredTypes,
|
||||
if (completion->isNotRecommended() && !skipMetaGroups)
|
||||
return ResultBucket::NotRecommended;
|
||||
|
||||
if (completion->getSemanticContext() ==
|
||||
SemanticContextKind::ExpressionSpecific &&
|
||||
!skipMetaGroups)
|
||||
return ResultBucket::ExpressionSpecific;
|
||||
if (!skipMetaGroups) {
|
||||
auto flair = completion->getFlair();
|
||||
if (flair.contains(CodeCompletionFlairBit::ExpressionSpecific) ||
|
||||
flair.contains(CodeCompletionFlairBit::SuperChain))
|
||||
return ResultBucket::ExpressionSpecific;
|
||||
}
|
||||
|
||||
if (completion->isArgumentLabels() && !skipMetaGroups)
|
||||
return ResultBucket::ExpressionSpecific;
|
||||
@@ -1126,6 +1124,7 @@ CompletionBuilder::CompletionBuilder(CompletionSink &sink, SwiftResult &base)
|
||||
: sink(sink), current(base) {
|
||||
typeRelation = current.getExpectedTypeRelation();
|
||||
semanticContext = current.getSemanticContext();
|
||||
flair = current.getFlair();
|
||||
completionString =
|
||||
const_cast<CodeCompletionString *>(current.getCompletionString());
|
||||
|
||||
@@ -1170,14 +1169,14 @@ Completion *CompletionBuilder::finish() {
|
||||
|
||||
if (current.getKind() == SwiftResult::Declaration) {
|
||||
base = SwiftResult(
|
||||
semanticContext, current.isArgumentLabels(),
|
||||
semanticContext, flair, current.isArgumentLabels(),
|
||||
current.getNumBytesToErase(), completionString,
|
||||
current.getAssociatedDeclKind(), current.isSystem(),
|
||||
current.getModuleName(), current.getNotRecommendedReason(),
|
||||
current.getBriefDocComment(), current.getAssociatedUSRs(),
|
||||
current.getDeclKeywords(), typeRelation, opKind);
|
||||
} else {
|
||||
base = SwiftResult(current.getKind(), semanticContext,
|
||||
base = SwiftResult(current.getKind(), semanticContext, flair,
|
||||
current.isArgumentLabels(),
|
||||
current.getNumBytesToErase(), completionString,
|
||||
typeRelation, opKind);
|
||||
|
||||
Reference in New Issue
Block a user