defold icon indicating copy to clipboard operation
defold copied to clipboard

Configurable port for Editor HTTP API

Open selimanac opened this issue 1 year ago • 5 comments

Editor HTTP API is a great solution especially for 3rd party IDE integrations. I would like to use it with Sublime Text(or vscode)

Currently its port is random and there is only way to get the random port of the Editor's http-server is by looking at console output. There is a workaround, but it is problematic and it is not a proper solution.

it would be perfect, if the port number can be configured from editor’s preference window or before the Editor lauch(maybe by passing a param to Editor). But of course it requires a port check before starting http-server. If the port is in use it might use a random port

selimanac avatar Mar 29 '24 08:03 selimanac

Taking into account that the user may have multiple editors running, I don't think it's the best solution to have a single predefined port in the preferences.

Isn't it a common practice to write a randomly generated port into a file at runtime so that local services know how to communicate?

In our case, it could be a file in the build or .internal folder, like:

project/build/*
or
project/.internal/*

with a filename such as port, editor_port, or editor_service.

AGulev avatar Oct 07 '24 15:10 AGulev

Taking into account that the user may have multiple editors running, I don't think it's the best solution to have a single predefined port in the preferences.

Fair point, can't argue.

with a filename such as port, editor_port, or editor_service.

Yes, why not. In this case IDE(Sublime Text, vsCode etc) can read this file from this folder and set it. But the problem of multiple editor is still exist. How do we know which editor is using which port(or do we have to know)....

selimanac avatar Oct 07 '24 15:10 selimanac

Yes, why not. In this case IDE(Sublime Text, vsCode etc) can read this file from this folder and set it. But the problem of multiple editor is still exist. How do we know which editor is using which port(or do we have to know)....

Not sure if it makes sense to have two editors running for the same project, so if editor saves port into the project folder - it's unique for that session with the project.

AGulev avatar Oct 07 '24 16:10 AGulev

Not sure if it makes sense to have two editors running for the same project

I don't think that is a use-case we should cater to.

britzl avatar Oct 07 '24 18:10 britzl

The file /.internal/editor-port could also contain multiple lines if you have multiple editors open. I like the solution, it would make it possible to execute a build command from VSCode for us. 👍

koenbollen avatar Oct 07 '24 19:10 koenbollen

I also using external (vim). It would be great if i can trigger reload with http request, so when the file is saved, on_reload can be called.

arywindows avatar Aug 10 '25 10:08 arywindows

I also using external (vim). It would be great if i can trigger reload with http request, so when the file is saved, on_reload can be called. Please check https://github.com/defold/defold/blob/dev/editor/doc/http-api.md

AGulev avatar Aug 10 '25 10:08 AGulev

@vlaaad @AGulev I develop a small Sublime Text extension and works great so far. Thank you all

selimanac avatar Aug 10 '25 10:08 selimanac

@vlaaad @AGulev I develop a small Sublime Text extension and works great so far. Thank you all

Oh, I'd like to know more about this! Can you share something yet?

britzl avatar Aug 12 '25 21:08 britzl

Thanks for this! 👍 I'll get working on a VSCode extension at some point. 😁

koenbollen avatar Aug 13 '25 09:08 koenbollen

Thanks for this! 👍 I'll get working on a VSCode extension at some point. 😁

As I know it's already exist and buil using editor API, the only downside that it parse port from the editor logs

AGulev avatar Aug 13 '25 09:08 AGulev

Oh, I'd like to know more about this! Can you share something yet?

@britzl It is extremely primitive and can’t handle edge cases. Any “vibe coder” could do a better job :) It just checks the .internal/editor-port file in the project folder when the project is opened (instead, the file should be watched), then adds a port variable and calls the commands(build, hotreload) using curl. I might prepare a proper extension if I get the time and share it…

selimanac avatar Aug 14 '25 09:08 selimanac

Just a note, the file is called .internal/editor.port

vlaaad avatar Aug 14 '25 09:08 vlaaad

https://defold.com/manuals/editor/#editor-server

vlaaad avatar Aug 14 '25 09:08 vlaaad