Skip to content

williamboman/lspcontainers.nvim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lspcontainers.nvim

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

Overview

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.

Installation

  1. Install latest Docker Engine for your operating system

  2. Install lspconfig and lspcontainers via package manager

  • via packer manager

    use 'neovim/nvim-lspconfig'
    use 'lspcontainers/lspcontainers.nvim'
  • via plug manager

    Plug 'neovim/nvim-lspconfig'
    Plug 'lspcontainers/lspcontainers.nvim'
  1. Setup the language of your choice from Supported LSPs

Advanced Configuration

Additional Languages

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.

Volume Syncing

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
}

Podman Support

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()),
}

Supported LSPs

Below is a list of supported language servers for configuration with nvim-lspconfig. Follow a link to find documentation for that config.

bashls

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()),
  ...
}

clangd

https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#clangd

require'lspconfig'.clangd.setup {
  cmd = require'lspcontainers'.command('clangd'),
  ...
}

dockerls

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()),
  ...
}

gopls

https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#gopls

require'lspconfig'.gopls.setup {
  cmd = require'lspcontainers'.command('gopls'),
  ...
}

html

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()),
  ...
}

intelephense

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()),
  ...
}

jsonls

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()),
  ...
}

omnisharp

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()),
  ...
}

powershell_es

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"},
  ...
}

pylsp

https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#pylsp

require'lspconfig'.pylsp.setup {
  cmd = require'lspcontainers'.command('pylsp'),
  ...
}

pyright

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()),
  ...
}

rust_analyzer

https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer

require'lspconfig'.rust_analyzer.setup {
  cmd = require'lspcontainers'.command('rust_analyzer'),
  ...
}

solargraph

https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#solargraph

require'lspconfig'.solargraph.setup {
  cmd = require'lspcontainers'.command('solargraph'),
  ...
}

sumneko_lua

https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#sumneko_lua

require'lspconfig'.sumneko_lua.setup {
  cmd = require'lspcontainers'.command('sumneko_lua'),
  ...
}

svelte

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()),
  ...
}

terraformls

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" },
  ...
}

tsserver

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()),
  ...
}

yamlls

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()),
  ...
}

vuels

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.

About

Neovim plugin for lspcontainers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 92.1%
  • Shell 7.9%