elixir-plug / plug

Compose web applications with functions
https://hex.pm/packages/plug
Other
2.84k stars 582 forks source link

Wrong editor links when running inside a container #1239

Closed pehbehbeh closed 1 month ago

pehbehbeh commented 2 months ago

When running inside a Docker container, the path used to generate editor links to a file looks like this:

/app/path/to/file.ex

The file is actually located on my system under:

/Users/Phil/Documents/Code/myproject/path/to/file.ex

So all generated links by Plug.Debugger are broken in my editor. I have not found a way to customise the root path.

Possible solution: ENV variable

Maybe introduce a new ENV like PLUG_EDITOR_ROOT which could be set to /Users/Phil/Documents/Code/myproject in this case. By default the previous behaviour is used. Would be non breaking.

Possible solution: Placeholder

Introduce a third placeholder like __ROOT__ which is set to /app/ (previous behaviour) and can be omitted:

vscode://file/__ROOT__/__FILE__:__LINE__
vscode://file//Users/Phil/Documents/Code/myproject/__FILE__:__LINE__

This would be a breaking change.


I would be happy to discuss a solution and can also try to provide a PR.

josevalim commented 2 months ago

I don't think the placeholder would be a breaking change. Sure, it won't work on older versions and other places, but only if you use __ROOT__ and those places could be updated too. Isn't it correct? Could you please try a PR?

pehbehbeh commented 2 months ago

I think it would be breaking, because __FILE__ currently contains /app/path/to/file.ex. It would then only contain path/to/file.ex and users would have to add __ROOT__ (or an explicit value) to their PLUG_EDITOR to get the full path.

josevalim commented 2 months ago

We could introduce two new vars then? __RELATIVEFILE__ and __ROOT__?

pehbehbeh commented 2 months ago

Sounds good. Personally, I would then only need __RELATIVEFILE__ to configure PLUG_EDITOR as follows:

vscode://file//Users/Phil/Documents/Code/myproject/__RELATIVEFILE__:__LINE__

But it would certainly not be difficult to add __ROOT__ as well.

josevalim commented 2 months ago

Only the relative one works for me too. PR welcome!