-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Add decl context dependent 'Flair' to decl keywords #37725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CodeCompletion] Add decl context dependent 'Flair' to decl keywords #37725
Conversation
7b37745
to
0cdee7b
Compare
@swift-ci Please smoke test |
@swift-ci Please smoke test macOS |
@@ -1540,6 +1542,12 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks { | |||
CodeCompletionResult::ResultKind::Keyword, | |||
SemanticContextKind::CurrentNominal, | |||
{}); | |||
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(CurDeclContext)) { | |||
if (AFD->getOverriddenDecl() != nullptr) { | |||
Builder.addFlair(CodeCompletionFlairBit::CommonKeywordAtCurrentPosition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
return false; | ||
} | ||
|
||
static bool isCompletionDeclContextLocalContext(DeclContext *DC) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably deserves a brief doc comment for why it's different from DC->isLocalContext()
. Also, why do we need both isCompletionDeclContextLocalContext
and isCodeCompletionAtTopLevel
instead of using !
to invert one of them? It's not clear to me whether isCodeCompletionAtTopLevel(X) == !isCompletionDeclContextLocalContext(X)
and the isLocalContext check is just an optimization, or if there is a subtle difference I don't understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a doc comment.
For example, for class C { <HERE> }
, isCompletionDeclContextLocalContext
and isCodeCompletionAtTopLevel
are both false
.
I don't think there's a true
/true
case though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, of course, thanks for explaining!
lib/IDE/CodeCompletion.cpp
Outdated
@@ -5930,11 +5971,127 @@ addKeyword(CodeCompletionResultSink &Sink, StringRef Name, | |||
Builder.setExpectedTypeRelation(TypeRelation); | |||
} | |||
|
|||
static void addDeclKeywords(CodeCompletionResultSink &Sink, | |||
static void | |||
addKeyword(CodeCompletionResultSink &Sink, StringRef Name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a default Flair parameter to the existing addKeyword(Sink, Name, Kind...)
function?
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.
* 'super' in a overriding decl is "common". * type decl introducers (e.g. 'struct', 'enum') at top-level in library files are "common" * type decl introducers in 'protocol' are invalid, hence "rare" * top-level only decl introducer (e.g. 'import', 'extension') are invalid at non-top-level, hence "rare" * nested types in function bodies are "rare" * member only decls (e.g. 'subscript', 'deinit') are invalid in function body, hence "rare" * some modifiers (e.g. 'public', 'private', 'override') are invalid for local decls, hence "rare" rdar://77934651
725d91b
to
a2b5968
Compare
@swift-ci Please smoke test |
Based on #37563
Introduce
CommonKeywordAtCurrentPosition
andRareKeywordAtCurrentPosition
super
in a overriding decl is "common".struct
,enum
) at top-level in library files are "common"protocol
are invalid, hence "rare"import
,extension
) are invalid at non-top-level, hence "rare"subscript
,deinit
) are invalid in function body, hence "rare"public
,private
,override
) are invalid for local decls, hence "rare"rdar://77934651