terhechte / SourceKittenDaemon

Swift Auto Completions for any Text Editor
MIT License
529 stars 37 forks source link

Swift 5 Support #78

Closed michaelnew closed 3 years ago

michaelnew commented 5 years ago

Spent a while trying to get things working again with Xcode 10.2 / Swift 5. I've been using this for a few days and it does seem to work, but probably shouldn't be merged yet.

Package.swift had to be updated to the new packaging format, which means all the dependencies also have to use the new format. In most cases there aren't tagged releases that we can point to that have the updates, so for now all the dependencies are just the latest on git. Embassy is pointed at my fork right now, but I have a PR open with them, so once that's merged that can be changed back to envoy/embassy.

The biggest change here is getting things to work with the latest version of XcodeEdit. I didn't spend much time on this: it was more of a "make it work" effort. This could probably do with some testing and/or review.

I don't think there's anything in this project that requires Swift 5, but Commandant won't compile without it. So the update effectively drops support for anything prior to Xcode 10.2.

Currently this is a bit messy, but I wanted to get this out there so no one else has to duplicate the effort.

DivineDominion commented 5 years ago

@michaelnew Any progress on the cleaning-up part and Embassy? Does anything else need to be done where I could help?

michaelnew commented 5 years ago

Doesn't look like Embassy has merged that PR. Might be worth making some noise over there to see if they'll go ahead and do that.

Otherwise I've been using this almost daily for a few months now, and as far as I can tell it's working well. It would be nice if someone who knew the codebase a little better took a look though.

Having said that, the current master branch doesn't work at all on Swift 5, so merging might be better than not. Or at lest have a branch for Swift 5 since it is a breaking change.

michaelnew commented 5 years ago

Embassy is now set up to use SPM with Swift 5, so the embassy dependency is no longer pointed at my branch.

IMO I think this should be merged unless anyone finds something wrong with it. Swift 5 has been out for quite a while now. It also might make sense to fork or tag current master since Commandant doesn't build on Swift 4, so this PR would effectively make things Swift 5 only.

ghost commented 5 years ago

You need to remove and re-run make install, then commit that Package.resolved file in order to get a reproducible build.

charshep commented 4 years ago

