Skip to content

Commit da94183

Browse files
joewillsherDougGregor
authored andcommitted
[SE-0095] [Code completion] for the Any type keyword
Now that Any isn’t in the stdlib we need to add it to code completion separately.
1 parent 3938d56 commit da94183

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4648,6 +4648,15 @@ static void addExprKeywords(CodeCompletionResultSink &Sink) {
46484648
AddKeyword("#dsohandle", "UnsafeMutablePointer<Void>", CodeCompletionKeywordKind::pound_dsohandle);
46494649
}
46504650

4651+
static void addAnyTypeKeyword(CodeCompletionResultSink &Sink) {
4652+
CodeCompletionResultBuilder Builder(
4653+
Sink, CodeCompletionResult::ResultKind::Keyword,
4654+
SemanticContextKind::None, {});
4655+
// pretend 'Any' is from another module
4656+
Builder.setKeywordKind(CodeCompletionKeywordKind::None);
4657+
Builder.addTextChunk("Any");
4658+
}
4659+
46514660

46524661
void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
46534662
bool MaybeFuncBody) {
@@ -4676,19 +4685,23 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
46764685
addSuperKeyword(Sink);
46774686
addLetVarKeywords(Sink);
46784687
addExprKeywords(Sink);
4688+
addAnyTypeKeyword(Sink);
46794689
break;
46804690

46814691
case CompletionKind::PostfixExpr:
46824692
case CompletionKind::PostfixExprParen:
46834693
case CompletionKind::SuperExpr:
46844694
case CompletionKind::SuperExprDot:
4685-
case CompletionKind::TypeSimpleBeginning:
4686-
case CompletionKind::TypeIdentifierWithDot:
4687-
case CompletionKind::TypeIdentifierWithoutDot:
46884695
case CompletionKind::CaseStmtBeginning:
46894696
case CompletionKind::CaseStmtDotPrefix:
4697+
case CompletionKind::TypeIdentifierWithDot:
4698+
case CompletionKind::TypeIdentifierWithoutDot:
46904699
break;
46914700

4701+
case CompletionKind::TypeSimpleBeginning:
4702+
addAnyTypeKeyword(Sink);
4703+
break;
4704+
46924705
case CompletionKind::NominalMemberBeginning:
46934706
addDeclKeywords(Sink);
46944707
addLetVarKeywords(Sink);

test/IDE/complete_type_any.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_IN_FUNC_PARAM > %t.types.txt
2+
// RUN: FileCheck %s -check-prefix=ANY_IN_FUNC_PARAM < %t.types.txt
3+
4+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_IN_VAR_TYPE > %t.types.txt
5+
// RUN: FileCheck %s -check-prefix=ANY_IN_VAR_TYPE < %t.types.txt
6+
7+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_METATYPE_VARIABLE > %t.types.txt
8+
// RUN: FileCheck %s -check-prefix=ANY_METATYPE_VARIABLE < %t.types.txt
9+
10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_METATYPE_MEMBER > %t.types.txt
11+
// RUN: FileCheck %s -check-prefix=ANY_METATYPE_MEMBER < %t.types.txt
12+
13+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ANY_IN_TYPEALIAS > %t.types.txt
14+
// RUN: FileCheck %s -check-prefix=ANY_IN_TYPEALIAS < %t.types.txt
15+
16+
17+
func testAnyInParamList(a: #^ANY_IN_FUNC_PARAM^#
18+
// ANY_IN_FUNC_PARAM: Begin completions
19+
// ANY_IN_FUNC_PARAM-DAG: Keyword/None: Any; name=Any
20+
// ANY_IN_FUNC_PARAM: End completions
21+
22+
func scope() {
23+
var a: #^ANY_IN_VAR_TYPE^#
24+
// ANY_IN_VAR_TYPE: Begin completions
25+
// ANY_IN_VAR_TYPE-DAG: Keyword/None: Any; name=Any
26+
// ANY_IN_VAR_TYPE: End completions
27+
}
28+
29+
let _: Any.Type = #^ANY_METATYPE_VARIABLE^#
30+
// ANY_METATYPE_VARIABLE: Begin completions
31+
// ANY_METATYPE_VARIABLE-DAG: Keyword/None: Any; name=Any
32+
// ANY_METATYPE_VARIABLE: End completions
33+
34+
_ = Int.#^ANY_METATYPE_MEMBER^#
35+
// ANY_METATYPE_MEMBER: Begin completions
36+
// ANY_METATYPE_MEMBER-NOT: Any
37+
// ANY_METATYPE_MEMBER: End completions
38+
39+
typealias A = #^ANY_IN_TYPEALIAS^#
40+
// ANY_IN_TYPEALIAS: Begin completions
41+
// ANY_IN_TYPEALIAS-DAG: Keyword/None: Any; name=Any
42+
// ANY_IN_TYPEALIAS: End completions
43+
44+

0 commit comments

Comments
 (0)