Skip to content

Commit 7c4aaef

Browse files
authored
[CodeCompletion] Disable completion for declaration name position (#16898)
Code completion should not suggest anything when declaring a new name. rdar://problem/29392238
1 parent 57ed4fc commit 7c4aaef

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,10 +2673,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
26732673
return makeParserErrorResult<Decl>();
26742674
}
26752675

2676-
if (DeclResult.isParseError() && MayNeedOverrideCompletion &&
2677-
Tok.is(tok::code_complete)) {
2678-
DeclResult = makeParserCodeCompletionStatus();
2679-
if (CodeCompletion) {
2676+
if (DeclResult.isParseError() && Tok.is(tok::code_complete)) {
2677+
if (MayNeedOverrideCompletion && CodeCompletion) {
26802678
// If we need to complete an override, collect the keywords already
26812679
// specified so that we do not duplicate them in code completion
26822680
// strings.
@@ -2698,6 +2696,9 @@ Parser::parseDecl(ParseDeclOptions Flags,
26982696
}
26992697
CodeCompletion->completeNominalMemberBeginning(Keywords);
27002698
}
2699+
2700+
DeclResult = makeParserCodeCompletionStatus();
2701+
consumeToken(tok::code_complete);
27012702
}
27022703

27032704
if (auto SF = CurDeclContext->getParentSourceFile()) {

test/IDE/complete_declname.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=CLASSNAME | %FileCheck %s --check-prefix=NO_COMPLETIONS
2+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=STRUCTNAME | %FileCheck %s --check-prefix=NO_COMPLETIONS
3+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ENUMNAME | %FileCheck %s --check-prefix=NO_COMPLETIONS
4+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOLNAME | %FileCheck %s --check-prefix=NO_COMPLETIONS
5+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PRECEDENCEGROUPNAME | %FileCheck %s --check-prefix=NO_COMPLETIONS
6+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OPERATORNAME | %FileCheck %s --check-prefix=NO_COMPLETIONS
7+
8+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-keywords=false -code-completion-token=METHODNAME | %FileCheck %s --check-prefix=NO_COMPLETIONS
9+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-keywords=false -code-completion-token=METHODNAME_OVERRIDE | %FileCheck %s --check-prefix=METHODNAME_OVERRIDE
10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-keywords=false -code-completion-token=METHODNAME_PROTOCOL | %FileCheck %s --check-prefix=NO_COMPLETIONS
11+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-keywords=false -code-completion-token=METHODNAME_CONFORMANCE | %FileCheck %s --check-prefix=METHODNAME_CONFORMANCE
12+
13+
// NO_COMPLETIONS-NOT: Begin completions
14+
15+
class #^CLASSNAME^# {}
16+
struct #^STRUCTNAME^#
17+
enum #^ENUMNAME^#
18+
protocol #^PROTOCOLNAME^# {}
19+
precedencegroup #^PRECEDENCEGROUPNAME^#
20+
infix operator #^OPERATORNAME^#
21+
22+
class MyCls {
23+
func foo() {}
24+
func #^METHODNAME^#
25+
}
26+
27+
class MySub : MyCls {
28+
func #^METHODNAME_OVERRIDE^#
29+
// METHODNAME_OVERRIDE: Begin completions, 1 items
30+
// METHODNAME_OVERRIDE-NEXT: Decl[InstanceMethod]/Super: foo() {|}; name=foo()
31+
// METHODNAME_OVERRIDE-NEXT: End completions
32+
}
33+
34+
protocol P {
35+
func foo() {}
36+
func #^METHODNAME_PROTOCOL^#
37+
}
38+
39+
struct MyStruct : P {
40+
func #^METHODNAME_CONFORMANCE^#
41+
// METHODNAME_CONFORMANCE: Begin completions, 1 items
42+
// METHODNAME_CONFORMANCE-NEXT: Decl[InstanceMethod]/Super: foo() {|}; name=foo()
43+
// METHODNAME_CONFORMANCE-NEXT: End completions
44+
}

0 commit comments

Comments
 (0)