Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocompletion when editing script in Xcode doesn't work #87

lukaskubanek opened this issue May 24, 2019 · 5 comments


Copy link

@lukaskubanek lukaskubanek commented May 24, 2019

Today, I researched a way for handling helper scripts for my Mac application. I tested all three major players (swift-sh, Marathon, Beak) and I like the approach of swift-sh the most. Especially the shebang and the idea of editing out into Xcode while working on the script without having to maintain the Xcode project afterwards.

Unfortunately, there have been also two issues which bother me a bit. The first one being the management of the Homebrew formula which I described in mxcl/homebrew-made#4. The second one is the inability to get the autocompleting in Xcode working.

Here are the steps I've performed. First, I installed the tool from source (version 1.12.0):

$ git clone
$ cd swift-sh
$ swift build -c release
$ cp .build/
$ cp .build/release/swift-sh "/Applications/Xcode"
$ cp .build/release/swift-sh-edit "/Applications/Xcode"

Then I created a sample script from the README:

$ cat <<EOF > script
#!/usr/bin/swift sh
import PromiseKit // @mxcl ~> 6.5
$ chmod u+x script
$ ./script
# => Promise("Hi!")

So far everything worked smoothly, so I tried to edit the script in Xcode 10.2 using $ swift sh edit script. Xcode opened but no matter which scheme I selected the autocompletion didn't work. The script scheme allowed me to run the script and the script-completion scheme behaved very strangely showing errors complaining about script not being main.swift. Below are some screenshots showing the problem.

@mxcl I must be missing something. Could you please give me a hint regarding what I'm doing wrong?




This comment has been minimized.

Copy link

@mxcl mxcl commented May 24, 2019

It did work, but seemingly has stopped working. The completion scheme is not meant to be run, but is autogenerated by Xcode. It is required to get complete, but apparently is not working currently.


This comment has been minimized.

Copy link

@lukaskubanek lukaskubanek commented May 24, 2019

Here are more thoughts about this issue and the edit command implementation. I just learnt that there was a big change in the behavior which went from the standard Xcode project generated via swift package generate-xcodeproj to a custom one which generates the Xcode project manually using tuist/xcodeproj (#57 & #58). I have to say that the latter Xcode project looks somehow half-baked compared to the one generated by SPM. I generated the Xcode project with SPM and the completion worked like a charm. Unfortunately, there is the saving issue which was the main reason for the change in #57.

While going through other tools today, I stumbled upon the way Marathon handles this. After executing the edit command, the Xcode project generated via SPM gets opened but the command is waiting. After performing the change the command is terminated which apparently copies the changed file to its original location. Wouldn't this be a nicer approach?

EDIT: This is the routine in the Marathon codebase I'm referring to.


This comment has been minimized.

Copy link

@mxcl mxcl commented Jul 20, 2019

Wouldn't this be a nicer approach?

I would not like this approach no. I need my terminal to be useful, not waiting for things, not to mention there are numerous ways you could lose work because the terminal command is killed while you continue to edit.

Honestly, I think it's a really terrible approach.


This comment has been minimized.

Copy link

@rubenfonseca rubenfonseca commented Oct 4, 2019

Hi guys thank you so much for this project. I was trying to see if I could make this work with XCode 11, but I also never get any autocompletion out of it. Does anybody have any idea what needs to be done? Maybe I could try to hack it :)


This comment has been minimized.

Copy link

@mxcl mxcl commented Oct 4, 2019

IIRC the trick was building a dylib or framework of the deps and providing that as a include/link path to the executable binary but not actually linking it.

I was inspired by what SwiftPM was doing for completion in its Package.swift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.