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:
@@ -492,23 +492,28 @@ bool SwiftToSourceKitCompletionAdapter::handleResult(
|
||||
static UIdent CCCtxCurrentModule("source.codecompletion.context.thismodule");
|
||||
static UIdent CCCtxOtherModule("source.codecompletion.context.othermodule");
|
||||
|
||||
switch (Result->getSemanticContext()) {
|
||||
case SemanticContextKind::None:
|
||||
Info.SemanticContext = CCCtxNone; break;
|
||||
case SemanticContextKind::ExpressionSpecific:
|
||||
Info.SemanticContext = CCCtxExpressionSpecific; break;
|
||||
case SemanticContextKind::Local:
|
||||
Info.SemanticContext = CCCtxLocal; break;
|
||||
case SemanticContextKind::CurrentNominal:
|
||||
Info.SemanticContext = CCCtxCurrentNominal; break;
|
||||
case SemanticContextKind::Super:
|
||||
Info.SemanticContext = CCCtxSuper; break;
|
||||
case SemanticContextKind::OutsideNominal:
|
||||
Info.SemanticContext = CCCtxOutsideNominal; break;
|
||||
case SemanticContextKind::CurrentModule:
|
||||
Info.SemanticContext = CCCtxCurrentModule; break;
|
||||
case SemanticContextKind::OtherModule:
|
||||
Info.SemanticContext = CCCtxOtherModule; break;
|
||||
|
||||
if (Result->getFlair().contains(CodeCompletionFlairBit::ExpressionSpecific) ||
|
||||
Result->getFlair().contains(CodeCompletionFlairBit::SuperChain)) {
|
||||
// NOTE: `CCCtxExpressionSpecific` is to maintain compatibility.
|
||||
Info.SemanticContext = CCCtxExpressionSpecific;
|
||||
} else {
|
||||
switch (Result->getSemanticContext()) {
|
||||
case SemanticContextKind::None:
|
||||
Info.SemanticContext = CCCtxNone; break;
|
||||
case SemanticContextKind::Local:
|
||||
Info.SemanticContext = CCCtxLocal; break;
|
||||
case SemanticContextKind::CurrentNominal:
|
||||
Info.SemanticContext = CCCtxCurrentNominal; break;
|
||||
case SemanticContextKind::Super:
|
||||
Info.SemanticContext = CCCtxSuper; break;
|
||||
case SemanticContextKind::OutsideNominal:
|
||||
Info.SemanticContext = CCCtxOutsideNominal; break;
|
||||
case SemanticContextKind::CurrentModule:
|
||||
Info.SemanticContext = CCCtxCurrentModule; break;
|
||||
case SemanticContextKind::OtherModule:
|
||||
Info.SemanticContext = CCCtxOtherModule; break;
|
||||
}
|
||||
}
|
||||
|
||||
static UIdent CCTypeRelNotApplicable("source.codecompletion.typerelation.notapplicable");
|
||||
@@ -914,14 +919,16 @@ static void transformAndForwardResults(
|
||||
CodeCompletionString::create(innerSink.allocator, chunks);
|
||||
CodeCompletion::SwiftResult paren(
|
||||
CodeCompletion::SwiftResult::ResultKind::BuiltinOperator,
|
||||
SemanticContextKind::ExpressionSpecific, /*IsArgumentLabels=*/false,
|
||||
SemanticContextKind::CurrentNominal,
|
||||
CodeCompletionFlairBit::ExpressionSpecific,
|
||||
/*IsArgumentLabels=*/false,
|
||||
exactMatch ? exactMatch->getNumBytesToErase() : 0, completionString,
|
||||
CodeCompletionResult::ExpectedTypeRelation::NotApplicable);
|
||||
|
||||
SwiftCompletionInfo info;
|
||||
std::vector<Completion *> extended =
|
||||
extendCompletions(&paren, innerSink, info, nameToPopularity, options,
|
||||
exactMatch, SemanticContextKind::ExpressionSpecific);
|
||||
exactMatch);
|
||||
assert(extended.size() == 1);
|
||||
return extended.front();
|
||||
};
|
||||
@@ -1002,11 +1009,11 @@ static void transformAndForwardResults(
|
||||
auto topResults = filterInnerResults(results, options.addInnerResults,
|
||||
options.addInnerOperators, hasDot,
|
||||
hasQDot, hasInit, rules);
|
||||
// FIXME: Overriding the default to context "None" is a hack so that they
|
||||
// won't overwhelm other results that also match the filter text.
|
||||
// FIXME: Clearing the flair (and semantic context) is a hack so that
|
||||
// they won't overwhelm other results that also match the filter text.
|
||||
innerResults = extendCompletions(
|
||||
topResults, innerSink, info, nameToPopularity, options, exactMatch,
|
||||
SemanticContextKind::None, SemanticContextKind::None);
|
||||
/*clearFlair=*/true);
|
||||
});
|
||||
|
||||
auto *inputBuf = session->getBuffer();
|
||||
|
||||
Reference in New Issue
Block a user