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
Possibility to run build from the external code editor. #6604
Comments
I think it is also worthwhile to investigate how to speed up a bob build. |
yep, it's another issue. I'll create a ticket, now when we have a nice time report that should help to figure out what's going on there |
Hello, How I see it: Rather than adding new endpoints for each command ("Build", "Rebuild", "Hot Reload", etc) add new single endpoint that will be accepting different "commands". |
Yes, absolutely! But we need a design discussion first! You have some suggestions that we need to discuss and agree upon before moving on with the implementation!
There are pros and cons with this. With one endpoint per action it becomes obvious from the url what the endpoint does. And if an endpoint doesn't exists you'll get a 404. A single endpoint will obviously result in fewer endpoints but it will be more prone to errors as you need to either POST some command or include the command as a query argument.
I don't see the value in running another web server. More open ports and more CPU resources are required.
The existing web server is configured with its handlers in |
Good point. I haven't thought about it from that perspective. The main reason was extensibility, to make it super simple adding more commands in future. Another reason was to try to avoid possible confusion between existing "internal" build or hot-reload endpoints with the "external" stuff.
Makes sense. Probably pros of an independent web server for "external use" are not worth the extra resource costs. One possible challenge with the existing server is to figure out how to make it discoverable since it is being assigned a random port by OS. To keep it simple for now, I will try to scan/find it on the VSCode side.
I was not sure if existing Java files in the source code were legacy code or not and what was your strategy as far as Clojure/Java is concerned. Since it will be for external editors perhaps someone else would like to contribute in future. |
This could be made configurable. We can check for an environment variable and use the port specified if the env var is set. |
It should be relatively trivial for us to add new endpoints for build, rebuild, and hot reload as long as they are fire-and-forget requests. If we need progress reporting or even just some way to know the build has completed, things may be a bit more complicated. You could do a long-polling request and simply not answer the request until the build has completed, but we don't want to lock up either VSCode or the editor in the meantime. On the editor side we could make sure such requests are processed on a background thread and presumably we could use promises or some similar mechanism in VSCode to get around it. Another approach would be to expose a websocket interface from the editor for external tools to communicate with. That gives us more flexibility since we can do two-way communication and not just respond to direct requests. I think we should focus on implementing fire-and-forget requests with the existing web server for now, though. |
I totally agree that this should be the first step! |
What if there's a build error? We will show it in the editor, but we won't have any way to communicate that something went wrong to VSCode if it is a fire-and-forget request. |
Regarding scanning for ports, users can have other servers running on their machine, so we probably want to restrict ourselves to a port range or something like that. I guess users might also have several Defold editors open with different projects. We might want some mechanism to match up the project path with a particular editor. Maybe we could port-scan a small range and send a handshake request that responds with the project path or something like that? |
What if 2 editors run on the same machine? Also, AFAIK we use UPnP for the discovery of remote engines running on the network (e.g. mobile), perhaps this is something that could also be used for vscode-editor communication and discovery? |
Eventually, it would be great to identify an opened project as well as Editor version (+sha1). I also will need guidance where to put new handlers in code. |
Handlers are registered with the web server here: https://github.com/defold/defold/blob/editor-dev/editor/src/clj/editor/boot_open_project.clj#L179-L183 I think it makes sense for the You pretty much want to do the equivalent of triggering the relevant Perhaps it would even make sense to be able to trigger arbitrary Also of concern: For the editor to be able to see the changes saved from VSCode without it getting app focus, we'd want to call |
I'm starting to feel us editor developers need to get involved in this request as it might not be immediately obvious what I'm talking about to someone new to the code base. 😅 I'd love to hear your thoughts around the interface we expose to VSCode. Are there other commands you'd like to see exposed in the near future? |
Thanks, @matgis! That should be enough to start. I'm a little bit familiar with the editor code so overall it makes sense, but the part that executes context menu commands -> global defhandlers is Terra Incognito :) If I could manage to make it working then I might ask for more guidance. |
Sorry if I stepped on your toes, but I got a bit carried away and implemented part of it in this PR: #7382 Turns out we could just use the existing ui mechanism for triggering command handlers, which let us add this functionality in a separate file from I need to figure out a mechanism for integrating the external changes into our data model before it can be merged, but you might be able to play around with it a bit at least! |
Updated the PR to integrate the external changes into our data model before executing any command. It would be nice to have the UPnP discovery mechanism as well. |
The PR has been merged. Please play around with it and let us know how it works for you! Caveats: |
Wonderful! Thank you! @matgis do I need to run the editor from the dev branch or is there any chance to try it as part of 1.4.3-beta? |
As long as you are on the default
The documentation has more info around how to use it. |
Reading HTTP server port from log files on first call, then the port is saved. On Windows and Linux works great, can't test on Mac but should also be ok. I think that SSDP is not necessary atm. |
So, that means this ticket is done? |
I think we can close it. |
Is your feature request related to a problem? Please describe (REQUIRED):
When a developer uses an external code editor he has to switch back to the editor after every change he wanna test in the build.
That would be nice to have a possibility to ask editor read changes and build game without changing active window.
Describe the solution you'd like (REQUIRED):
The editor may receive a command from an external code editor using the editor's web server.
Describe alternatives you've considered (REQUIRED):
none
The text was updated successfully, but these errors were encountered: