 So, yeah I am PM Sahu and I am a software engineer working at the Ansible DevTools team from Red Hat India. So, for the next 10 to 12 minutes I will be talking about what actually a language server is and how does it actually work then we take a look at the fact that why do we need a language server today and now and after that probably we will just I will just show some steps so that we can learn how to build our own language server. Finally, I will conclude and just before concluding I will just give you a code walkthrough and a small demo of a small language server again. So yeah, what is language server and how does it work? So a small question, have you ever imagined working on a code editor that does not understand the programming language you are working on? Probably not because today as the complexity is increasing we cannot imagine working in a code editor that does not provide autocompletion for us, maybe linting for us, syntax highlighting, hovering, go to definitions etc. And all these features that I explained are known as language services for a programming language. Now traditionally what used to happen was someone had to develop an extension for a programming language per code editor to support that particular programming language in that particular editor. And you can imagine how time consuming it is and to support different editors one had to repeat the same underlying logic again and again but with the different APIs because every tool provides different APIs and this is where language server comes into picture back in 2015 Microsoft along with Red Hat came up with the idea for the language server protocol. What actually is a language server? Language server is basically a tool that provides all these language features in a decentralized manner. There is this tool, those are the extensions which can directly communicate with the language server and can give you the results. This is a clear example that shows that this is the first example that explains how this thing works without a language server. Basically, if I want to support Python for VS code, Atom and Wim, I'll have to develop all the three extensions for these three editors. But now what happens is with the language server, if I want to support Python, I would just need to create one language server and all these three tools would have the would have tools or libraries that would communicate with the language server and there you go. You get all the language features. Moving ahead, just a small introduction about how this particular thing works. So we have a development tool that is the IDEs and the extensions and the other hand we have the language server, the language server basically. Now when the user opens a document, a notification for did open is sent to the language server and when the user starts typing something or starts editing the text document, it sends a notification called did change. And now let's say we want to provide diagnostics when some when user starts writing. So now the server sees that the diagnostic provider has been registered in the did change life cycle. So it analyzes, creates the diagnostic reports and sends back to the extension. The same goes with the go to definitions, the auto completions and the hoverings that things would be much more clear when I show you the code. So I'll just proceed. Yeah, now before moving further, just wanted to clarify some differences. There are three terms, language server, the language client and the language server protocol. Basically, what is the language server? As I explained, this is the tool where you define all the language capabilities and write the logic and basically like the logic for the providers. What's the language client? This is the code editor that communicates with the language server and leverages the services. The language server protocol, that's the set of rules that governs the communication between the server and the client, which is basically based on the JSON, RPC request and response mechanism. So yeah, now comes the important question. Why do we actually need to learn language server today? So obviously the very first two points are clearly if you have your own custom programming language or a scripting language, you will definitely want to create a language server for that so that other people can use it with ease. The second is again, if you are working on a code editor and you want to support some important programming languages, just go get an extension, build an extension that could communicate with the existing language servers. But for the last two days, I was there in FOSS Asia and I have just recently noticed a lot of you guys have developed projects and almost all of them require some sort of a configuration file for that project to work. And this is where I find the importance of language server comes into picture. For example, you're working on a project and you need a set of configuration files that the user needs to type in so that he or she can actually work on that project. You can actually write language features particularly for that particular config file so that the user will be able to easily adapt to the configuration settings and can work accordingly. And for this part, I'll be demoing this particular example with the Ansible config files. Yeah, let's quickly go ahead and see how you can build your language server. Basically, first of all, choose an SDK. You don't need to rely on the internal workings. How you send a notification, how you receive a notification, you don't need to know that. Just go pick an SDK and there's a huge set of SDKs that are available. You can just go and based on your programming language, you can choose one. Next, choose the tool. For example, if I want to develop an extension, I would go ahead and use the VS Code tool and I would like to and I will start the development of the extension. Next, structure the project. You know, while starting the language server, it's very small, but as you grow, the code complexity increases. So it's better. It's a very good idea to structure the project and then finally define the language capabilities in the server. And in the client side, it's just a matter of initializing the server. This is how I like to structure the project. I have a client, I have a server and the extension.ts is the place where I initiate the language server and now comes the server part. We have a server.ts file. This is where I actually push in the provider logic at a particular event cycle. And then I have providers like completion provider and the validation provider. List can go on the definition provider, however, providers, etc. And then some utility files if you have some. Okay, now we'll move to the code and I can show you some good stuff here. So let me switch to the VS code and here. So initially I was talking about the event cycle. So this is how the event cycle works. So we have something called connection dot on completion. You just read register your logic for the completion provider in this particular, in this particular piece of code. For me, it is do completion. And then there's a complete, there's an again, an event cycle called as on completion resolve where I would like to return do completion resolve. Particularly do completion and do do completion reserve are my custom functions that I've created and the logic that I've written over there. Now there's something known as on date change. Let me find that out. Yeah, on date change. And as I said you I would like to validate a particular document when something changes in the document. So I just call validate text document on this particular part. And this is how the code is and that should work. And just a small demo. So we have an Ansible config file over here and this is how it looks without the language server. It's very hard to identify if there are some mistakes or not. And if you want to type something, we actually don't get a feedback and I don't know what could go inside this particular section. But now we'll see this with the with the language server. Now the language server is activated for this file and I already can see some results over here. The first quickly line says that yeah, this is an unknown option. So I need to verify that and I know it's debug. There you go. This is correct. And this says there's an unknown tag known as unknown option known as tag. I need to correct it, but I know it is tags. I'll do this this week. And now to demo some auto completion and I start typing. It tells me there's no suggestion. That means I have no other options available here. But inside default, if I come and start typing, I get all the available options inside default. And now what's even interesting is it is context aware. After a gap line, if I ask for auto completion, it knows that this is a section and there you go. The completion works this way. And now when I'm in Jinja, I know there's one option, particularly in that particular section. I get the auto completion here as well. So this is how the auto completion works. And yeah, probably I will end. And before concluding, I would just like to add one more small thing over here. Yeah, so how successful is a language server, basically? I can tell you the success of this because I am the author of the Ansible language server and the VS code extension. And within the past 1.5 years, there have been around 330 plus K downloads in the marketplace and 46,000 downloads in the open VSX repository. Talking about the language server particularly, this already Ansible extension made for the Emacs and the NeoVim editors using our language server. So this is the power of open source and I hope in my presentation I was able to convey the importance as well as it could act as a starting guide for someone who would like to develop a language server. So thank you. Any questions? Very nice session. One question, though. How are multiple versions handled? Next is an example. I have version 1, and say in version 2, there is some feature which is removed. Now, again, that change will need to reflect in the language server, right? Even for my usual development as an example, OK. Some syntax was valid for version 1, but it's no longer valid for version 2. So how are the versions controlled? So there's nothing fancy that is going on over here. For example, if I can understand correctly, while using this particular thing, I have something called as always that let me find that out and simple config options. Let's say in the new version. I don't have this particular option for me. Agnostic become prompt. It's just a matter of fact that I would need to remove that particular thing from here. And that's how you don't need to change anything. But if you develop your code in such a way where you have one single source of truth for all the facts that the language server can particularly use, you just need to modify that particular file and the rest of things would be taken care of. I hope this answers your question. Thank you.