Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ require'lspconfig'.omnisharp.setup {
}
```

#### Mount Additional Volumes

You can mount additional volumes to let the lsp server access caches or other directories.

```lua
require'lspconfig'.rust_analyzer.setup {
cmd = require'lspcontainers'.command(
'rust_analyzer',
{
extra_volumes = {
'/home/[UserName]/.cargo:/root/.cargo:ro',
...
}
}
),
...
}
```

The property `extra_volumes` recieves a list of strings formated for the `--volume` option of Docker.
[See reference](https://docs.docker.com/engine/reference/run/#volume-shared-filesystems).

### Podman Support

If you are using podman instead of docker it is sufficient to just specify "podman" as `container_runtime`:
Expand Down
49 changes: 31 additions & 18 deletions lua/lspcontainers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ local supported_languages = {
local user = user_id..":"..group_id

if runtime == "docker" then
network = "bridge"
network = "bridge"
elseif runtime == "podman" then
network = "slirp4netns"
network = "slirp4netns"
end

return {
Expand Down Expand Up @@ -61,47 +61,53 @@ local supported_languages = {
solargraph = { image = "docker.io/lspcontainers/solargraph" },
sumneko_lua = { image = "docker.io/lspcontainers/lua-language-server" },
svelte = { image = "docker.io/lspcontainers/svelte-language-server" },
tailwindcss= { image = "docker.io/lspcontainers/tailwindcss-language-server" },
tailwindcss = { image = "docker.io/lspcontainers/tailwindcss-language-server" },
terraformls = { image = "docker.io/lspcontainers/terraform-ls" },
tsserver = { image = "docker.io/lspcontainers/typescript-language-server" },
vuels = { image = "docker.io/lspcontainers/vue-language-server" },
yamlls = { image = "docker.io/lspcontainers/yaml-language-server" },
}

-- default command to run the lsp container
local default_cmd = function (runtime, workdir, image, network, docker_volume)
local default_cmd = function(runtime, workdir, image, network, docker_volume, extra_volumes)
if vim.loop.os_uname().sysname == "Windows_NT" then
workdir = Dos2UnixSafePath(workdir)
end

local mnt_volume
if docker_volume ~= nil then
mnt_volume ="--volume="..docker_volume..":"..workdir..":z"
else
mnt_volume = "--volume="..workdir..":"..workdir..":z"
end

return {
local cmd = {
runtime,
"container",
"run",
"--interactive",
"--rm",
"--network="..network,
"--workdir="..workdir,
mnt_volume,
image
"--network=" .. network,
"--workdir=" .. workdir,
}

if docker_volume ~= nil then
table.insert(cmd, "--volume="..docker_volume..":"..workdir..":z")
else
table.insert(cmd, "--volume="..workdir..":"..workdir..":z")
end

for _, v in pairs(extra_volumes) do
table.insert(cmd, "--volume="..v)
end

table.insert(cmd, image)

return cmd
end

local function command(server, user_opts)
-- Start out with the default values:
local opts = {
local opts = {
container_runtime = "docker",
root_dir = vim.fn.getcwd(),
cmd_builder = default_cmd,
network = "none",
docker_volume = nil,
extra_volumes = {},
}

-- If the LSP is known, it override the defaults:
Expand All @@ -119,7 +125,14 @@ local function command(server, user_opts)
return 1
end

return opts.cmd_builder(opts.container_runtime, opts.root_dir, opts.image, opts.network, opts.docker_volume)
return opts.cmd_builder(
opts.container_runtime,
opts.root_dir,
opts.image,
opts.network,
opts.docker_volume,
opts.extra_volumes
)
end

Dos2UnixSafePath = function(workdir)
Expand Down