vscode-elixir
vscode-elixir copied to clipboard
Path mapping to support "Go to detention" inside Docker
Is it possible somehow to specify path mapping between container FS and Host FS?
Because currently if I develop locally using Docker containers Erlang/Elixir by itself and my source code are placed inside the container.
VSCode is installed on my host machine (not inside the container).
_build
folder and .beam
files are exposed via FS sharing to host.
So VSCode can see .beam
and I suppose that allows Autocompletion - stdlib modules and my code is autocompleted by VSCode. But Go to definition does not work.
I suppose it because the internal of .beam
files that have path information according to Docker container root folders, but VSCode attempts to find the same path on my Host machine.
For example Ecto module in iex
inside the elixir 1.4 docker image
iex(1)> i Ecto
...
Module bytecode
_build/dev/lib/ecto/ebin/Elixir.Ecto.beam
Source
deps/ecto/lib/ecto.ex
and my local host machine Elixir installation shows
iex(1)> i Ecto
....
Module bytecode
_build/dev/lib/ecto/ebin/Elixir.Ecto.beam
Source
/www/deps/ecto/lib/ecto.ex
Also I suppose that /www
is because my working_dir
in docker-compose is set to /www
. And it is saved after compilation.
I am not sure I investigated in correct direction, but maybe it possible to specify (in extension settings) this "path prefix" to do correct path resolution on the host machine ?
Interesting setup. Can you maybe open up the developer console in vscode (via the "Help" menu) and try a few go to definitions and make a screenshot / copy of the log output?
An example docker-compose file may also be of interested so that i am able to reproduce the use case.
I am so glad you are interested :)
I have created a test repo with minimalistic MIX app https://github.com/iJackUA/vscode-elixir-docker-test And I have put in README steps to reproduce and expected results.
As for DevTool console, here is output I can trace (with those test project)
On Host machine (Hover + Cmd + Click redirects to correct Definition)
**Hover**
[Extension Host] [vscode-elixir] cmd: DOCL { "NewModule.call_me", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", 16 }
**Hover + Cmd**
[Extension Host] [vscode-elixir] cmd: DEFL { "NewModule,call_me", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", 16 }
[Extension Host] [vscode-elixir] cmd: DOCL { "NewModule.call_me", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", 16 }
**Hover + Cmd + Click**
[Extension Host] [vscode-elixir] cmd: DEFL { "NewModule,call_me", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", 16 }
[Extension Host] TextEditor disposed
On Docker (Hover + Cmd + Click DOES NOT redirects to Definition)
**Hover**
[Extension Host] [vscode-elixir] cmd: DOCL { "NewModule.call_me", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", 16 }
**Hover + Cmd**
[Extension Host] [vscode-elixir] cmd: DEFL { "NewModule,call_me", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/lib/vsctest.ex", 16 }
**Hover + Cmd + Click**
the same as for `Hover + Cmd`
I am not experienced in VSCode extensions development, but locally I did a proof of concept "hack" in https://github.com/fr1zle/vscode-elixir/blob/bffea3539ccfd605dfc62729551d86fd886ba153/alchemist-server/lib/api/defl.exs#L118
Added string replace
case module.module_info(:compile)[:source] do
nil -> nil
source -> List.to_string(source) |> String.replace("/www", "/Users/ievgen/Projects/Elixir/vscode-elixir-docker-test/")
end
And now in my test project it seems that Go to definition works in both cases with local compile and Docker compile.
But this solution requires a maintainer love :) As it involves adding a Workspace settings params (and I see that this ext does not have any settings yet) and generalizing this fix from hardcode to settings param usage (or ignoring if it is set to default).
Hint for this who struggle because of the same issue. Temporary and the most less obtrusive way to do a hardcode fix, create a local symlink (for the case explained abowe)
sudo ln -s /Users/ievgen/Projects/Elixir/vscode-elixir-docker-test /www
Just set you paths. Now VSCode while trying to access source codes in /www folder get forwarded to real sources via symlink and all Go to Definiton request now works as expected (and yes you will need to recreate symlink for each project or create a set of unique folder names).
@iJackUA your autocomplete is working with this setup? I have a phoenix project inside a docker and the VSCode in my host machine. But the autocomplete doesn't work for me.
@lypborges yes, autocomplete still works for me