What the hell is NULL-LS | FREE COURSE // EP 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'm going to show you how to get some amazing neovim functionality with linters and formatters by the end of this video you'll be able to lint JavaScript files with es lint format your Ruby files with rubocop and more and the best part is you'll be set up to extend this functionality to whatever language you're working with easily we'll also be talking about null LS for neovim what it is and why it's so great or what's so great I'll explain let's get into it [Music] welcome back to neovim for noobs and everyone else really in this free series we've been creating a modern and modular neovim config that would rival any text editor or IDE before we get started with linting let's go over our config real quick so in the last few episodes we've put together an incredible config for our neovim setup if we open our config up in neovim we can see that we have Neo tree we have all kinds of goodies like telescope for doing fuzzy finding and also for grapping through our project and specifically in the last episode we gave ourselves some amazing features in neovim through its built-in LSP configuration we also went over what LSPs are and how they work so if you're interested check out the last episode in fact check out all the episodes because they're pretty cool but in our LSP config we can see that we have a three-headed setup right here with Mason Mason LSP config and neovim and Vim LSP config the way these work together is that Mason installs all of our LSPs Mason LSP config sort of bridges the gap between Mason and envm LSP config and also gives us the great insure installed property that we use right here to make sure that Lu LS and TS server are installed and at the end of the day we have some key maps that allow us to do certain things like hover over stuff for documentation and also doing code actions with space CA and we can see that we can Mark Vim as a defined Global if we want that is a code action so right now we have a really great configuration and I'm looking forward to extending it with some cool stuff so now we have some very powerful LSP features in our config but what about linting and formatting our code well there are plenty of tools that handle linting and formatting but they're kind of in an awkward spot you see linters and formatters like rubocop black or ES lint are all command line tools and aren't language servers in and of themselves and back in the day which was a Wednesday by the way we had more plugins to help integrate these tools into neovim specifically Al asynchronous linting engine and cooc do envm but these plugins required their own settings and they were kind of hard to manage so this is where null LS came into play null LS is an amazing plug-in that essentially wraps command line tools into a generalized LSP enabling easy communication between these tools and Neo's built-in LSP client so instead of installing different plugins to handle linting and formatting we could just use null LS to wrap our Tools in a generalized language server and everything else just looks like another language server to neovim sounds great right well there's just one problem null LS for various reasons has been deprecated by the Creator I mean we could just use null LS anyways but it ties in very closely to Neo's internals leaving it very open to Breaking from changes within neovim any merged PR by neovim core could break this plug-in so it's best not to use it if possible but a great alternative has been created in a plugin called non LS non LS is a community managed Fork of null LS and it looks like it'll be wellmaintained for a long time I love the idea of using NLS because as you'll see soon the syntax is very minimal for null LS and the API for formatting and linting are really clean because our tools get wrapped in an LSP so things just feel a lot easier to manage so let's get into it I'll show you what it looks like so we can see here non LS is a community managed Fork of null LS the thing about null LS is that it was so popular and the configuration was so simple that when the author deprecated this package everyone got together and recreated it essentially forking it and now they're managing it on their own and we can see here that there's tons of commits the latest commits were just a few days ago so it seems like this is going to be handled and maintained for a pretty long time and that's why I feel safe using non LS as a plugin here I think it's going to be really great and I'll show you what the syntax looks like it's pretty cool so let's go ahead and install nun LS now a funny thing here to look at is that nun LS doesn't rewrite any of the variables from null LS so essentially you're going to be calling null LS instead of non LS which is something to keep in mind it you get used to it pretty quick but just keep that in mind so let's install nonone LS we can go to our neovim configuration and look at our Lua plugins directory and we want to add a new file let's just call it nun ls. Lua pretty easy and in this file we want to return a new Lua table and this table is going to start with the short GitHub URL of non LS the plugin now we can see right here there's some very basic setup functionality here so let's go ahead and start off with that so our we want to set a local variable called null LS for our setup function but I remember now I have to put that in my config block right here and we can see all this LSP stuff is amazing I'm loving it and now we can call setup on our null LS variable here and let's add the initial formatter for this setup now null LS has a ton of built-in formatting Diagnostics and completion tools and we're going to start with Lua because obviously that's what we're writing our configuration in so let's set that one up first and I'll show you what it looks like so we want to set our sources to a table and initially we want to include null ls. builtins do formatting. style Lua I did not need a comma there I don't know why I did that now if we quit neovim and reopen it we can see that lazy is installing nonone LS of course that's what we expect now and null LS is complaining that it failed to load style Lua so let's reload our config oh I think I just misspelled it it's sty Lua yeah it's styu so let's close this reopen vim and if we go to none LS we can see we have our formatter probably running I can't really tell but so now what we have here is we have a formatting tool called style Lua that's going to be wrapped in a generalized LSP with null LS so that we can now call LSP functions to call the things that style Lua gives us almost like it's an LSP sort of like a pseudo LSP but there's one thing we're forgetting here we do not have style Lua installed on our system so we use Mason to install it Mason has a ton of LSP dap linters and formatters and style Lua is a formatter so we can navigate to style Lua in Mason and type I to install it and we can see up here that style Lua is now installed so let's quit Mason and let's continue setting up the rest of our stuff here so now the final thing we want is just to set a keymap right so we can do vm. keymap doset in normal mode and we want to set leader GF to call the vm. lp. buff. format function and what is this going to do well it's going to call format for the built-in LSP client for neovim so anything that could respond to format that's attached to this buffer will then format this file and now that we've installed style Lua through Mason and we've set up style Lua through null LS it should work things should communicate together fairly easily so let's quit our Neil Vim config reopen neim and let's go to our none LS configuration file so if we type leader GF we should see something happen let's see leader GF and you can see that we now have double quotes around all of our stuff instead of single quotes and it added a little comma to the bottom here so we are currently formatting everything with style Lua that's sick that was so easy wasn't that amazing let's see how we can do more stuff with this okay so now let's talk about Ruby on Rails you see in my day job I am an API engineer and I work primarily in Ruby on Rails now Ruby doesn't have an LSP server per se and when it comes to linting and formatting Ruby files the default standard is a gem called rubocop now it's very important to add rubocop to our setup here because otherwise we don't really have any LSP configuration stuff for Ruby so let's go ahead and add rubocop as a linter and a formatter in NLS but first really quickly let's just look at my Ruby project here this is a rails project so we have controllers and help ERS and Views and some JavaScript stuff and if we click on our about controller um well it looks like we don't have very good highlighting in our Ruby code so that tells me that tree sitter isn't really doing anything with Ruby here and I think I know the problem if we go back into our configuration and we look at our tree sitter configuration we see that we have only Lua and JavaScript are are Ure installed so let's change that to something a little more interesting let's go to autoinstall equals true this should automatically install whenever tree sitter encounters a language that doesn't have a parser for so let's go back to our rubby files and see if tree Setter automatically installs something for Ruby oh and we can see down here tree Setter installs install something for Ruby and now our configuration is doing something awesome our Ruby code is being nicely highlighted by tree sitter so that's really cool I think we should change that in our configuration we want to have Auto install for Tre Setter so that it will install parsers whenever it encounters a language where it doesn't have a parser installed nice thing to keep in mind okay so now let's go back to our neovim configuration we want to go into null LS here and we want to add a couple new things to our sources we want to add a Diagnostics entry for Diagnostics there we go for rubocop and also a formatting entry for rubocop as well now what this does is this will give us the linting that we need for rubocop and also the formatting ability using this key map down here for leader GF so now the next step is in Mason we want to install rubocop so let's look at linters and we can look for rubocop and we see it right here so let's install rubocop and it's installing it through a gem yada yada yada and hey rubic cops installed all right cool so now let's quit Neo them let's CD back to my Ruby on Rails project and let's just see if we're getting any kind of linting stuff happening here I can't tell right off the bat so let me just do something something like I don't know okay here we go so now this is what's interesting we are using rubocop to lint this file and then none LS what it's doing is it's wrapping this command line the standard in and standard out interface in a generalized LSP so that our LSP client is actually talking to rubocop through this generalized LSP so this looks like an LSP but really all it is is a Diagnostics tool for linting our file really interesting so now let's see if we can format it using leader GF and there we go it worked so now we have rubocop for formatting and linting our Ruby files and that's so simple these are all built into non LS easy okay so now let's add just a couple more things here for our um non LS setup we want to add eslint and prettier typically in JavaScript projects you use prettier for formatting and Es lint for the Diagnostics which is linting so now let's create a new entry for ES lint and then a new formatting entry for prettier of course all we have to do here is open up Mason we can go into linters search for prettier it's not there it's probably in formatters search for prettier there it is so let's install prettier and then let's go over to our linters let's search for eslint and we can install eslint d cool I believe I misspelled eslint here yes it's es lore D so now we have all the linting and formatting for our JavaScript files and it's all set up really well and now of course if we want to handle formatting and linting in Python if you're a python bro then this section is for you I'm not a python guy so it's hard for me to have a confident answer here but I do know that there are a couple programs that people typically use with python and that is black for formatting and I sort for sorting and linting your files so in Mason we can just open up the UI we can search for black and we can see that python has black and it is a formatter so let's install black and while we're here we can also install isort which is another formatter oh yeah isort is for formatting your Imports that's right so let's install isort and then here we can in our configuration add a couple new formatting uh entries one for black and then one for I sort and then that's really all you have to do now you have I sort and and black formatting your python files and the configuration is that easy pretty sweet right so what have we really learned in this episode well we learned about how null LS is an amazing package for combining all these disparate tools together wrapping them into generalized LSPs and allowing the neoven built-in LSP client to talk to them we then made sure tree sitter was set up to install new parsers whenever it encountered a language that it didn't have a parser for and we added linting and formatting to all kinds of Lang languages we added it for python for Ruby and for JavaScript and for Lua so now we can format our files according to whatever our company wants or our team wants and it's amazing I love it our configuration is getting pretty amazing here but we have just one more thing we got to do here and that is autoc completion and Snippets guess what that's coming up next episode so stick around subscribe and hey Merry Christmas nerds
Info
Channel: typecraft
Views: 61,953
Rating: undefined out of 5
Keywords: neovim, vim, neovim setup, neovim from scratch, neovim from scratch lua, neovim setup from scratch, neovim configuration, neovim tutorial for beginners, neovim tutorial, neovim tutorial mac, neovim course, neovim free, free neovim course, how to install neovim, neovim lua, neovim config tutorial, how to config neovim, neovim installation guide, how to setup neovim, vim editor, neovim plugin tutorial, vim plugins tutorial, null-ls, null-ls nvim, null-ls alternative
Id: SxuwQJ0JHMU
Channel Id: undefined
Length: 14min 27sec (867 seconds)
Published: Wed Dec 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.