Installing LSPs with Mason
Mason is a package manager that runs inside of Neovim and installs various Neovim-related dependencies on your system. Here's how to configure it to install language servers for you.
Hey there! I’m Nat Bennett, and you’re reading my Neovim newsletter, a bi-weekly-ish note where I try to share something useful about Neovim or Neovim configuration.
If you’ve been finding the newsletter useful, please share it with your friends! Your friends will get gentle encouragement to use Neovim (and use it more effectively) and I’ll get sweet, sweet new reader dopamine. It’s win-win.
This week I finally broke down and set up Mason. Mason is a package manager that runs inside of Neovim and installs various Neovim-related dependencies on your system. This struck me as deeply suspicious — I’m the kind of person who installs absolutely everything on my system through Brew or by compiling it myself from source — but then I tried to install the Go LSP and, man. In theory I know how to install Go binaries. In practice, what the hell is a $GOPATH?
So I gave Mason a shot and it worked the first time I tried. Here’s the relevant diff adding it to my config.
If you just want the grab ‘n go version, here are the lines to add to your list of Lazy packages:
{ "williamboman/mason.nvim" },
{ "williamboman/mason-lspconfig.nvim" },
And here’s the relevant config to set up Mason itself
require("mason").setup()
require("mason-lspconfig").setup()
Finally to automatically install whatever packages you want
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls" },
}
Add whatever language servers you want from the officially supported list and in theory it “just works.” (I’ve heard that these instructions are not at all sufficient if you’re using BSD.)
You can also install servers by hand using the :LspInstall
command but this makes me break out in hives and I don’t recommend it. Check your config into source control, folks.
Note that these instructions assume that you’re already configuring installed language servers. (I’ve written about this kind of incidentally but don’t have an up-to-date “this is the way” guide for just language server configuration yet, partly because my understanding of how to do this keeps evolving as I add more features to my config.)