SourceKit - Compilation Condition - Error Response


I've got some questions regarding 'sourcekit response for compilation conditions' and I truly need you guys for directions.

Create a "CursorInfo" request for the below code:

import Foundation

class Foo {
    var prop: String?
    func test() {
        #if targetEnvironment(simulator)
        prop = "simulator"
        prop = "device"


I'm looking to get a response for both conditions. The 'if condition' response it's as expected but the 'else condition' is throwing an error and I was expecting a response instead.


How can I get a response for the 'else condition' - prop = "device"?
Or is this expected and should work only for the active compilation condition? Maybe there is a way to ignore the condition?

Thank you in advance.


-- begin response ------------
key.kind: source.lang.swift.ref.var.instance, "prop",
key.usr: "s:4main3FooC4propSSSgvp",
key.filepath: ".../cursor-req.swift",
key.offset: 39,
key.length: 4,
key.typename: "String?",
key.annotated_decl: "var prop: <Type usr="s:SS">String?",
key.fully_annotated_decl: "<decl.var.instance><syntaxtype.keyword>var</syntaxtype.keyword> <>prop</>: <decl.var.type><ref.struct usr="s:SS">String</ref.struct>?</decl.var.type></decl.var.instance>",
key.typeusr: "$sSSSgD",
key.containertypeusr: "$s4main3FooCD",
key.refactor_actions: [
key.actionname: "Global Rename",
-- end response --------------
Produced: Response for CursorInfo in .../cursor-req.swift at offset 166 with args: -sdk /Applications/ -target x86_64-apple-ios11.0-simulator .../cursor-req.swift
-- begin response ------------
key.internal_diagnostic: "Unable to resolve cursor info."
-- end response --------------

How do I test?

alias sk-stress="/Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-11-11-a.xctoolchain/usr/bin/sk-stress-test

sk-stress --report-responses -r CursorInfo -m none .../cursor-req.swift swiftc -sdk /Applications/ -target x86_64-apple-ios11.0-simulator .../cursor-req.swift

Unfortunately, it's expected that it only works in the active condition, since only the active condition gets type-checking and name binding.

I'm using SourceKit to parse and find the "prop" in both conditions. I guess a workaround is needed here.

Ben, thanks for the clarification.

Terms of Service

Privacy Policy

Cookie Policy