LSP Explained (in 5 Minutes)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the five W's of LSP who when what where and why the who is that it was created by Microsoft originally with red hat and code Envy the primary stakeholders today are Microsoft and VSS code originally it was open sourced in June of 2016 but I would say that it really caught its stride in around 2020 when most languages that are coming out it's somewhat of a requirement that they have an LSP or some viable LSP in the ecosystem we've even seen that LSPs now become a standard part of the runtime of some languages which is really interesting as well what is language server protocol LSP language server protocol is sort of a specification for saying how does an editor which from henceforth we will call client and a server communicate to each other to tell them about the state of the current project any errors going on with the project or how to navigate between the project and even things like autoc completion where does it happen it happens in your editor I okay I get this one's a bit of a stretch but I needed to stick with my theme all right so where does it happen in your editor a language server is generally some external process either a binary like rust analyzer or go PLS or perhaps something that's executed by your language runtime like TS server which is executed by node that communicates with the client which is your editor usually your editor will spawn that process by itself so that needs to be installed separately or through some plugin and then it will own that process for the lifetime of the editor session so once the editor is closed then that LSP will also be closed so it sort of owns the entire life cycle of that program an example of how this would work is in a notification where you have something like hey I've changed the contents of the file your editor needs to let the server know that because you would want the state to be updated before you save the the file right as you're typing you don't want a save to happen in between each keystroke what you'd like is for the keystrokes to be sent as they happen to the server so that the server can have an instant look into what's going on inside the editor a message might look something like this where you see a method with text document did change for example some params of I'm opening this file and this is the current version and here's the content changes that I'm going to be adding to the file a request an example of request might be hey please tell me where this thing is defined so that would be sending a text document definition request from your Editor to the server and the server would reply with a location so for example that might look something like this where you say hey I'm sending this request I'd like the definition I'm currently in this file and in this particular position and the language server might respond with something like hey you actually want to go to this definition file and here's the start and end rate range of that definition servers can also send notifications to the client to let you know that maybe a build failed or that there's some type error inside of your code that might look something like a server sending this message where it says that it's publishing Diagnostics with a certain list of Diagnostics and the files associated with those Diagnostics why go through all of this work well the primary thing that LSP is fixing is that previous to LSP the primary way that a editor would add support for a language is writing some custom Plug-In or even a complete custom Editor to provide information that we normally take for granted right now you know going to definition or finding references auto complete all of these language intelligence features an editor would have to write an entire plug-in for that and on the flip side a language if it wanted support would need to try and build that for each of the editors that it would like for people to use and generally speaking languages like when more people use their language so they would be pushed to do that for a lot of editors this creates an M byn problem which is a lot of work for both editors and language maintainers the goal of LSP is hey what if we could just create a specification so that editors just have to say here's how we're going to handle and emit these messages and languages could have some way of saying hey here's how we handle and emit these messages and then now it's just at least roughly an m plus n problem right editors only have to do the work once languages only have to do the work once and you instantly have support for both any editor or language depending on you know whose perspective you're looking at and that's why we have LSP but what you might ask is everyone says what's LSP but no one ever asks how's LSP right and in that case I would say it seems to be doing quite well these days thanks everybody hope you enjoyed the video bye oh don't forget to smash the like button and subscribe of course and leave a comment if you thought anything was really cool I'd love to cover another topic for you bye
Info
Channel: TJ DeVries
Views: 40,127
Rating: undefined out of 5
Keywords:
Id: LaS32vctfOY
Channel Id: undefined
Length: 5min 5sec (305 seconds)
Published: Thu Feb 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.