Debugging your Neovim configuration

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone so um ever since the no Vim conference last year I've been receiving a lot of requests of me sharing my debugging configuration um I mentioned how I use the Lua debugger to debug my my init Lua or um even when I'm contributing to new features I will use the debugger to look at the plugins or or even when I'm debugging the itself and so I will I'm preparing this video so um all of you can um hopefully do something similar so um first I'll start with um showing you how I configure the debugger um this if I go to my d. Lua file here in my nail con um well first of all it is always useful to set up the break points um icons that you want to use and so for example like um um this one it is the one that I said um you can see over here um how I have this icon for the breakpoint and so um you can set up that for some I candy um now if I go to um to the Lua configuration itself you will want the following plugins so first of all you want to use um um and then dap um if if you are not familiar with it dap it's similar to LSP um it stands for the debugger adapter protocol and the website even looks very similar to the LSP website um but debuggers can also follow a similar protocol and this is how you can still get a a very similar debugging experience in vs code in themm in visual studio and you name it um and so that's a nice fact um so that will be the one um that you will want to install um and Thea and beamed up UI um this will also allow you to see things like as the local variables um where you have placed your breakpoints um stock traces among other things that will make this debugging experience quite similar to vs code if you have used it in the past um next I set up the the the key Bindings that I want to use and so um this one it is for evaluating a specific variable when the debugger is on I will show this later um and let's see this is again just configuring the the specific windows that I want to open when I turn on the debugger um this one for virtual text it's really nice it shows kind of like a newly hint at the very end of the line and so when you're debugging that can be very useful um and then there's some other plugins depending on the languages that you want to debug and so um to figure this out I mean just Google it um or or look to readit um I I I also have to mention that um I'm just going to open um Lacy themm because um in fact all of these configuration when I first got started I just adapted it from from what lazy them does um of course like given that I don't have all of the lazy vam infrastructure I handle my own configuration um you can still use this as a reference of what you would want to use um like using a specific setup and so um if you go here and you look at the full spec it's very it should be very straightforward for you to just copy paste what lazy vam does and go from there um so here I use um the the configuration that I use when I'm debugging typescript or JavaScript um but I think that the most important and the one that I will try to focus on on this video it is Lua debugging so for these you will want to use the Lua adapter um it is called one small step for Vin kind and um this particular pluging for um launching the server um you will see how this works um in a bit and um some other more key bindings um this particular of like um let me select what I'm referring to that part particular um configuration it's something that um it is documented in thei um read me and so make sure that you from all of the plugins you take a look um overseer it is a a pluging from the same um guy that came up with conform and um I'm blanking um the one that you can also use for oh dressing and so he has amazing PL and overseer allows you to run pre and post um debugging tasks which are often defined in vs code folders and so that's really nice when you're working on a code base where the other maintainers or or people in the team will use vs code and you still want to use the same configuration that they have and so you can also look at overseer for for for that and um the Lua configuration adapter and so for this one um again this is in one small step for V kind um let me go back here and here in the plugin um you will see how the configuration tells you exactly how you want to configure this and so as always just read the manual um but there's I I cannot really tell you much more of what um written here and so going back to the config now that we have this um let's come up with an example and so um let's try to go to um let's see I'm trying to think what would be nice to have here um let's go to mini files um and the reason I I picked this one is because I have a this particular function that I use use um for opening files from the tree Explorer in a split like this and so say that I just installed mini files I'm creating this new function and um I want to know more about the types of the arguments that I would be handling here and so um I would like to know more about like these particular arguments and the shape of them and um just make sure that I know what they look like um in this case mini files always has a great documentation and so you would actually um be able to know the types but say that we're dealing with a different plugin then that's not the case and so now that um we have this scenario I'm going to start by setting up a breakpoint here um and here you can see that um the key binding that I said is my leader and the then D and then B so tole breakpoint and um now I will open a new tab in my terminal and um I'll get started by opening no Vim again and now um I will open a file that's not currently open in the other no instance and I'm going to open the the server and so leader d and then you can see here that L it will launch the L adapter and you will see here that I have a notification saying that the server started listening in the port and so now that I have the server here listening going back to the instance that I'm debugging I'm going to start and so uh for that my key binding is F5 and so you can see that the breakpoint hasn't being hit yet because I haven't um triggered that code and so going back here I'm going to open mini files and you can see that I already um that that line is selected you can see that the icon in here has changed because I'm there this is what I was referring to with the um virtual text that it shows kind of like an inline hint showing the values of the variables in that line and so now the that I'm here um let's say that I want to just open another break point there um and I'm going to continue and continue and now this now that when I press control V which is the key binding that I said in line 23 over here that should trigger the right hand side function which is the one that in in in line 20 it is the the one that I have as a zon um break point over here and so um contrl V and here I'm hitting the second breakpoint um let's see that I I don't know how um the functions that are available in the mini files API and so here in the locals window in the debugger um you can press enter to expand them and see um what the variables of that what that modu looks like um you can also look at the stack Trace um here um there doesn't seem to be a very exciting stack Trace because I guess that this is just the call back of the keymap so there's not a lot to look at but say that here I continue continue continue and um that way you can look at what the code looks like like um in your debugging configuration when you're customizing it or there's a new bug and you want to be a very nice person and have a lot of information when you go to the plugin repo and open the issue it is amazing when you're able to say oh there's a bug and I know how to fix it and so that's um a first scenario that I wanted to present um now you can very easily just um exit that instance and that should automatically close the debugger um and so okay um now that out of the way um let's say that um instead of debugging my code or my configuration I want to debug a plugin and so if you're using lazyy um as a package manager um I'm not too sure of other package managers but I imagine that it would be something very similar um Lacy stores your plugins like the code itself in local um share um let's see and them um Lacy and um let's see what's a nice one um I mean let's go to mini files um again and here you can also debug the code that's not yours and so let's see um let's go to like a random um function um let's see config default config um trying to think of like one that won't immediately just um stop um um so okay see that something it's wrong with the with the mappings that I said that I try to set up a a a binding in the plugins configuration and then it doesn't end up being what I expected and so let's say that I'm going to debug the map um which I haven't opened this file before but briefly it seems to be the one that will set up the keymaps based on the plugins configuration and so again just as before you can set up a breakpoint there um and here opening another instance in this case I'm going to um start the Lua debugger right away before I even start um before I even open a buffer just because um I have a suspicion that this function will run um when the plugin is first loaded and so now if I try to open mini files indeed um here I I try to open mini files it's not open yet because it's waiting on the debugger and so at this point you can just as before look at the values of the locals um here it seems that there like options for the keymap that I'm setting um you can see in this case that we have a more interesting um stack trace and so if you want to go up in the stack trees to the function that it's calling um map um you can go here and press enter um I think or no let's see do I have a key map for that um it seems like I don't wait I was not ready for this but okay I don't want to spend too much time on that um this was not pre-recorded so um but I'm sure that you can configure it to go upwards in the stack Trace where I actually think that there's like a adap like go back or go forward um map for that um so yeah I think that that's um all that I have and that I wanted to show um I'm just going to remove that break point um and now you can see that the um fils it's open because it's not longer stuck on the on the debugger on the other instance and um I'm going to be closing this um and I just want to see if there's anything else interesting here um to show you all um well something really nice um now that I see like a breakpoint condition um so like say that you want to set up a breako just like to see if um some code is being hit um but you don't want to stop every single time and so something really useful that you can set it is um I don't know this might be very silly but say that we want to set up a break point here and um you can here say give like a Boolean condition indicating when you want to actually hit on that break point and just not continue any every single time and so say that I just want to stop if for some weird reason um the DB model is Neil and so once you do that um that breako will only be hit under that particular condition so that you don't need to continue pressing continue continue or F5 um just for for that um like just just for that particular case um and so in that case you can see that I have that break point there um I also wanted to show you how you can configure um the highlights that you want and so here I set it up to be similar to my color theme um I use a variation of Dracula that I deal with myself um and um yeah I think that that's all that I wanted to share for today um I'll be sharing all of the links in the video when I uploaded including my configuration it's all available for all of you to use as a reference and I hope that you enjoy this um I'm not a streamer I'm not a a huge influencer yet and so if I made any mistakes or if you have any feedback I'm more than happy to hear um and and yes happy coding
Info
Channel: Maria Solano
Views: 2,686
Rating: undefined out of 5
Keywords:
Id: 47UGK4NgvC8
Channel Id: undefined
Length: 18min 4sec (1084 seconds)
Published: Sun Mar 03 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.