mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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:
@@ -16,6 +16,7 @@
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/Basic/Debug.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Basic/OptionSet.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
@@ -375,33 +376,6 @@ enum class SemanticContextKind {
|
||||
/// Used in cases when the concept of semantic context is not applicable.
|
||||
None,
|
||||
|
||||
/// This is a highly-likely expression-context-specific completion
|
||||
/// result. This description is intentionally vague: this is a catch-all
|
||||
/// category for all heuristics for highly-likely results.
|
||||
///
|
||||
/// For example, the name of an overridden superclass member inside a nominal
|
||||
/// member function has ExpressionSpecific context:
|
||||
/// \code
|
||||
/// class Base {
|
||||
/// init() {}
|
||||
/// init(a: Int) {}
|
||||
/// func foo() {}
|
||||
/// func bar() {}
|
||||
/// }
|
||||
/// class Derived {
|
||||
/// init() {
|
||||
/// super. // init() -- ExpressionSpecific
|
||||
/// // init(a: Int) -- Super
|
||||
/// }
|
||||
///
|
||||
/// func foo() {
|
||||
/// super. // foo() -- ExpressionSpecific
|
||||
/// // bar() -- Super
|
||||
/// }
|
||||
/// }
|
||||
/// \endcode
|
||||
ExpressionSpecific,
|
||||
|
||||
/// A declaration from the same function.
|
||||
Local,
|
||||
|
||||
@@ -434,6 +408,16 @@ enum class SemanticContextKind {
|
||||
OtherModule,
|
||||
};
|
||||
|
||||
enum class CodeCompletionFlairBit: uint8_t {
|
||||
/// **Deprecated**. Old style catch-all prioritization.
|
||||
ExpressionSpecific = 1 << 0,
|
||||
|
||||
/// E.g. override func foo() { super.foo() ...
|
||||
SuperChain = 1 << 1,
|
||||
};
|
||||
|
||||
using CodeCompletionFlair = OptionSet<CodeCompletionFlairBit>;
|
||||
|
||||
/// The declaration kind of a code completion result, if it is a declaration.
|
||||
enum class CodeCompletionDeclKind {
|
||||
Module,
|
||||
@@ -615,6 +599,7 @@ private:
|
||||
unsigned AssociatedKind : 8;
|
||||
unsigned KnownOperatorKind : 6;
|
||||
unsigned SemanticContext : 3;
|
||||
unsigned Flair: 8;
|
||||
unsigned IsArgumentLabels : 1;
|
||||
unsigned NotRecommended : 4;
|
||||
unsigned IsSystem : 1;
|
||||
@@ -640,6 +625,7 @@ public:
|
||||
///
|
||||
/// \note The caller must ensure \c CodeCompletionString outlives this result.
|
||||
CodeCompletionResult(ResultKind Kind, SemanticContextKind SemanticContext,
|
||||
CodeCompletionFlair Flair,
|
||||
bool IsArgumentLabels, unsigned NumBytesToErase,
|
||||
CodeCompletionString *CompletionString,
|
||||
ExpectedTypeRelation TypeDistance,
|
||||
@@ -647,7 +633,7 @@ public:
|
||||
CodeCompletionOperatorKind::None,
|
||||
StringRef BriefDocComment = StringRef())
|
||||
: Kind(Kind), KnownOperatorKind(unsigned(KnownOperatorKind)),
|
||||
SemanticContext(unsigned(SemanticContext)),
|
||||
SemanticContext(unsigned(SemanticContext)), Flair(unsigned(Flair.toRaw())),
|
||||
IsArgumentLabels(unsigned(IsArgumentLabels)),
|
||||
NotRecommended(unsigned(NotRecommendedReason::None)),
|
||||
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
|
||||
@@ -668,12 +654,13 @@ public:
|
||||
/// \note The caller must ensure \c CodeCompletionString outlives this result.
|
||||
CodeCompletionResult(CodeCompletionKeywordKind Kind,
|
||||
SemanticContextKind SemanticContext,
|
||||
CodeCompletionFlair Flair,
|
||||
bool IsArgumentLabels, unsigned NumBytesToErase,
|
||||
CodeCompletionString *CompletionString,
|
||||
ExpectedTypeRelation TypeDistance,
|
||||
StringRef BriefDocComment = StringRef())
|
||||
: Kind(Keyword), KnownOperatorKind(0),
|
||||
SemanticContext(unsigned(SemanticContext)),
|
||||
SemanticContext(unsigned(SemanticContext)), Flair(unsigned(Flair.toRaw())),
|
||||
IsArgumentLabels(unsigned(IsArgumentLabels)),
|
||||
NotRecommended(unsigned(NotRecommendedReason::None)),
|
||||
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
|
||||
@@ -688,11 +675,12 @@ public:
|
||||
/// \note The caller must ensure \c CodeCompletionString outlives this result.
|
||||
CodeCompletionResult(CodeCompletionLiteralKind LiteralKind,
|
||||
SemanticContextKind SemanticContext,
|
||||
CodeCompletionFlair Flair,
|
||||
bool IsArgumentLabels, unsigned NumBytesToErase,
|
||||
CodeCompletionString *CompletionString,
|
||||
ExpectedTypeRelation TypeDistance)
|
||||
: Kind(Literal), KnownOperatorKind(0),
|
||||
SemanticContext(unsigned(SemanticContext)),
|
||||
SemanticContext(unsigned(SemanticContext)), Flair(unsigned(Flair.toRaw())),
|
||||
IsArgumentLabels(unsigned(IsArgumentLabels)),
|
||||
NotRecommended(unsigned(NotRecommendedReason::None)),
|
||||
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
|
||||
@@ -708,6 +696,7 @@ public:
|
||||
/// arguments outlive this result, typically by storing them in the same
|
||||
/// \c CodeCompletionResultSink as the result itself.
|
||||
CodeCompletionResult(SemanticContextKind SemanticContext,
|
||||
CodeCompletionFlair Flair,
|
||||
bool IsArgumentLabels, unsigned NumBytesToErase,
|
||||
CodeCompletionString *CompletionString,
|
||||
const Decl *AssociatedDecl, StringRef ModuleName,
|
||||
@@ -717,7 +706,7 @@ public:
|
||||
ArrayRef<std::pair<StringRef, StringRef>> DocWords,
|
||||
enum ExpectedTypeRelation TypeDistance)
|
||||
: Kind(ResultKind::Declaration), KnownOperatorKind(0),
|
||||
SemanticContext(unsigned(SemanticContext)),
|
||||
SemanticContext(unsigned(SemanticContext)), Flair(unsigned(Flair.toRaw())),
|
||||
IsArgumentLabels(unsigned(IsArgumentLabels)),
|
||||
NotRecommended(unsigned(NotRecReason)),
|
||||
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
|
||||
@@ -737,6 +726,7 @@ public:
|
||||
|
||||
// Used by deserialization.
|
||||
CodeCompletionResult(SemanticContextKind SemanticContext,
|
||||
CodeCompletionFlair Flair,
|
||||
bool IsArgumentLabels, unsigned NumBytesToErase,
|
||||
CodeCompletionString *CompletionString,
|
||||
CodeCompletionDeclKind DeclKind, bool IsSystem,
|
||||
@@ -749,7 +739,7 @@ public:
|
||||
CodeCompletionOperatorKind KnownOperatorKind)
|
||||
: Kind(ResultKind::Declaration),
|
||||
KnownOperatorKind(unsigned(KnownOperatorKind)),
|
||||
SemanticContext(unsigned(SemanticContext)),
|
||||
SemanticContext(unsigned(SemanticContext)), Flair(unsigned(Flair.toRaw())),
|
||||
IsArgumentLabels(unsigned(IsArgumentLabels)),
|
||||
NotRecommended(unsigned(NotRecReason)), IsSystem(IsSystem),
|
||||
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
|
||||
@@ -813,6 +803,10 @@ public:
|
||||
return static_cast<SemanticContextKind>(SemanticContext);
|
||||
}
|
||||
|
||||
CodeCompletionFlair getFlair() const {
|
||||
return static_cast<CodeCompletionFlair>(Flair);
|
||||
}
|
||||
|
||||
bool isArgumentLabels() const {
|
||||
return static_cast<bool>(IsArgumentLabels);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user