-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Parse #if block containing CC token as active #33475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
22c157f
6653172
dd6046b
7198b3b
6cfdaf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -695,8 +695,9 @@ void Parser::skipSingle() { | |
void Parser::skipUntil(tok T1, tok T2) { | ||
// tok::NUM_TOKENS is a sentinel that means "don't skip". | ||
if (T1 == tok::NUM_TOKENS && T2 == tok::NUM_TOKENS) return; | ||
|
||
while (Tok.isNot(T1, T2, tok::eof, tok::pound_endif, tok::code_complete)) | ||
|
||
while (Tok.isNot(T1, T2, tok::eof, tok::pound_endif, tok::pound_else, | ||
tok::pound_elseif)) | ||
Comment on lines
-699
to
+700
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As for |
||
skipSingle(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t | ||
|
||
struct MyStruct { | ||
init() {} | ||
var value: Int | ||
} | ||
|
||
// MEMBER_MyStruct: Begin completions, 2 items | ||
// MEMBER_MyStruct-DAG: Keyword[self]/CurrNominal: self[#MyStruct#]; | ||
// MEMBER_MyStruct-DAG: Decl[InstanceVar]/CurrNominal: value[#Int#]; | ||
// MEMBER_MyStruct: End completions | ||
|
||
#if true | ||
let toplevelActive = MyStruct() | ||
_ = toplevelActive.#^MEMBER_TOPLEVEL_ACTIVE?check=MEMBER_MyStruct^# | ||
#else | ||
let toplevelInactive = MyStruct() | ||
_ = toplevelInactive.#^MEMBER_TOPLEVEL_INACTIVE?check=MEMBER_MyStruct^# | ||
#endif | ||
|
||
func foo() { | ||
#if true | ||
let infuncActive = MyStruct() | ||
_ = infuncActive.#^MEMBER_INFUNC_ACTIVE?check=MEMBER_MyStruct^# | ||
#else | ||
let infuncInactive = MyStruct() | ||
_ = infuncInactive.#^MEMBER_INFUNC_INACTIVE?check=MEMBER_MyStruct^# | ||
#endif | ||
} | ||
|
||
protocol TestP { | ||
func foo() | ||
func bar() | ||
} | ||
struct TestStruct: TestP { | ||
#if true | ||
func foo() {} | ||
func #^OVERRIDE_ACTIVE^# | ||
// OVERRIDE_ACTIVE: Begin completions, 1 items | ||
// OVERRIDE_ACTIVE-DAG: Decl[InstanceMethod]/Super: bar() {|}; | ||
// OVERRIDE_ACTIVE: End completions | ||
#else | ||
func bar() {} | ||
func #^OVERRIDE_INACTIVE^# | ||
// OVERRIDE_INACTIVE: Begin completions, 1 items | ||
// OVERRIDE_INACTIVE-DAG: Decl[InstanceMethod]/Super: foo() {|}; | ||
// OVERRIDE_INACTIVE: End completions | ||
#endif | ||
} | ||
|
||
struct TestStruct2 { | ||
#if true | ||
func activeFunc() {} | ||
func test() { | ||
self.#^SELF_ACTIVE^# | ||
} | ||
// SELF_ACTIVE: Begin completions, 3 items | ||
// SELF_ACTIVE-DAG: Keyword[self]/CurrNominal: self[#TestStruct2#]; | ||
// SELF_ACTIVE-DAG: Decl[InstanceMethod]/CurrNominal: activeFunc()[#Void#]; | ||
// SELF_ACTIVE-DAG: Decl[InstanceMethod]/CurrNominal: test()[#Void#]; | ||
// SELF_ACTIVE: End completions | ||
#else | ||
func inactiveFunc() {} | ||
func test() { | ||
self.#^SELF_INACTIVE^# | ||
} | ||
// SELF_INACTIVE: Begin completions, 3 items | ||
// SELF_INACTIVE-DAG: Keyword[self]/CurrNominal: self[#TestStruct2#]; | ||
// SELF_INACTIVE-DAG: Decl[InstanceMethod]/CurrNominal: inactiveFunc()[#Void#]; | ||
// SELF_INACTIVE-DAG: Decl[InstanceMethod]/CurrNominal: test()[#Void#]; | ||
// SELF_INACTIVE: End completions | ||
#endif | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
struct MyStruct { | ||
init() {} | ||
var value: Int = 1 | ||
} | ||
|
||
func foo(arg: MyStruct) { | ||
#if true | ||
_ = arg./*8:11*/ | ||
#else | ||
_ = arg./*10:11*/ | ||
#endif | ||
} | ||
|
||
struct TestStruct { | ||
#if true | ||
func testActive(arg: MyStruct) { | ||
_ = arg./*17:13*/ | ||
} | ||
#else | ||
func testInactive(arg: MyStruct) { | ||
_ = arg./*21:13*/ | ||
} | ||
#endif | ||
} | ||
|
||
// Test that (1) fast completion happens even in inactive #if blocks, and | ||
// (2) #if in toplevel decls invalidate cached ASTContext | ||
|
||
// RUN: %sourcekitd-test \ | ||
// RUN: -req=complete -pos=8:11 %s -- %s -parse-as-library == \ | ||
// RUN: -req=complete -pos=10:11 %s -- %s -parse-as-library == \ | ||
// RUN: -req=complete -pos=17:13 %s -- %s -parse-as-library == \ | ||
// RUN: -req=complete -pos=21:13 %s -- %s -parse-as-library \ | ||
// RUN: | %FileCheck %s --check-prefix=RESULT | ||
|
||
// RESULT-LABEL: key.results: [ | ||
// RESULT-DAG: key.description: "value" | ||
// RESULT: ] | ||
// RESULT-NOT: key.reusingastcontext: 1 | ||
|
||
// RESULT-LABEL: key.results: [ | ||
// RESULT-DAG: key.description: "value" | ||
// RESULT: ] | ||
// RESULT: key.reusingastcontext: 1 | ||
|
||
// RESULT-LABEL: key.results: [ | ||
// RESULT-DAG: key.description: "value" | ||
// RESULT: ] | ||
// RESULT: key.reusingastcontext: 1 | ||
|
||
// RESULT-LABEL: key.results: [ | ||
// RESULT-DAG: key.description: "value" | ||
// RESULT: ] | ||
// RESULT-NOT: key.reusingastcontext: 1 |
Uh oh!
There was an error while loading. Please reload this page.