@michaelnew I cloned your branch and after a few days so far so good. The only change I had to make was I needed to comment out some of the (seemingly) superfluous compiler flags that were being passed to SourceKittenFramework (issue #65). Is everything still working for you? If so, what's required to resurrect this project? From what I can tell it's the following:

BTW thanks for doing all this work.

sebschlo commented 4 years ago

Would love to get this project resurrected. Happy to help if I can. I tried installing @michaelnew 's branch as well, and removed the flags, but I'm getting:

Fatal error: 'try!' expression unexpectedly raised an error: XcodeEdit.ProjectFileError.internalInconsistency([XcodeEdit.ReferenceError.orphanObject(type: "XCSwiftPackageProductDependency", id: XcodeEdit.Guid(value: "529994A92384C9E500AB5ABF")), XcodeEdit.ReferenceError.orphanObject(type: "XCSwiftPackageProductDependency", id: XcodeEdit.Guid(value: "529994AB2384C9E900AB5ABF"))]): file /private/tmp/SourceKittenDaemon/Sources/SourceKittenDaemon/Project/Project.swift, line 102
Illegal instruction: 4

It looks like it might be an issue with my specific project dependencies, or maybe with XcodeEdit. I'm not super familiar with these libraries, any ideas of what could be going on here? @charshep ?

leviathan commented 3 years ago

Apart from some warnings this look good to me.

PR branch clone & clean install

$> make install
mkdir -p.build/release
swift build -c release --build - path.build
Fetching https://github.com/Carthage/Commandant.git
Fetching https://github.com/jpsim/SourceKitten.git
Fetching https://github.com/envoy/Embassy.git
Fetching https://github.com/tomlokhorst/XcodeEdit
Fetching https://github.com/antitypical/Result.git
Fetching https://github.com/Quick/Quick.git
Fetching https://github.com/mattgallagher/CwlCatchException.git
Fetching https://github.com/mattgallagher/CwlPreconditionTesting.git
Fetching https://github.com/drmohundro/SWXMLHash.git
Fetching https://github.com/jpsim/Yams.git
Fetching https://github.com/Quick/Nimble.git
Cloning https://github.com/jpsim/Yams.git
Resolving https://github.com/jpsim/Yams.git at 2.0.0
Cloning https://github.com/antitypical/Result.git
Resolving https://github.com/antitypical/Result.git at master
Cloning https://github.com/Carthage/Commandant.git
Resolving https://github.com/Carthage/Commandant.git at master
Cloning https://github.com/mattgallagher/CwlPreconditionTesting.git
Resolving https://github.com/mattgallagher/CwlPreconditionTesting.git at 1.2.0
Cloning https://github.com/jpsim/SourceKitten.git
Resolving https://github.com/jpsim/SourceKitten.git at master
Cloning https://github.com/tomlokhorst/XcodeEdit
Resolving https://github.com/tomlokhorst/XcodeEdit at develop
Cloning https://github.com/Quick/Quick.git
Resolving https://github.com/Quick/Quick.git at 2.2.0
Cloning https://github.com/drmohundro/SWXMLHash.git
Resolving https://github.com/drmohundro/SWXMLHash.git at 5.0.1
Cloning https://github.com/Quick/Nimble.git
Resolving https://github.com/Quick/Nimble.git at 8.0.5
Cloning https://github.com/envoy/Embassy.git
Resolving https://github.com/envoy/Embassy.git at master
Cloning https://github.com/mattgallagher/CwlCatchException.git
Resolving https://github.com/mattgallagher/CwlCatchException.git at 1.2.0
/SourceKittenDaemon/.build/checkouts/Result/Result/NoError.swift:10:3: warning: will never be executed
return true
    ^
   /SourceKittenDaemon/.build/checkouts/Result/Result/NoError.swift:9:60: note: 'lhs' is uninhabited, so this function body can never be executed

public static func == (lhs: NoError, rhs: NoError) -> Bool {
    ^
   /SourceKittenDaemon/.build/checkouts/Yams/Sources/Yams/Emitter.swift:338:32: warning: initialization of 'UnsafeMutablePointer < yaml_version_directive_t > ' (aka 'UnsafeMutablePointer < yaml_version_directive_s > ') results in a dangling pointer
    versionDirective = UnsafeMutablePointer(&versionDirectiveValue)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /SourceKittenDaemon/.build/checkouts/Yams/Sources/Yams/Emitter.swift:338:53: note: implicit argument conversion from 'yaml_version_directive_t' (aka 'yaml_version_directive_s') to 'UnsafeMutablePointer < yaml_version_directive_t > ' (aka 'UnsafeMutablePointer < yaml_version_directive_s > ') produces a pointer valid only for the duration of the call to 'init(_:)'
    versionDirective = UnsafeMutablePointer(&versionDirectiveValue)
        ^~~~~~~~~~~~~~~~~~~~~~
   /SourceKittenDaemon/.build/checkouts/Yams/Sources/Yams/Emitter.swift:338:53: note: use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope
    versionDirective = UnsafeMutablePointer(&versionDirectiveValue)
        ^

[18/18] Build complete!
mkdir -p dist/bin
cp.build/release/sourcekittend dist/bin/sourcekittendaemon
mkdir -p "/usr/local/bin"
mkdir -p "/usr/local/lib"
cp -f "dist/bin/sourcekittendaemon" "/usr/local/bin/"

My environment info

macOS Big Sur / Version: 11.4 (20F71)

➜ xcode-select --print-path
/Applications/Xcode.app/Contents/Developer

➜ xcodebuild -version          
Xcode 12.5.1
Build version 12E507

➜ swift --version
Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)
Target: x86_64-apple-darwin20.5.0

➜ swift build --version
Swift Package Manager - Swift 5.4.0
terhechte commented 3 years ago

Sorry for not looking into this for quite some time. @michaelnew I'll review the PR today and see if there's anything I see that demands attention. I'm fine with the warnings that are emitted as they're all from deps.

leviathan commented 3 years ago

@terhechte thanks! 👌 Also kudos to @michaelnew for this PR.