Giter Site home page Giter Site logo

nvim-lspinstall's Introduction

logo

About

This is a very lightweight companion plugin for nvim-lspconfig. It adds the missing :LspInstall <language> command to conveniently install language servers.

The language servers are installed locally into stdpath("data"), you can use :echo stdpath("data") to find out which directory that is on your machine.

Isn't this something I should use my system's package manager for?

Installation

Via Vim-Plug

Plug 'neovim/nvim-lspconfig'
Plug 'kabouzeid/nvim-lspinstall'

The following is a good starting point to integrate with nvim-lspconfig.

require'lspinstall'.setup() -- important

local servers = require'lspinstall'.installed_servers()
for _, server in pairs(servers) do
  require'lspconfig'[server].setup{}
end

For a complete example you might refer to my personal configuration in the Wiki.

Usage

  • :LspInstall <language> to install/update the language server for <language> (e.g. :LspInstall python).
  • :LspUninstall <language> to uninstall the language server for <language>.
  • require'lspinstall'.setup() to make configs of installed servers available for require'lspconfig'.<server>.setup{}.

Advanced Configuration (recommended)

A configuration like this automatically reloads the installed servers after installing a language server via :LspInstall such that we don't have to restart neovim.

local function setup_servers()
  require'lspinstall'.setup()
  local servers = require'lspinstall'.installed_servers()
  for _, server in pairs(servers) do
    require'lspconfig'[server].setup{}
  end
end

setup_servers()

-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
require'lspinstall'.post_install_hook = function ()
  setup_servers() -- reload installed servers
  vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
end

Bundled Installers

Language Language Server
angular Angular Language Service
bash bash-language-server
clojure clojure-lsp
cmake cmake-language-server
cpp clangd
csharp OmniSharp
css css-language-features (pulled directly from the latest VSCode release)
dockerfile docker-langserver
elixir Elixir Language Server (elixir-ls)
elm Elm Language Server (elm-ls)
ember Ember Language Server
fortran Fortran Language Server (fortls)
go gopls
graphql GraphQL language service
haskell haskell-language-server
html html-language-features (pulled directly from the latest VSCode release)
java Eclipse JDTLS with Lombok
json json-language-features (pulled directly from the latest VSCode release)
kotlin kotlin-language-server
latex texlab
lua (sumneko) lua-language-server
php intelephense
puppet puppet-editor-services
purescript purescript-language-server
python pyright-langserver
ruby solargraph
rust rust-analyzer
svelte svelte-language-server
tailwindcss tailwindcss-intellisense (pulled directly from the latest VSCode extension)
terraform Terraform Language Server (terraform-ls)
typescript typescript-language-server
vim vim-language-server
vue vls (vetur)
yaml yaml-language-server
Name Description
deno https://deno.land/
diagnosticls https://github.com/iamcco/diagnostic-languageserver
efm https://github.com/mattn/efm-langserver
rome https://rome.tools/

Note: css, json and html language servers are pulled directly from the latest VSCode release, instead of using the outdated versions provided by e.g. npm install vscode-html-languageserver-bin.

Custom Installer

Use require'lspinstall/servers'.<lang> = config to register a config with an installer. Here config is a LSP config for nvim-lspconfig, the only difference is that there are two additional keys install_script and uninstall_script which contain shell scripts to install/uninstall the language server.

The following example provides an installer for bash-language-server.

-- 1. get the default config from nvim-lspconfig
local config = require"lspinstall/util".extract_config("bashls")
-- 2. update the cmd. relative paths are allowed, lspinstall automatically adjusts the cmd and cmd_cwd for us!
config.default_config.cmd[1] = "./node_modules/.bin/bash-language-server"

-- 3. extend the config with an install_script and (optionally) uninstall_script
require'lspinstall/servers'.bash = vim.tbl_extend('error', config, {
  -- lspinstall will automatically create/delete the install directory for every server
  install_script = [[
  ! test -f package.json && npm init -y --scope=lspinstall || true
  npm install bash-language-server@latest
  ]],
  uninstall_script = nil -- can be omitted
})

Make sure to do this before you call require'lspinstall'.setup().

Note: don't replace the / with a . in the require calls above (see here if you're interested why).

Lua API

  • require'lspinstall'.setup()

  • require'lspinstall'.installed_servers()

  • require'lspinstall'.install_server(<lang>)

  • require'lspinstall'.post_install_hook

  • require'lspinstall'.uninstall_server(<lang>)

  • require'lspinstall'.post_uninstall_hook

  • require'lspinstall/servers'

  • require'lspinstall/util'.extract_config(<lspconfig-name>)

nvim-lspinstall's People

Contributors

akinsho avatar alisonjenkins avatar ankurs47 avatar aotarola avatar aserowy avatar bashton-ajenkins avatar cigrainger avatar connorlay avatar jameswalmsley avatar jedimahdi avatar josemarluedke avatar jqno avatar kabouzeid avatar mordechaihadad avatar msricher avatar nogweii avatar notusknot avatar nryoung avatar polyzen avatar tapayne88 avatar thecontinium avatar viniciusmuller avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.