Neovim plugin for lspcontainers - developed weekly live at The Alt-F4 Stream on Twitch.
IMPORTANT: everything below is a work-in-progress and subject to change at any time
Provide a simple method for running language servers in Docker containers using neovim/nvim-lspconfig
. This plugin expects the same language server names from neovim/nvim-lspconfig
. See neovim/nvim-lspconfig/CONFIG.md for a complete list of servers.
-
Install latest Docker Engine for your operating system
-
Install
lspconfig
andlspcontainers
via package manager
-
via
packer
manageruse 'neovim/nvim-lspconfig' use 'lspcontainers/lspcontainers.nvim'
-
via
plug
managerPlug 'neovim/nvim-lspconfig' Plug 'lspcontainers/lspcontainers.nvim'
- Setup the language of your choice from Supported LSPs
You can add configurations to more languages my providing an image and the command to start the container by adding following options to lspcontainers commands:
NOTE: LspContainers makes no attempt to modify LspConfig. It is up to the end user to correctly configure LspConfig.
lspconfig.html.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = lspcontainers.command('html', {
image = "lspcontainers/html-language-server:1.4.0",
cmd = function (runtime, volume, image)
return {
runtime,
"container",
"run",
"--interactive",
"--rm",
"--volume",
volume,
image
}
end,
}),
root_dir = lspconfig.util.root_pattern(".git", vim.fn.getcwd()),
}
The cmd
option of the lspcontainers config also allows modification of the command that is used to start the container for possibly mounting additional volumes or similar things.
In some circumstances a language server may need the root_dir
path synced with the Docker container. To sync up the volume mount with the lspconfig's root_dir
, use on_new_config
:
local server = "sumneko_lua"
require'lspconfig'[server].setup{
on_new_config = function(new_config, new_root_dir)
new_config.cmd = require'lspcontainers'.command(server, { root_dir = new_root_dir })
end
}
If you are using podman instead of docker it is sufficient to just specify "podman" as container_runtime
:
lspconfig.gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = lspcontainers.command('gopls', {
container_runtime = "podman",
}),
root_dir = lspconfig.util.root_pattern(".git", vim.fn.getcwd()),
}
Below is a list of supported language servers for configuration with nvim-lspconfig
. Follow a link to find documentation for that config.
- bashls
- clangd
- dockerls
- gopls
- html
- intelephense
- jsonls
- omnisharp
- powershell_es
- pylsp
- pyright
- rust_analyzer
- solargraph
- sumneko_lua
- svelte
- terraformls
- tsserver
- yamlls
- vuels
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#bashls
require'lspconfig'.bashls.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('bashls'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#clangd
require'lspconfig'.clangd.setup {
cmd = require'lspcontainers'.command('clangd'),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#dockerls
require'lspconfig'.dockerls.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('dockerls'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#gopls
require'lspconfig'.gopls.setup {
cmd = require'lspcontainers'.command('gopls'),
...
}
require'lspconfig'.gopls.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('html'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#intelephense
require'lspconfig'.intelephense.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('intelephense'),
root_dir = util.root_pattern("composer.json", ".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#jsonls
require'lspconfig'.jsonls.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('jsonls'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#omnisharp
require'lspconfig'.omnisharp.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('omnisharp'),
root_dir = util.root_pattern("*.sln", "*.csproj", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#powershell_es
require'lspconfig'.powershell_es.setup {
before_init = function(params)
params.processId = vim.NIL
end,
on_new_config = function(new_config, new_root_dir)
new_config.cmd = require'lspcontainers'.command(server, {root_dir = new_root_dir})
end,
cmd = require'lspcontainers'.command(server),
filetypes = {"ps1", "psm1", "psd1"},
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#pylsp
require'lspconfig'.pylsp.setup {
cmd = require'lspcontainers'.command('pylsp'),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#pyright
require'lspconfig'.pyright.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('pyright'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
require'lspconfig'.rust_analyzer.setup {
cmd = require'lspcontainers'.command('rust_analyzer'),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#solargraph
require'lspconfig'.solargraph.setup {
cmd = require'lspcontainers'.command('solargraph'),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#sumneko_lua
require'lspconfig'.sumneko_lua.setup {
cmd = require'lspcontainers'.command('sumneko_lua'),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#svelte
require'lspconfig'.svelte.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('svelte'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#terraformls
require'lspconfig'.terraformls.setup {
cmd = require'lspcontainers'.command('terraformls'),
filetypes = { "hcl", "tf", "terraform", "tfvars" },
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#tsserver
require'lspconfig'.tsserver.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('tsserver'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#yamlls
require'lspconfig'.yamlls.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('yamlls'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#vuels
require'lspconfig'.vuels.setup {
before_init = function(params)
params.processId = vim.NIL
end,
cmd = require'lspcontainers'.command('vuels'),
root_dir = util.root_pattern(".git", vim.fn.getcwd()),
...
}
To contribute to LSPs, please see the lspcontainers/dockerfiles repository.