Skip to content

Cannot receive editor support for regions inside compiler directives enabled by traits #2747

Description

@bioball

Swift version

swift-driver version: 1.148.6 Apple Swift version 6.3.2 (swiftlang-6.3.2.1.108 clang-2100.1.1.101)

Platform

arm64-apple-macosx26.0

Editor

Visual Studio Code

Description

I'm working on code that is enabled by a trait, and cannot get sourcekit-lsp to provide editor support for code that is inside regions that are conditionally included via traits.

Here is my locally set .sourcekit-lsp/config.json:

{
  "swiftPM": {
    "traits": ["libpkl", "libpkl_shared"]
  }
}

Here's a reproducer branch; focus on file LibPklClient.swift:

https://github.com/bioball/pkl-swift/tree/sourcekit-bug

Trying to compile with swift build --traits libpkl,libpkl_shared produces error:

Building for debugging...
/Users/danielchao/code/apple/pkl-swift/Sources/PklSwift/LibPkl/LibPklClient.swift:69:14: error: value of type 'LibPklClient' has no member 'foobar'
 67 |
 68 |         // nonsense; `foobar` doesn't exist on `self`
 69 |         self.foobar = "hi"
    |              `- error: value of type 'LibPklClient' has no member 'foobar'
 70 |
 71 |         let context = ResponseContext(continuation: continuation)
[6/9] Compiling PklSwift LibPklClient.swift

However, VSCodes doesn't highlight this error. Also, other basic things don't work, e.g. go-to definition.

Steps to Reproduce

  1. Clone this branch https://github.com/bioball/pkl-swift/tree/sourcekit-bug
  2. Add this file to .sourcekit-lsp/config.json:
    {
      "swiftPM": {
        "traits": ["libpkl", "libpkl_shared"]
      }
    }
    
  3. Navigate to LibPklClient.swift inside Visual Studio Code, and find that the editor isn't showing any error diagnostics, and other things don't work either (e.g. go-to-definition)

NOTE: running swift build produces errors as expected:

Building for debugging...
/Users/danielchao/code/apple/pkl-swift/Sources/PklSwift/LibPkl/LibPklClient.swift:69:14: error: value of type 'LibPklClient' has no member 'foobar'
 67 |
 68 |         // nonsense; `foobar` doesn't exist on `self`
 69 |         self.foobar = "hi"
    |              `- error: value of type 'LibPklClient' has no member 'foobar'
 70 |
 71 |         let context = ResponseContext(continuation: continuation)
[6/9] Compiling PklSwift LibPklClient.swift

Logging

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions