Dan2552 / SublimeTextSwiftAutocomplete

Swift autocompletion in Sublime Text using SourceKitten
MIT License
155 stars 7 forks source link

Unhardcode SDK and target #5

Open Dan2552 opened 7 years ago

Dan2552 commented 7 years ago

Use in order:

nettlep commented 6 years ago

is there a way to lookup the most recent iOS SDK to use as default?

Here ya go:

xcrun --show-sdk-path

This will show the current SDK path. In my case, that is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk.

You'll notice that it's returning the path to the macOS SDK, which I believe is the default. You can request the iOS path with:

xcrun --show-sdk-path --sdk iphoneos

Because of this, it may be wise to require a preference to specify the SDK to auto-locate. Assuming macOS or iOS would cause frustration as some of the information presented would be incomplete/incorrect if the wrong SDK is used.

Also note that one can use xcode-select to select the command-line tools, in which case the SDK won't print properly from xcrun (it will return nothing.)

Dan2552 commented 6 years ago

Ah perfect, thanks.

I'm not a fan of requiring any preference if I can avoid it. I'm happy with options existing as long as there's a sensible fall-through for when one isn't set.

Maybe if all else fails it'd be worth trying to infer from source contents (imports) which SDK is in use. I guess that might not necessarily work for cross-platform apps though.

With all of that in mind I think this order makes a bit more sense:

Saying all that though, that's just what I see as the ideal. I'm not in a rush for implementing all of those different fall-throughs anytime soon.

nettlep commented 6 years ago

The reason I suggested the preference requirement is because if the correct SDK isn't chosen, then it looks like it works, but auto-completion and documentation will be occasionally incorrect or not available. It's the "occasionally incorrect" that's the real problem (misleading results suggesting code that won't compile.)

I'm one of those living in the cross-compile world. My project builds for iOS, macOS and Linux/Arm. That last one requires a cross-compile toolchain/SDK that Xcode knows nothing about. Most of the code resides in custom Frameworks/libraries and is shared across all three platforms.

This is going to become more of an issue with Swift having official support for Linux (no Xcode) and the primary development focus for Swift 5 is ABI Stability which will promote more cross-platform development. Consider your 5 bullet points from the perspective of a Linux developer: Only the first bullet point will be apply to them.

So I guess I don't have a good solution which is why I thought the required preference might be the safest path to guarantee no misleading results.

Maybe collaborate with the SourceKitten guy to see if he has suggestions?

Dan2552 commented 6 years ago

It's a shame Sublime Text doesn't really give much control over extra UI elements, it'd be nice to have a similar control as Xcode has in the top left to choose a target device.

I wonder if we could compromise with something like if a preference is not set, in the documentation view popup shows an appropriate message to indicate an SDK must be chosen (maybe even links to actually set a preference, if possible). A similar thing could be shown for if sourcekitten isn't installed.

Or maybe the very top or bottom of every documentation view could always have an SDK line, (again if possible, including a link to change SDK).

rudedogg commented 6 years ago

I think a Sublime Text preference (per project) for SDK/frameworks would be perfect.

To make it more automatic for most users, maybe it's possible to be fancy and use https://github.com/xcodeswift/xcproj for the fallback/default setting?

Edit: May be worth looking at https://github.com/vknabel/vscode-swift-development-environment/commit/87127004c8927f955f8cd731d48d961ce3dc8afb