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

Path mapping to support "Go to detention" inside Docker #59

Open
iJackUA opened this issue Apr 7, 2017 · 6 comments
Open

Path mapping to support "Go to detention" inside Docker #59

iJackUA opened this issue Apr 7, 2017 · 6 comments

Comments

@iJackUA
Copy link

iJackUA commented Apr 7, 2017

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 ?

@timmhirsens
Copy link
Owner

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.

@iJackUA
Copy link
Author

iJackUA commented Apr 10, 2017

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`

@e-kuzminov-md
Copy link

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).

@iJackUA
Copy link
Author

iJackUA commented May 23, 2017

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).

@lypborges
Copy link

lypborges commented Sep 22, 2017

@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.

@iJackUA
Copy link
Author

iJackUA commented Sep 22, 2017

@lypborges yes, autocomplete still works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants