Skip to content

Commit 113a242

Browse files
DougGregortkremenek
authored andcommitted
SE-0022: Code completion for #selector.
1 parent 2279e09 commit 113a242

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,21 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19851985
Builder.addRightParen();
19861986
}
19871987

1988+
void addPoundSelector() {
1989+
// #selector is only available when the Objective-C runtime is.
1990+
if (!Ctx.LangOpts.EnableObjCInterop) return;
1991+
1992+
CodeCompletionResultBuilder Builder(
1993+
Sink,
1994+
CodeCompletionResult::ResultKind::Keyword,
1995+
SemanticContextKind::ExpressionSpecific,
1996+
ExpectedTypes);
1997+
Builder.addTextChunk("selector");
1998+
Builder.addLeftParen();
1999+
Builder.addSimpleTypedParameter("@objc method", /*isVarArg=*/false);
2000+
Builder.addRightParen();
2001+
}
2002+
19882003
void addFunctionCallPattern(const AnyFunctionType *AFT,
19892004
const AbstractFunctionDecl *AFD = nullptr) {
19902005
foundFunction(AFT);
@@ -4569,6 +4584,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
45694584

45704585
case CompletionKind::AfterPound: {
45714586
Lookup.addPoundAvailable(ParentStmtKind);
4587+
Lookup.addPoundSelector();
45724588
break;
45734589
}
45744590
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AFTER_POUND | FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
{
6+
if ##^AFTER_POUND^#
7+
}
8+
9+
// CHECK: Keyword/ExprSpecific: available({#Platform...#}, *); name=available(Platform..., *)
10+
// CHECK: Keyword/ExprSpecific: selector({#@objc method#}); name=selector(@objc method)

0 commit comments

Comments
 (0)