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

Visual Studio Code support? #49

Closed
markst opened this issue Jun 1, 2022 · 23 comments
Closed

Visual Studio Code support? #49

markst opened this issue Jun 1, 2022 · 23 comments

Comments

@markst
Copy link

markst commented Jun 1, 2022

Hey @johnno1962, firstly thanks for all your work on HotReloading!

I stupidly made the issue on wrong repo here: jordansinger/SwiftUI-Kit#46

Cheers for responding.

I wonder if you might offer some help as to how I can get HotReloading to work when debugging using vscode.

I've created a demo repo here: https://github.com/markst/hotreloading-vscode-ios
Hot reloading works great when running the generated Xcode project from Xcode.
However when launching the project from vscode, hot reloading doesn't work.

@johnno1962
Copy link
Owner

johnno1962 commented Jun 1, 2022

Hi, I'm not sure I can support you on that journey but looking at your repo, you don't seem to have added the HotReloading repo to your Package.swift or loaded the iOSInjection.bundle? You would normally do the latter here: https://github.com/markst/hotreloading-vscode-ios/blob/dev/Demo/Injection/Injection.swift#L11

@markst
Copy link
Author

markst commented Jun 1, 2022

Ah the Package.swift is simply there for SourceKit-LSP support, which may not be necessary.

The HotReloading is repo is added in the project.yml: https://github.com/markst/hotreloading-vscode-ios/blob/dev/project.yml#L6

As I mentioned - it is working fine when building & running in Xcode.

@johnno1962 That's fine, I wondered if something might be screamingly obviously as to why it may not work using xcodebuild

@johnno1962
Copy link
Owner

johnno1962 commented Jun 1, 2022

On second thoughts, there is very little prospect of VSCode support as InjectionIII needs to know where to find the build logs in order to work out how to recompile Swift source files. It might be possible to adapt it but the priority for now will be absorbing the changes that come with Xcode 14.

@markst
Copy link
Author

markst commented Jun 1, 2022

Ah well in that case it seems that passing the Xcode DerivedData directory to xcodebuild does resolve my issue:

xcodebuild -scheme Demo -configuration Debug -sdk iphonesimulator -derivedDataPath ~/Library/Developer/Xcode/DerivedData -allowProvisioningUpdates ARCHS=arm64 <

markst added a commit to markst/hotreloading-vscode-ios that referenced this issue Jun 1, 2022
@johnno1962
Copy link
Owner

Top marks for creativity there! Are you saying Injecting works now?

@markst
Copy link
Author

markst commented Jun 2, 2022

vscode-hotreload-2 2022-06-02 09_24_05

@johnno1962
Copy link
Owner

johnno1962 commented Jun 2, 2022

Wow! No changes to HotReloading required? I'll put a pointer to your repo in the README. It may be using the build logs from when you were using Xcode but still great work.

@markst
Copy link
Author

markst commented Jun 2, 2022

It may be using the build logs from when you were using Xcode but still great work.

I thought that, but have deleted my ~/Library/Developer/Xcode/DerivedData directory multiple times & still works.

@johnno1962 unless the logs are located elsewhere?

@johnno1962
Copy link
Owner

johnno1962 commented Jun 2, 2022

I'm a bit surprised to be honest HotReloading is finding them, but if it works it works ¯\(ツ)/¯. Let me know how you get on and if it's stable I'll ad a note to the HotReloading README.

@markst
Copy link
Author

markst commented Jun 3, 2022

I've added a section to README which explains how to overcome the derivedLogs location:
https://github.com/markst/hotreloading-vscode-ios#support-hotreloading

@johnno1962
Copy link
Owner

This is awesome work! I''ve added a section to the README of HotReloading with a pointer to your project already. I'm wondering if it is possible to use a fixed DerivedData path without the Xcode hash? HotReloading should still find your logs and this would mean people can clone your project and use it without having to modify it.

@johnno1962
Copy link
Owner

johnno1962 commented Jun 4, 2022

In fact, it's already going to work isn't it? The Xcode hash you've entered is probably going to be used anyway. I feel a tweet coming on.

@markst
Copy link
Author

markst commented Jun 4, 2022

Sort of related to johnno1962/InjectionIII#388 then?

If using a DerivedData path without the hash, somewhere along the way the directory with the hash gets created:

image

Far as I can tell, two reference to DerivedData logs are:
https://github.com/johnno1962/HotReloading/blob/main/Sources/HotReloading/StandaloneInjection.swift#L31
https://github.com/johnno1962/HotReloading/blob/main/Sources/injectiond/InjectionServer.swift#L362

@johnno1962
Copy link
Owner

I think the hashed path will get created just by viewing the project in Xcode without building it. This aside does injection work if leave off the hash? Perhaps it doesn't make much difference in the end.

@markst
Copy link
Author

markst commented Jun 4, 2022

Nope, fresh DerivedData and hashed path gets created without ever opening Xcode. It get's created the first time saving after launching using iOS Debug.

Injection only works when passing hashed path to xcodebuild -derivedDataPath.

I'm happy with this setup, no real pressure to support custom derived path.

@johnno1962
Copy link
Owner

johnno1962 commented Jun 4, 2022

Interesting, but if people clone your project the hash will be different and it won't work for them which is a shame. I guess they could figure it out.

@markst
Copy link
Author

markst commented Mar 10, 2023

I did make a start at building a swift package which could be used to generate the hash as part of the vscode environment. https://github.com/markst/xcode-project-hashes

I guess ideally I'd create a vscode extension which would automate the process: markst/hotreloading-vscode-ios#4

@johnno1962
Copy link
Owner

johnno1962 commented Mar 10, 2023

Hey Mark, I'm happy you're still looking on this. I assume you found the XcodeHash implementation to work from. The other news is that I re-wrote The HotReloading Project to take out all the unnecessary code involved in working with the app that had accumulated over the years and is no longer required: https://github.com/johnno1962/InjectionLite. You may want to switch over to that? This code works out the correct build logs to work from by using the last modified one.

@markst
Copy link
Author

markst commented Dec 15, 2023

had a real quick go integrating InjectionLite using Xcode in my demo project, but need to dig deeper as to why it's not working for me:

2023-12-16 08-35-22 2023-12-16 08_37_40

@johnno1962
Copy link
Owner

johnno1962 commented Dec 15, 2023

Hi @markst, Don't you just need an @ObserveInjection var forceRedraw at the end of your View struct to force the redraw? See: https://github.com/johnno1962/HotSwiftUI. To avoid crashes on more substantial edits you should also have a .eraseToAnyView() or .enableInjection() at the end of your view body to "erase" the concrete type returned so it doesn't change over an injection.

@johnno1962
Copy link
Owner

johnno1962 commented Dec 15, 2023 via email

@markst
Copy link
Author

markst commented Jan 24, 2024

thought I'd share this if it's of interest: https://github.com/markst/vscode-xcodegen-builder

@johnno1962
Copy link
Owner

Sounds Handy! Did you get your view refresh problems sorted out in the finish?

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

2 participants