coc.nvim to nvim-lsp
TypeScript(Node)を近いレベルで開発できそうなところまでnvim-lspで試した
使った主なプラグイン
code:vim
call dein#add('neovim/nvim-lspconfig')
call dein#add('williamboman/nvim-lsp-installer')
call dein#add('b0o/SchemaStore.nvim')
call dein#add('onsails/lspkind-nvim')
call dein#add('ray-x/lsp_signature.nvim')
call dein#add('tami5/lspsaga.nvim')
" call dein#add('j-hui/fidget.nvim')
call dein#add('petertriho/nvim-scrollbar')
cmp
code:vim
call dein#add('hrsh7th/nvim-cmp')
call dein#add('f3fora/cmp-spell')
call dein#add('hrsh7th/cmp-buffer')
call dein#add('hrsh7th/cmp-cmdline')
call dein#add('hrsh7th/cmp-emoji')
call dein#add('hrsh7th/cmp-nvim-lsp')
call dein#add('hrsh7th/cmp-path')
call dein#add('lukas-reineke/cmp-rg')
call dein#add('quangnguyen30192/cmp-nvim-ultisnips')
call dein#add('tzachar/cmp-tabnine', {'build': './install.sh'})
jsonls と yamlls のschema取得に使う
スキーマは取得できてるしHoverも見れるのに(GHAの?)YAMLでDiagnosticsで怒られる問題が残ってる
補完メニューをリッチにできる、主にnvim-cmpと一緒に使う
入力中にメソッドのシグネチャとかを常に表示できる、実際にコード書いてると邪魔になるかも
nvim-lspの標準より表示が綺麗だったり機能が強かったりするやつ、一部コマンドはnvim-lspじゃなくてsagaを使う
スクロールバーを出してその中でDiagnosticsの位置も表示してくれる、hlslensとの連携も出来て強い
cocよりよさそうなところ
cmpの独自補完メニューがとても強い
補完のマッチのハイライト表示が一番便利
補完候補の見た目もかなりかっこよくできる
borderを表示するPR取り込まれたらもっとよさそう
cmpのコマンドライン補完も強い
細かい部分についてはcocよりいい感じの挙動をしてくれるプラグインがありそう、玉石混淆
課題
tsserverとtypescript-language-serverの差でcoc-tsserverの挙動の方が慣れてる部分がいくつかあった
実際に開発に使うにはfzf-previewをnvim-lspに対応させないとダメ
あとはそこそこ必要なのだとtsnipとか、lightlineの表示とかも
慣れてないのもあるけど設定が面倒、新しい言語書くときに設定で毎回ある程度頑張る必要がありそう
以下がcocと似た感じで使えるように試してた設定
nvim-lsp
code:vim
nnoremap <silent> K <Cmd>call <SID>nvim_lsp_show_documentation()<CR>
nnoremap <silent> <Plug>(dev)a <Cmd>Lspsaga code_action<CR>
nnoremap <silent> <Plug>(dev)rn <Cmd>Lspsaga rename<CR>
nnoremap <silent> <Plug>(dev)n <Cmd>Lspsaga diagnostic_jump_next<CR>
nnoremap <silent> <Plug>(dev)p <Cmd>Lspsaga diagnostic_jump_prev<CR>
nnoremap <silent> <Plug>(dev)I <Cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <Plug>(dev)T <Cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> <Plug>(dev)q <Cmd>lua vim.lsp.diagnostic.set_loclist()<CR>
nnoremap <silent> <Plug>(dev)f <Cmd>lua vim.lsp.buf.formatting_seq_sync()<CR>
function! s:nvim_lsp_show_documentation() abort
execute 'h ' . expand('<cword>')
else
lua require('lspsaga.hover').render_hover_doc()
endif
endfunction
autocmd CursorMoved * Lspsaga show_cursor_diagnostics
lua <<EOF
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = false,
})
local lsp_config = require("lspconfig")
local lsp_installer = require("nvim-lsp-installer")
local lsp_saga = require("lspsaga")
require("lsp_signature").setup({ hint_enable = false })
-- require("fidget").setup()
require("scrollbar").setup({ handle = { color = "Comment" }, handlers = { diagnostic = true, search = true } })
lsp_saga.setup({
error_sign = " ",
warn_sign = " ",
hint_sign = " ",
infor_sign = " ",
diagnostic_header_icon = "",
rename_prompt_prefix = "> ",
})
lsp_installer.on_server_ready(function(server)
local opts = {}
opts.on_attach = on_attach
opts.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
if server.name == "tsserver" then
opts.settings = {
format = { enable = false }
}
end
if server.name == "eslint" then
opts.on_attach = function (client, bufnr)
client.resolved_capabilities.document_formatting = true
end
opts.settings = {
format = { enable = true }
}
end
if server.name == "jsonls" then
opts.settings = {
json = { schemas = require('schemastore').json.schemas() }
}
end
if server.name == "yamlls" then
opts.settings = {
yaml = { schemas = require('schemastore').json.schemas() }
}
end
server:setup(opts)
vim.cmd do User LspAttachBuffers
end)
EOF
endif
nvim-cmp
code:vim
lua <<EOF
local cmp = require('cmp')
local lspkind = require('lspkind')
cmp.setup({
snippet = {
expand = function(args)
end,
},
mapping = {
'<C-u>' = cmp.mapping.scroll_docs(-4), '<C-d>' = cmp.mapping.scroll_docs(4), if cmp.visible() then
cmp.confirm({ select = true })
else
fallback()
end
end,
},
sources = cmp.config.sources({
{ name = 'ultisnips' },
{ name = 'nvim_lsp' },
{ name = 'cmp_tabnine' },
{ name = 'buffer' },
{ name = 'rg' },
{ name = 'path' },
{ name = 'spell' },
{ name = 'emoji' },
}),
formatting = {
-- fields = { 'abbr', 'kind', 'menu' },
format = lspkind.cmp_format({
with_text = true,
menu = {
}
})
},
})
cmp.setup.cmdline("/", { sources = { { name = "buffer" } } }) -- Doesn't work with searchx
cmp.setup.cmdline(":", { sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } }) })
require('lspkind').init({
preset = 'codicons',
symbol_map = {
Text = " ",
Method = " ",
Function = " ",
Constructor = " ",
Field = " ",
Variable = " ",
Class = " ",
Interface = " ",
Module = " ",
Property = " ",
Unit = " ",
Value = " ",
Enum = " ",
Keyword = " ",
Snippet = " ",
Color = " ",
File = " ",
Reference = " ",
Folder = " ",
EnumMember = " ",
Constant = " ",
Struct = " ",
Event = " ",
Operator = " ",
TypeParameter = " ",
},
})