Skip to content

Commit 878c9c6

Browse files
committed
[CodeCompletion] Enable type completion at beginning of attribute
for 'VarDecl' or if we don't know the kind of the decl. Property delegate allows arbitrary type name (with `@propertyDelegate` attr).
1 parent afd6d66 commit 878c9c6

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class CodeCompletionCallbacks {
186186
virtual void completeAccessorBeginning(CodeCompletionExpr *E) {};
187187

188188
/// Complete the keyword in attribute, for instance, @available.
189-
virtual void completeDeclAttrKeyword(Decl *D, bool Sil, bool Param) {};
189+
virtual void completeDeclAttrBeginning(Decl *D, bool Sil, bool Param) {};
190190

191191
/// Complete the parameters in attribute, for instance, version specifier for
192192
/// @available.

lib/IDE/CodeCompletion.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13671367
void completeCaseStmtKeyword() override;
13681368
void completeCaseStmtBeginning() override;
13691369
void completeCaseStmtDotPrefix() override;
1370-
void completeDeclAttrKeyword(Decl *D, bool Sil, bool Param) override;
1370+
void completeDeclAttrBeginning(Decl *D, bool Sil, bool Param) override;
13711371
void completeDeclAttrParam(DeclAttrKind DK, int Index) override;
13721372
void completeInPrecedenceGroup(SyntaxKind SK) override;
13731373
void completeNominalMemberBeginning(
@@ -4601,9 +4601,8 @@ void CodeCompletionCallbacksImpl::completeDeclAttrParam(DeclAttrKind DK,
46014601
CurDeclContext = P.CurDeclContext;
46024602
}
46034603

4604-
void CodeCompletionCallbacksImpl::completeDeclAttrKeyword(Decl *D,
4605-
bool Sil,
4606-
bool Param) {
4604+
void CodeCompletionCallbacksImpl::completeDeclAttrBeginning(Decl *D, bool Sil,
4605+
bool Param) {
46074606
Kind = CompletionKind::AttributeBegin;
46084607
IsInSil = Sil;
46094608
if (Param) {
@@ -5378,6 +5377,11 @@ void CodeCompletionCallbacksImpl::doneParsing() {
53785377

53795378
case CompletionKind::AttributeBegin: {
53805379
Lookup.getAttributeDeclCompletions(IsInSil, AttTargetDK);
5380+
5381+
// Provide any type name for property delegate.
5382+
if (!AttTargetDK || *AttTargetDK == DeclKind::Var)
5383+
Lookup.getTypeCompletionsInDeclContext(
5384+
P.Context.SourceMgr.getCodeCompletionLoc());
53815385
break;
53825386
}
53835387
case CompletionKind::AttributeDeclParen: {

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
29402940
if (!CodeCompletion) {
29412941
delayParseFromBeginningToHere(BeginParserPosition, Flags);
29422942
} else {
2943-
CodeCompletion->completeDeclAttrKeyword(nullptr, isInSILMode(), false);
2943+
CodeCompletion->completeDeclAttrBeginning(nullptr, isInSILMode(),
2944+
false);
29442945
}
29452946
}
29462947

@@ -3012,9 +3013,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
30123013

30133014
if (FoundCCTokenInAttr) {
30143015
if (CodeCompletion) {
3015-
CodeCompletion->completeDeclAttrKeyword(DeclResult.getPtrOrNull(),
3016-
isInSILMode(),
3017-
false);
3016+
CodeCompletion->completeDeclAttrBeginning(DeclResult.getPtrOrNull(),
3017+
isInSILMode(), false);
30183018
} else {
30193019
delayParseFromBeginningToHere(BeginParserPosition, Flags);
30203020
return makeParserError();

lib/Parse/ParsePattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
224224
parseDeclAttributeList(param.Attrs, FoundCCToken);
225225
if (FoundCCToken) {
226226
if (CodeCompletion) {
227-
CodeCompletion->completeDeclAttrKeyword(nullptr, isInSILMode(), true);
227+
CodeCompletion->completeDeclAttrBeginning(nullptr, isInSILMode(), true);
228228
} else {
229229
status |= makeParserCodeCompletionStatus();
230230
}

0 commit comments

Comments
 (0)