Introduction to Language Server Protocol (LSP)

Wathsara Wishwantha Daluwatta
3 min readOct 16, 2019

--

Have you ever worked with IDE for programming languages like Java, Javascript, Typescript, etc? How easy it is now? You get suggestion (autocompletion) from IDE, provide definitions for the functions, suggest error fixes and it provides many more features. So simply we can say IDE help a lot for fast and easy coding.

Well, If IDE provides this much of a feature, who is this language server protocol?

Language Server is meant to provide the language-specific smarts and communicate with development tools over a protocol that enables inter-process communication. This is what Microsoft is saying about the language server. In simply we can say when you are writing a programing code, IDE connects with the language server and it provides all those specific features of the language to the IDE. So you get the completion items, you get error suggestions and IDE so friendly for programmers. All these are because of the language server.

There are three main components involved in the process of language server.

  • Client — development tool (IDE)
  • Communication — JSON RPC
  • Server — Language server

HOW?

  • The user opens a document. The IDE notifies the language server that the user opened a document.
  • The user edits the document. The editor notifies the server about the document changes. The language server analyses this information and notifies the IDE with the errors and warnings that it has found.
  • The user requests some specific commands. The user asks for a definition of a symbol, completion of a text from the current cursor position, etc. The editor sends the proper request to the server which response accordingly. The editor can then use this information to satisfy the request of the user.
  • The user closes the document. The editor notifies the language server that the user closed a document.
(https://microsoft.github.io/language-server-protocol/img/language-server-sequence.png)

I hope you guys have some sort of an idea about what LSP is and how it works right? But why we need LSP?

Just imagine we have M number of programming languages and N number of IDEs. NO LSP lets the work of M * N (Look at the image below). To solve this problems, Microsoft specified Language Server Protocol which standardizes the communication between language tooling and IDE. This leads to some major advantages as they communicate with the IDE through the Language Server Protocol. As an example, Language Servers can be implemented in any language and run in their own process to avoid performance cost.

https://code.visualstudio.com/assets/api/language-extensions/language-server-extension-guide/lsp-languages-editors.png

Hope you learn something from here. If you need to learn more about language server protocol please refer the links at References.

Looking forward to see you guys soon with my next article. Have a Good Day!!

References

https://microsoft.github.io/language-server-protocol/overview

--

--

Wathsara Wishwantha Daluwatta

Software Engineer at WSO2 | Studied BSc (Hons) Software Engineering at University of Colombo School of Computing