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

Open
lukaskubanek opened this issue May 24, 2019 · 9 comments
Open

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

lukaskubanek opened this issue May 24, 2019 · 9 comments

Comments

@lukaskubanek
Copy link

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 https://github.com/mxcl/swift-sh.git
$ cd swift-sh
$ swift build -c release
$ cp .build/
$ cp .build/release/swift-sh "/Applications/Xcode 10.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
$ cp .build/release/swift-sh-edit "/Applications/Xcode 10.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/"

Then I created a sample script from the README:

$ cat <<EOF > script
#!/usr/bin/swift sh
import PromiseKit // @mxcl ~> 6.5
print(Promise.value("Hi!"))
EOF
$ 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?

xcode-scheme-script

xcode-scheme-script-completion

@mxcl
Copy link
Owner

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.

@lukaskubanek
Copy link
Author

lukaskubanek commented May 24, 2019

Here are more thoughts about this issue and the edit command implementation. I just learned 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.

@mxcl
Copy link
Owner

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.

@rubenfonseca
Copy link

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 :)

@mxcl
Copy link
Owner

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.

@nearfri
Copy link

nearfri commented Sep 10, 2020

It works after adding Import Paths.

2020-09-10_17-42-27

@jsorge
Copy link
Contributor

jsorge commented Sep 10, 2020

Thank you for pointing that out @nearfri!

@mxcl
Copy link
Owner

mxcl commented Sep 22, 2020

Supposedly fixed in 2.1.0, please confirm.

@haikusw
Copy link
Contributor

haikusw commented Jan 5, 2021

This is working perfectly for me in Xcode 12.2 (swift 5.3.1) under macOS 10.15.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants