nvim-lsp-installerからmason.nvimへ移行する
NeovimのLSPの設定支援プラグインとして人気だったnvim-lsp-installerの開発終了が発表されました。
nvim-lsp-installerwill no longer be actively maintained, meaning I won't be doing things like porting new mason.nvim packages to nvim-lsp-installer, monitoring lspconfig for changes that require updates, or put much effort into user support or bug issues (the recommendation for the latter will be to migrate to mason.nvim).
現在、同じ作者の後継プロジェクトであるmason.nvimへの移行が推奨されています。
移行手順
以下の公式discussionで移行方法が紹介されています。
まず:LspUninstallAllでインストール済みのLSPをすべて削除します。
(設定にensure_installedを入れている場合は一旦コメントアウトなどしておいたほうが良いと思われます)
:LspInstallInfoでInstalled serversが0になっていればOKです。

つづいてプラグインおよび設定を変更します。
以下の設定は、Info画面のアイコンを修正し、インストール済みのサーバーそれぞれにsetupを実行するサンプルです。
-で表示されている行はnvim-lsp-installerでの設定、+で表示されている行はmason.nvimでの設定を表しています。
mason.nvimだけでなく、mason-lspconfig.nvimもインストールする必要がある(参考)ことに注意してください。
Plug 'neovim/nvim-lspconfig'
- Plug 'williamboman/nvim-lsp-installer'
+ Plug 'williamboman/mason.nvim'
+ Plug 'williamboman/mason-lspconfig.nvim'
lua << EOF
- local lsp_installer = require('nvim-lsp-installer')
- lsp_installer.setup({
+ local mason = require('mason')
+ mason.setup({
ui = {
icons = {
- server_installed = "✓",
- server_pending = "➜",
- server_uninstalled = "✗"
+ package_installed = "✓",
+ package_pending = "➜",
+ package_uninstalled = "✗"
}
}
})
local nvim_lsp = require('lspconfig')
- for _, server in ipairs(lsp_installer.get_installed_servers()) do
- local server_name = server.name
+ local mason_lspconfig = require('mason-lspconfig')
+ mason_lspconfig.setup_handlers({ function(server_name)
local opts = {}
opts.on_attach = function(_, bufnr)
local bufopts = { silent = true, buffer = bufnr }
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', 'gtD', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', 'grf', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>p', vim.lsp.buf.format, bufopts)
end
nvim_lsp[server_name].setup(opts)
- end
+ end })
EOF
なお、インストール済みのサーバーを一覧する方法はこちらのやりとりを参考にしました。
LSPのインストールや、ステータスの確認は:Masonで開くウィンドウから行えます。
:MasonInstall server_nameでもインストールが可能です(このあたりはnvim-lsp-installerで:LspInstall server_nameでLSPをインストールしていたのとほぼ同じですね)。

以上で移行完了です。
動作確認は:LspInfoで見ても良いですし、適当な入力をしてエラーメッセージを出してみても良いでしょう。

筆者の場合、nvim-lsp-installerの設定はほぼ全て流用できたので、特に問題なく移行できました。
nvim-lsp-installerの開発終了が予定されているので、折を見て移行しておくのが良いと思います。
注意点
masonでインストールするLSP名はリポジトリ名を用いているため、一部のLSPは名前が変わっています。
例: luaのLSPは:MasonInstall sumneko_luaではなく:MasonInstall lua-language-serverで導入するようになっています
ただし、mason_lspconfigを利用した設定では、これまでどおりの名前が使えます(参考::h mason-lspconfig)。
local nvim_lsp = require('lspconfig')
local mason_lspconfig = require('mason-lspconfig')
mason_lspconfig.setup_handlers({
function(server_name)
local opts = {}
if server_name == "sumneko_lua" then
opts.settings = {
Lua = {
diagnostics = { globals = { 'vim' } },
}
}
end
nvim_lsp[server_name].setup(opts)
end
})
Discussion