ChimeHQ / LanguageClient

Language Server Protocol (LSP) client for Swift
BSD 3-Clause "New" or "Revised" License
93 stars 10 forks source link

SwiftUI Previews not working #16

Open jbromberg opened 5 months ago

jbromberg commented 5 months ago

SwiftUI Previews fail to load when using this package due to many compile errors related to the ProcessEnv and FSEventsWrapper dependencies. Here's a build log showing the errors:

Build for Previews code-edit_2024-01-18T10-57-02.txt

mattmassicotte commented 5 months ago

Ahhh you are building for the simulator. I wonder if that’s it.

jbromberg commented 5 months ago

Yea no matter what I change the device to in the SwiftUI preview window I get the same errors

mattmassicotte commented 5 months ago

Really appreciate the report!

There are checks in there, and they appear good enough for Linux builds. Need to investigate.

mattmassicotte commented 5 months ago

Could it be that according to SPM this is macOS, but according to the compiler it is not? That would be a wild problem that I would totally believe.

mattmassicotte commented 5 months ago

I have confirmed that in this specific situation, the package dependency conditionals think this is macOS 😵‍💫.

jbromberg commented 5 months ago

Hmmm. So does that mean using @available wouldn't work?

mattmassicotte commented 5 months ago

@available is a good thought, but that is a runtime construct, not a compile-time thing. We need to prevent the compiler from seeing this code. (This distinction is a little confusing. I wrote about it a bit here: https://www.chimehq.com/blog/swift-and-old-sdks)

Step one, I managed to create a reasonably minimal example and included it in a bug report: FB13551706

mattmassicotte commented 5 months ago

So I investigated a few different possible fixes for this, and I wasn't able to find one that didn't have drawbacks.

I think the most readable solution, given that this only affects SwiftUI previews on iOS is to maintain a branch with the features not supportable by iOS explicitly removed.