CoC vs native LSP (mason/lspconfig) #4866
-
I've been wandering around Reddit and some other forums and I noticed some experienced NVIM users prefer using native LSP (through mason/lspconfig) instead of CoC. I personally don't see why someone would spend days/weeks messing with native LSP configs instead of using this batteries included software (CoC) that takes care of all the automation of installing and running the LSPs in a non-conflicting way. I use Python mainly so it's super handy to have CoC take care of running mypy/black/pyright all together for me, as well as being easily configurable (python bin path, etc) via I'm opening this discussion mainly to know what @fannheyward thinks about those arguments against CoC, and what you think about this recent preference some devs are developing towards native LSP. Do you think there's any real advantage or is it the old "blue vs red" debate, where it's just a matter of preference instead of actual issues/limitations. References: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
I find |
Beta Was this translation helpful? Give feedback.
-
First of all, thank you for your question @yuriescl! I really don't like the comparison, or those arguments against CoC. Every time I saw posts like "native LSP is better than CoC" or "changed to native LSP because of xxx", I just check the downside of CoC they were talking about, to see if something can be improved in CoC. I'll try to explain my thoughts on this topic, in my personal opinion, why I'm still using CoC and spending time on CoC and extensions.
The main difference between CoC and native LSP is, how to talk with language server:
In quick words, native LSP reduced one more RPC request, should be faster than CoC. It's true with some language servers. But I don't think it's a big deal, because the RPC request is very fast, and the language server is the bottleneck. I'll explain why it's not a big deal below. In CoC, vimL parts (with some Lua too) core task is UX rendering (includes UI highlighting, responding to user interaction, floating windows, etc). We have a separate node process to talk with LS. The process will send requests to LS, receive responses, parse/decode the JSON body, sort or filter the completion results, and notify vimL parts to render UI. The language-client codes are ported from The nvim's native LSP client does all the things UX rending and LSP requests handling, in one place. It's fast with LuaJIT but not perfect in some cases. For example, some LS will result in thousands of completion items in JSON, the decoding work will slow down user's UI. (nvim already added Another example is telescope-nvim vs fzf.vim(fzf-lua), they both use Besides LSP client, coc.nvim node process provides an extension host, you can write extensions in Node.js with the same/similar APIs as VSCode extensions, or non-LSP related extensions like For the slowness, the most intuitive experience is the latency from user input to completion items popup. coc.nvim waits for a delay of I wrote some pros of coc.nvim, nvim's native LSP client has some pros too:
The last part, Lua and nvim configuration in Lua. Lua is a full-featured programming language than vimL, more readable and maintainable. It's a great experience to write plugins in Lua, especially since nvim makes it first-citizens language, provides more native Lua APIs. But Lua is not designed as DSL to do configuration. I use several Lua plugins but still setup nvim with vimL. I see people move their Thank you for reading, my own two cents. |
Beta Was this translation helpful? Give feedback.
-
I think one reason people prefer to use built-in LSP is that it provides lsp apis or hooks to customize their neovim features. This aspect, compared to coc.nvim, gives a more Vim-like feeling of being able to customize everything you want (even though they can't really customize everything). As for performance and speed, I've never felt any practical difference when comparing the lsp speed between builtin and coc.nvim, so I don't think performance and speed are key factors in this comparison. Leaving aside the part about LSP, I also prefer to use coc for developing my own plugins. For me personally, I also like to develop some personal plugins, including those for coc, Lua, and VSCode. Based on my experience in plugin development, working with untyped languages like JavaScript and Lua gives me a feeling that the code I write is 'dangerous'. So, regardless, I find typed languages to be superior to untyped ones. Lua is great, but it's not for me. I'm only willing to use it to configure my nvim settings rather than to actually develop a plugin with it. One of my interests is porting plugins from VSCode to nvim, and coc makes this task much simpler. This is perhaps the biggest reason why I use coc :) |
Beta Was this translation helpful? Give feedback.
-
I'm also seeing those comments and, for the life of me, cannot understand how / why anyone would prefer nvim LSP or vim-lsp over CoC. Besides getting all of the great tooling out of the box with CoC, it's just so much faster! |
Beta Was this translation helpful? Give feedback.
First of all, thank you for your question @yuriescl!
I really don't like the comparison, or those arguments against CoC. Every time I saw posts like "native LSP is better than CoC" or "changed to native LSP because of xxx", I just check the downside of CoC they were talking about, to see if something can be improved in CoC.
I'll try to explain my thoughts on this topic, in my personal opinion, why I'm still using CoC and spending time on CoC and extensions.
The main difference …