Skip to content

Commit 56ce861

Browse files
committed
[CodeCompletion] Eat identifier characters after CC position
Text on editors (e.g. Xcode) may contain identifiers following to CC position which should be considered as "filtering text" for the code completion. For example, a user types '@A' the CC position is between '@' and 'a'. The user probably expects attributes starting with 'a'. Eat identifier characters after CC token in Lexer. By this change, for instance for '@<token>IB class', the parser now can detect this is a start of class declaration and emit class attributes completions. rdar://problem/46103294
1 parent a923281 commit 56ce861

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/Parse/Lexer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,8 @@ void Lexer::lexImpl() {
23862386
case 0:
23872387
switch (getNulCharacterKind(CurPtr - 1)) {
23882388
case NulCharacterKind::CodeCompletion:
2389+
while (advanceIfValidContinuationOfIdentifier(CurPtr, BufferEnd))
2390+
;
23892391
return formToken(tok::code_complete, TokStart);
23902392

23912393
case NulCharacterKind::BufferEnd:

test/IDE/complete_decl_attribute.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AVAILABILITY2 | %FileCheck %s -check-prefix=AVAILABILITY2
33
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD2 | %FileCheck %s -check-prefix=KEYWORD2
44
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD3 | %FileCheck %s -check-prefix=KEYWORD3
5+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD3_2 | %FileCheck %s -check-prefix=KEYWORD3
56
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD4 | %FileCheck %s -check-prefix=KEYWORD4
67
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD5 | %FileCheck %s -check-prefix=KEYWORD5
78
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD_LAST | %FileCheck %s -check-prefix=KEYWORD_LAST
@@ -63,6 +64,10 @@ class C {}
6364
// KEYWORD3-NEXT: Keyword/None: usableFromInline[#Class Attribute#]; name=usableFromInline
6465
// KEYWORD3-NEXT: End completions
6566

67+
@#^KEYWORD3_2^#IB
68+
class C2 {}
69+
// Same as KEYWORD3.
70+
6671
@#^KEYWORD4^#
6772
enum E {}
6873
// KEYWORD4: Begin completions, 5 items

0 commit comments

Comments
 (0)