Neovim - LSP Setup

Install plugin ‘lspconfig’

If you use Packer

Put it inside vim config file:

1
use 'neovim/nvim-lspconfig'

Lua Language Server Configuration

Install (brew)

1
brew install lua-language-server

In any lua file or in a specific file that includes LSP configuration:

1
require'lspconfig'.sumneko_lua.setup{}
  • It activates LSP for lua files
  • You can check that LSP works for Lua files
    • Open any .lua file
    • type :LspInfo
    • You should see the line 1 client(s) attached to this bufer and Client: sumneko_lua

JavaScript/TypeScript Server Configuration

Install (npm)

1
npm install -g typescript-language-server typescript

Install (yarn)

1
yarn global add typescript-language-server

nvm

  • If you use Node Version Manager then typescript-language-server will be installed in the specific folder for the specific version of Node
  • For example for Node with version 18.7.0 it will be in the path $NVM_DIR/versions/node/v18.7.0/lib/node_module/typescript-language-server
  • Important!: ensure the server is executable from the command line (just type typescript-language-server and it should be available)

Pre-installing language servers by nvm and npm/yarn

  • Some of the language servers are available as npm packages
  • They can be installed by npm or yarn
  • You can specify the list of language servers that will be installed every time when you install node by nvm

The list should be in the special config file that is available on the path:

1
$NVM_DIR/default-package

An example of file default-package:

1
2
3
typescript-language-server
pyright

There can be any npm packages, not just language servers.

Subscribe to the newsletter

Get a once-per-week email with my latest content. By subscribing to this newsletter you will also be the first to receive last updates of my eBooks and courses.

0 members

Comments 💬