Why Language Server Protocol (LSP) is extremely powerful
Most code is read and not written. As Uncle Bob Martin says, “the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code.”
On why language servers are so useful
It’s all about the navigation
Ever work in an enterprise project where there are source files that are several thousand lines long? It often becomes a massive pain to navigate those files within a traditional text editor like vim.
Operations like Go to Definition and Peek references are essential to navigation. Why bother with a CMD+F when a simple right click will do?
Intellisense is amazing it’s like autocomplete for programmers
In an enterprise project, there could be thousands of symbols. Having a type-sensitive symbol suggestion list is simply amazing because otherwise we will be scratching our heads to remember the exact symbols and their spelling.
On being a master at creating language servers
Parsing is hard
The truth is that building parsers is often perceived as an expensive process. In the rush to create language servers often it is common to use the parser from the compiler. However, compilers are typically built without a regard for incremental approaches and without the robustness needed for advanced IDE work. A compiler simply has to check if the code is in or not in the language. An IDE tool needs to keep on chugging even if the program is incorrect.
Tools like tree-sitter are arguably the bleeding edge of parser generators.z
In general, expect to fiddle faddle with grammars for weeks if not months. Be patient it’s a virtue. However, a good thing to know is that correctness is not fully expected. We are not building a compiler. It is okay to make some mistakes.
Performance is important
Users expect to recieve their content assist suggestions quickly. Caching is something LSP developers should always keep in mind.