vscode-solargraph
vscode-solargraph copied to clipboard
Issue with Docker using VSCode Remote-WSL over WSL2
Hey there,
I'm developing a small Rails based API, current development environment consist on Windows 10, with Ubuntu 18.04 over WSL2, calling VSCode from inside the ubuntu shell, using the VSCode - Remote WSL extension.
I had this plugin working as intended for a couple days by setting up Solargraph settings to use an external transport and properly setting the solar daemon on a side docker service through docker-compose.
The problem is that it suddenly stop working, VSCode connects to solargraph daemon without problems, performs all the queries that it should do, Solargraph itselfs builds all the files and docs that it needs, but it's not returning any results when being consulted.
I have rebuilt everything, deleted .solargraph and .yard folders, reinstalled plugins and vscode, the only difference i can think of was that when it was working i had the 0.38.0 version, and updated to 0.38.2 yesterday.
This is the output of the solargraph service:
solar_1 | {"jsonrpc":"2.0","id":15,"result":[{"uri":"file:///home/mvilera/ambar/api/app/controllers/companies_controller.rb","range":{"start":{"line":0,"character":0},"end":{"line":34,"character":3}}}]}
solar_1 | [INFO] Server received textDocument/definition
solar_1 | [DEBUG] {"jsonrpc"=>"2.0", "id"=>16, "method"=>"textDocument/definition", "params"=>{"textDocument"=>{"uri"=>"file:///home/mvilera/ambar/api/app/controllers/companies_controller.rb"}, "position"=>{"line"=>0, "character"=>16}}}
solar_1 | [INFO] Sending response to textDocument/definition
solar_1 | [DEBUG] Content-Length: 192
solar_1 |
solar_1 | {"jsonrpc":"2.0","id":16,"result":[{"uri":"file:///home/mvilera/ambar/api/app/controllers/companies_controller.rb","range":{"start":{"line":0,"character":0},"end":{"line":34,"character":3}}}]}
solar_1 | [INFO] Server received textDocument/references
solar_1 | [DEBUG] {"jsonrpc"=>"2.0", "id"=>17, "method"=>"textDocument/references", "params"=>{"textDocument"=>{"uri"=>"file:///home/mvilera/ambar/api/app/controllers/companies_controller.rb"}, "position"=>{"line"=>0, "character"=>16}, "context"=>{"includeDeclaration"=>true}}}
solar_1 | [INFO] Sending response to textDocument/references
solar_1 | [DEBUG] Content-Length: 192
solar_1 |
solar_1 | {"jsonrpc":"2.0","id":17,"result":[{"uri":"file:///home/mvilera/ambar/api/app/controllers/companies_controller.rb","range":{"start":{"line":0,"character":6},"end":{"line":0,"character":25}}}]}
solar_1 | [INFO] Server received textDocument/hover
solar_1 | [DEBUG] {"jsonrpc"=>"2.0", "id"=>18, "method"=>"textDocument/hover", "params"=>{"textDocument"=>{"uri"=>"file:///home/mvilera/ambar/api/app/controllers/companies_controller.rb"}, "position"=>{"line"=>30, "character"=>32}}}
solar_1 | [INFO] Sending response to textDocument/hover
solar_1 | [DEBUG] Content-Length: 78
solar_1 |
solar_1 | {"jsonrpc":"2.0","id":18,"result":{"contents":{"kind":"markdown","value":""}}}
solar_1 | [INFO] Server received $/solargraph/checkGemVersion
solar_1 | [DEBUG] {"jsonrpc"=>"2.0", "method"=>"$/solargraph/checkGemVersion", "params"=>{"verbose"=>true}}
solar_1 | [INFO] Server sent window/showMessage
solar_1 | [DEBUG] {:type=>3, :message=>"The Solargraph gem is up to date (version 0.38.2)."}
And this is my docker-compose:
version: '3.5'
volumes:
postgres-data:
services:
webapi:
build:
dockerfile: Dockerfile
context: ./
ports:
- 3000:3000
- 35729:35729
environment:
RAILS_ENV: development
volumes:
- ".:/home/app-user"
depends_on:
- db
user: "1000:1000"
command:
- /bin/sh
- -c
- |
[ -e tmp/pids/server.pid ] && rm tmp/pids/server.pid
bundle exec rails s -b 0.0.0.0
db:
image: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
solar:
build:
context: ./
dockerfile: Dockerfile
command: bundle exec solargraph socket --host=0.0.0.0 --port=7658
environment:
RAILS_ENV: development
volumes:
- ".:/home/app-user"
ports:
- "7658:7658"
depends_on:
- webapi
- db
The only thing that i notice is that the request sends the filepath on the WSL environment, and on Docker it has another path for the same file, perhaps the solargraph data library can't find a match due to that.
The only thing that i notice is that the request sends the filepath on the WSL environment, and on Docker it has another path for the same file, perhaps the solargraph data library can't find a match due to that.
I think your diagnostic is correct. A workaround (no idea how limited it is, I think @castwide can shed some light here) is to create a symlink inside your container /home/mvilera/...
-> /home/app-user
. The idea is solargraph will be receiving queries saying "the file is /home/mvilera/...", which it can't find normally but, because of the link, it will.
@castwide Do you see a way this workaround would fail? If not, maybe we could include some config:
...
solargraph.dir: "/home/something/in/container"
...
defaulting to $(dirname pwd)
, and then, inside solargraph, interpret queries with file:/path/to/app/some/file
as $(solargraph.dir)/some/file
? Would that make sense?
My workaround was something like this:
solargraph:
image: ruby:2.7.5-slim-buster
command: solargraph socket --host=0.0.0.0 --port=7658
working_dir: $PWD
volumes:
- .:$PWD:cached,rw
ports:
- 7658:7658
This would map the local folder using its full name.