Debugging In Neovim (ft BashBunni)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay awesome first try nice try what's up youtube we're back with another bash to basics here to teach you about debugging inside dmm today they said it couldn't be done but i'm here to tell you it can be done so basically what we're going to get to throughout this video showing you steps along the way what you need to configure of course a few other vim tricks thrown in here and there we're eventually going to get to a screen that looks like what you see here so the top is we've got expressions expressions are something that you can write evaluate at each frame along the debugging steps so that if you had some complicated function you needed color otherwise you could evaluate that we've got the stack which tells you how far down in particular functions you are and where you're at in the code at this moment after that we've got your current breakpoints which you can see here bash has got just one set up right now that we were doing to stop at the beginning of our file so that we could sort of just step through the code as we go and then after that we've got some locals which are just different scopes that you can have that tell you what the current state of the program is finally at the very bottom here which is right behind me we're able to actually run commands to tell the debugger to do different steps of course we can step into step over step back do all the different things that you'd expect to be able to do in a debugger we're going to talk about how to do that right now stay tuned thanks everybody let's just set the scene a little bit for uh what's going on here do you know what dap is as in d-a-p the acronym not dabbing on the haters but d-a-p not d-a-b um isn't it um debugger debugging adapter protocol dang nice bash you came prepared i like it i like to see it i actually genuinely tried to get this set up but like oh wow okay nice i did not did not succeed okay dap one easier right now because chad is just in shock about about the dab so you know we just let everyone have a moment to recover wow these are quality these are quality dabs okay nice are you a fortnight streamer too bash or what i was practicing specifically for this because i knew that dap would be coming up quite a bit so i was rehearsing in the mirror earlier today nice very cool very cool yeah uh just yeah i just like you i like the image of you preparing uh because you're like i can't wait for tj i know he's not gonna be able to resist making a dabbing joke after we say dap so i'm gonna prepare my best dabs exactly exactly yeah um okay so nvim dapto uh is basically an implementation of the debug adapter protocol like you mentioned and this like the concept of what we're going to talk about today is super super similar conceptually to what happens like for lsp right so lsp is just like a protocol that tells editors how to ask questions to like some other service and then once a language implements that thing then you can keep on using that same tool to do it over and over right so for lsp it's like go to definition but for debuggers it's like start debugging you know like okay continue to next spot step over those are all the commands that basically well not those aren't all of the commands but those are some of the commands that you can say to like a debugger and it's the same principle as lsp that makes sense so far yeah that makes sense cool so uh there's two there's at least two main plug-ins that i know of that support debug adapter protocol inside of uh vim and neovim the first one is vimspector we're not going to use that one today because i don't know how to use it in the oven i also wouldn't i also couldn't get that one working so that one i think i would say although like it's it's not that it's not trying to support any of them i think the guy who runs it pure morning like does try and support any of him but i think his primary focus is on making sure it works for vim right so uh but so then the other one the one that we'll use today is nvim dap and that's the one that i use and i've had good experience with it so far and a lot of the like concepts and ways that it's structured are very similar to the kinds of ideas and structures that after you learn more about built-in isp you'll be like oh i see like how these two things kind of can be like related to each other ah yes okay i also have um okay just a little side note i also have another issue um i haven't been able to get my awesome linter working well let's go and we're gonna need to install some new plugins as uh every every uh one of these things seems to start out with right people's classic complaint with neovim installing too many plugins so yes um the first plugin that we're going to install and we can walk through sort of what each of these does and i'll place this in the chat is uh nvim dap so i don't i don't know if you have any other oh nice you've already got this one oh and you have nvm go and w oh oh my goodness i tried i just yeah actually i'm impressed you already found the list of exactly the plugins that i was gonna say we should use very cool very cool nice okay so these are already um these are all installed so if you right and they're like up to date like if you do plug update or something just to make sure that they're actually like they're all uh up to date that'd be good hold on okay no we're good we're good i just got a warning okay my terminal need to be updated but it's fine okay we're good that's totally that's totally cool okay so with that now we can start trying to actually configure envendap to do some stuff for you and i like we're just going to start with something really simple which we'll go over in the main like important key maps that you need for nvimnap and then we'll work on customizing like how it works and all of that good stuff uh afterwards okay so the oh go ahead i copied their what they had in their like readme but again it it didn't it didn't work ah okay there i have things uh interesting okay so this is from dapgo so i would um there's a couple things first off what we need to do is we we want to get those um those key maps they're not going to work i think until like dapgo actually like gets started so let's actually just i'm assuming you don't like use f5 for any other keys right like you're just mapping f5 to say like continue right yeah i don't use any of the the function keys perfect so let's just take all of those key maps and move them like above this setup function just so just paste them right after your comment that says debugging all right yep cool so that's the first one that's great um and then just delete uh yep perfect you got it so that's good that's the first thing oh and then we need to remove all of the the like buffer equals zero stuff from here because we actually want these to be set up like globally right these are things like anytime you press leader b you want that to add a break point does that make sense oh i see so what is so the buffer buffer equals zero that's usually just setting it for your current buffer yeah yes right so that's wherever you execute this from it'll set that for the buffer that you're in okay bash this is a good time let's um i'm going to teach you a cool unrelated trick highlight the rest of the lines highlight the rest of it like with the yeah with visual mode okay like okay yeah just like a shift v is easy to go into visual line mode oh shift v sorry i didn't block yeah yep no you're good oh yep okay and then move down until you select the rest of the key maps okay all right so now press colon s this is going to put you in substitute right so then do a slash this is saying okay i'm going to enter in some pattern here that i want to delete so yeah so let's do just like this whole pattern which is right but we can also delete even like the comma part so like let's start with oh yeah you're there you're there already you're you're fast you got it and then after you write out the pattern write another slash and then that will take them away and then press enter boom whoa okay that's really cool i didn't know that that existed that exists that is the the built-in vims that works for like regular vim out of the box on a remote server et cetera et cetera so so an alternative you know you so you can put whatever so this is a classic thing that i like to do as well is get a visual selection of some area right and then you can do that uh search replace which is uh really nice uh to do yeah that's way faster cool and then like for example if we wanted to dent all of these if you press like uh the left bracket i don't know that's like less than and then say like ap you don't need to be in visual mode yeah just like less than ap yeah yep see how that debug that de-dented everything in that paragraph very cool [Music] so right because that's a that's a basically like a command and then you can say uh a motion for it too so you can just ddent all of those which is a real nice i know prime's here so i have to do the ap if you type d-a-p bash prime's favorite thing whoa boom delete around paragraph you should probably press u to undo that of course but just so just so everyone sees we can dap in a lot of ways inside of vim you know yeah my leader is cool yeah yeah awesome but it doesn't matter uh which leader you use because uh that's why it's easy to copy and paste into other people's things anyways prime does dab on the haters he puts haters a paragraph of haters and then he daps them and they disappear okay so now though anyways anyways back to you oh nice i just keep on missing these uh these dabs until like two seconds later because usually i'm looking at the screen that has chat so it's really i just love seeing the the dabs two seconds after we say it every time like there's just this really long delay of like me saying the word dap and then three seconds later you're like oh that sounds like dab and then you drop one okay okay okay chat's getting me distracted okay so so now though this is good this is good now we've got key maps that are set up to run uh various different like dap items we could actually change some of this to be a little bit clearer but let's let's leave them for now um because it's okay like we could use them to be like lua functions instead of strings but let's not we don't need to worry about that like at uh at this time okay cool yeah all right so now that we've got this um you should be able to just like uh source this file with uh source percent like after you save it so colon w to write it and then you know and then do that uh just resource this lua file i totally have a shortcut for it and i don't remember what it is oh yeah probably i it might be leader leader x because that's what i had and i don't remember if that's what i told you to do but i don't remember can i just can i just do source yeah you can just type source and then space percent yeah perfect okay so now we should have a key map for f5 right so if you did uh like so so that's good so that will let us now have a way that we can call dap continue dapp.continue is basically the entry point for all of the debugger things so dap continue will either like continue on in the execution if a debugger is already attached or if there's none attached then it will ask you which one you want to start now we don't have anything set up for lua so there's nothing good to like connect there right but now we could go open up a go file and we could see if we start uh like are able to to do things so do you have a a go project that has some i sure do like tests because that's probably the best spot for us to start i do okay excellent all right i was just showing this for like the plugins these are the plugins that you need if anyone wants to clip it so that anyone who asks can see it there you go yep i'll paste these in the description of the youtube video that people are watching later when they're watching this that's right i guess i'm probably gonna have to have my config open at some point all right cool yeah let's so we can leave we can just open a new tab and come back to this later or a pain if you will a pain i don't know what they're right i don't know what the right uh t-mux name for this is prime can tell me is it called the t-mux pain when you do it this way i'm i'm a t-much novice so i think i've tested i don't know you just um yeah i think that's that's okay this is okay we're good sweet okay so all we need now is to open up some file that has tests doesn't matter if they pass or fail or anything right now okay cool so the first thing we should be able to do is if you go down to like let's go to like line 28-ish or something like that right we set one of your key maps to toggle a break point to leader b so if you do leader b does any yeah does anything happen oh nice wait why did that happen was was that just because my my key maps were like waiting for the dap go to like start yeah so they were you are correct yes you were just literally doing nothing with those they never got called because you had the key maps to start dapgo yeah inside of the thing that waits for dapgo to start that is a difficult situation to be in i was trying to like i was like what would teach what would teach you and then i was like looking at my telescope config and i'm like there's there's there's mappings in here i think this is the right place to go and it indeed was not so yeah so you're you're you're on the right track but the thing is for this one so you're definitely thinking of a lot of the right stuff which is i don't just want to always put key maps everywhere like every time no matter what the difference is for this one you always like regardless of which file type you're in or anything like that you always want to be able to add a breakpoint right it doesn't matter which file you're in and so that's why like we made these global maps instead of uh like buffer maps does that make sense oh yeah okay so that's why when you pressed leader b before literally nothing happened yeah right it's because so what bash what is the way that you would check to see if you have a mapping for a particular like key combination oh i usually just look at my config file um so here's a new tip there's a couple tips first one the the one that works everywhere is if if you're in normal mode right which is what we're in for these if you type colon and map just one word nmap and then hit enter this will give you all of the mappings that you currently have for normal mode oh this is right you can scroll through here with like f and j and k and all that good stuff right yeah so that's good that can give you some info but you can also do something like if you press q you'll quit out of this because it's a pager you can do nmap and then just type space leader right so do like this will give you just the ones that yeah just like you would type it for a normal map yeah here's all of your leader mappings so that's really good because now you can know oh i see that i actually have leader b showing lua required app dot toggle breakpoint right but if that was in your setup function before you wouldn't have actually seen that right it would have just been nothing for leader b so you can in fact type as much of the like mapping that you want to do right and then indeed as someone is mentioning in chat there's one more level that you can do as well which is quite cool if you put verbose in front of this so if you did verbose space and map space leader this will also tell you where those things were last set if that is information available so when you're cleaning up your dot files you can like decide which ones you actually use and then be like oh yeah by the way i don't use that one it's on this line i can go delete that yeah so that's the that's the built-in way everyone should know that information i think for when they're interacting with me of him you can also just do colon telescope key maps oh shoot i'm pretty sure that's yeah yes yes way once again solving all the problems i didn't know i had yeah so now you can just like start typing leader or actually you might have to type space probably because uh it doesn't like interpret the fact but well now you can see all the space ones that you have right and so that's that's something there too can i look for like oh i can look at all my lubo ones wow this is like a great way to i feel like the worst thing ever is like having to clean up your dot files because then i always end up breaking things so this is like very helpful for being able to figure out like okay for you know if i uninstalled this plugin do i still have like old key maps that are still in there for some reason indeed like we should search for like coc and see how many you still have left from like coc or something right like maybe we deleted them when we got her what i have two not that not bad only two left right so like uh yeah so anyways that's but that's that will at least let you know this is just a general right like tip for i guess debugging your setup right is you're able to sort of look through these both with the like built-in way of doing that but also like if you're just sort of like searching for something or if you're searching for something then you can also look through telescope to help you get there wow yeah i'm so impressed this is awesome awesome awesome very cool so now though after we found out why literally nothing was working for your debug configuration before because you were just pressing leader b and vim was like okay i can do back like what does this mean this means nothing to me yeah um now we can set breakpoints which is really cool so now let's just see what happens if we press f5 all right all right that's our dap dot continue um mapping there you have so if you press f5 don't you debug test hey yeah let's yeah let's see what happens you pressed four and then enter or something yeah yeah debug adapter didn't respond either the adapter's slow or there's a problem with your adapter or a go configuration check the logs for errors very cool gap set log level so before we go there my first question is have you installed the actual program that connect that is the debug adapter for go do you understand the question that i'm asking oh like not the plug-in just like there's an actual thing that i need right so right so just like when we were thinking about for lsp right what's like a common thing what i had to have like go the go please exactly right installed yep yeah so we also need to install something uh and there's a list of there's actually a list of them on nvimvap's wiki and so i'll link that in the chat as well but this is where people also get confused because they think i've installed the plugin but remember these are just the client side of those things they're not the actual server that's going to do that just like for lsp right it's like oh for lsp we have to have a server that actually does the stuff right which makes sense it's but you might not you just might not know that right at uh right at the beginning so uh we can look how to install the one for go and it's actually very easy uh you can actually just do go install delve delve debug i did install delve oh you did okay yeah and it's uh it's like available to be run on your path and everything just yeah oh nice okay and you have the latest one installed uh i think so if you just uh if you paste the thing i just put in chat in to make sure that uh it's like that will make sure that it's the latest delph which is needed for adapt support i think yeah i just installed it like the other day so it probably is but that's probably not a bad thing too yeah just in case it's always good it's always good to check and make sure all right okay done nice so now we can go back and we can see if um see if that does anything we can just yeah quit and then try going again okay actually quite out of it yeah let's just we'll just just in case in case something weird happen okay nice add the break point yep and then we can try um here and debug test i don't know for sure that oh nice that's new can you see the error message yeah it's a little bit behind your um oh yeah i'm not sure i'm not turning my terminal right okay hold on let me oh yeah let me like yeah just stop sharing and then share uh nice all right nice very cool excellent now i can see your terminal i'm like a pro streamer and function arm connect [Music] error connection refused on connect okay so i i don't know actually i haven't actually used nvim dapgo myself so i don't know if that's why um if we're missing something in the setup so i would say what we should do is go back to nvmdap goes uh like page and make sure that we we have that the other option that we could do instead is here i'll play something else and chat from there from their page about what we could try and do and see if maybe we need to call debug test through this dap go thing instead of through uh the f5 i actually don't know okay so we could just try running lua require dap dash go dot debug test inside of here and see if that does anything as well all right yep and so then you should be able to do leader td and see if that starts something for you after you pay starting debug session oh that's new this is new why did that work was it not did it not like oh wait yeah so i don't know exactly off the top of my head how dap go works right because dap goes just like another plug-in that's trying to wrap some stuff for you it seems like this is taking longer than i would expect for it to like get here because your project's not that big yeah like so it should it should like start immediately yeah that part's kind of interesting um could i have to do with my like semi-scuffed attempt at setting this up oh yeah maybe we should look a little bit more i mean the dap ui stuff looks pretty good um unattached seems i don't think you need that out of match like we're not doing anything with it so you can just delete everything inside of the setup that goes that up there yeah um and then you do you have anything below here for debugging like anything below inside of here um i think it's no it looks it looks good after that cool yeah this is just for the dap ui okay i don't think i think we can uh for adapt ui as well i think by default you don't have to pass anything in oh yeah i guess they're all like not loading anyway so i can probably just yeah so let's just delete everything inside there and we can come back to it later so just call setup even without the table inside oh i see okay yep and i think that should just do the default so you can we can just see if uh so let's let's put out of your other neovim and then start over well we'll need to run that mapping thing again or we can add that into your uh the one that you posted yeah the map silent leader so if you do colon and map and just press up i think in like inside of the oven we'll probably run the last command that matches that that's true there we go perfect yep so let's try leader td here again after you after you've done this i didn't set a breakpoint oh okay uh that's fine set a breakpoint and then run it again okay okay oh and then run like leader like type space td i don't know if you ran that right oh no i didn't i can't tell if you're typing that yeah yeah because that will actually start the debugging test failed to launch okay interesting so that's new maybe because we just did something did we do do anything weird this i think i did do weird things let me try that okay so let me just set the break point so i'm doing leader b for that and then was it leader td yeah after you but you might have to map that again because we didn't add it to your config yet oh i see so that's what the nmap thing is doing it's like saying yeah right so yep oh so it's basically just setting okay and then now i do perfect yep okay so now i actually let's try running um there oh nice where did they there's an error very cool arrow no it's not an error we're not an arrow oh arrow yeah yeah indeed we're debugging right now so can you run uh lua and then uh require uh parentheses quote dap ui no no no spaces or dashes or anything just app ui like that yep and then yep and then at the end of this do dot open and then parentheses parentheses yeah hit it boom whoa i think this deserves a dap okay from from both of us from both of us the chad has been well you want to do a double you want to do a double i'm a dad so uh i'm allowed for mine to look embarrassing but bash you'll have to you'll have to reconcile with yourself about how the embarrassing is but are you ready to do a double dab i'm ready double dap three two one oh oh double dab i thought we were that just meant we were dabbing at the same time oh no okay double oh double okay whatever i'm just turning on my camera my team okay we do need a dab count how did we not start that at the beginning someone will have to go back and watch the bob we'll we'll save the synchronized double dap till the end after we do a few more things right we'll save it we'll save it okay okay okay so bash we're here look at this we have we have ui we're connected to a test and i think um if you go back to your config we can look at the other key maps that you have to start doing some interesting things all right can you step into f11 yeah totally let's try it out and see what happens oh oh no i need to remap it rip rip your mappings [Laughter] we stepped into something completely different i guess what about f10 does f10 work well why does that also do something different i don't know this is a good question oh okay just step forward we can't jump inside of these at the moment that's okay but we can keep stepping forward so if you keep going like if if you keep doing this right we'll be able to see what's going on you can see in the bottom left corner there's new locals yeah if you move over to that window and press enter it will expand them so you can actually look at what's inside of them so i can just move through these windows like i normally would in neovim it's literally just neoven windows yes control w and then just navigate yeah oh and then here oh can i make this bigger i have no of course it's just it's just a window so yeah you can do anything you want it's just windows just all the normal stuff that you have for neovim right that's like so this is where things get quite exciting where people are like oh why don't i just i want to use my vs code one and i'm gonna make fun of people for using neo them because i only like my way which i've already seen in the chat nice try i notice you guys i just ignore you easy um right like this is where it's cool because you already know how to navigate through all these windows you already know what you prefer for like making windows smaller bigger focusing them putting them in different tabs uh whatever your like normal neovim window like workflow is right you can just keep on doing those things right so you can move the windows around etc so that part's pretty cool because now if you wanted to like focus one window you could just do control w capital t it'll open it up in a new tab and then you can move between those tabs by doing you know like all the stuff that you would normally do this is just another knee of him window i would totally do that i had no idea that command existed yeah and then you can press gt to move to the other tab just gt yep there you go wait you can do that you i had no idea yes so you can like break weight they're but they're in the same buffer they're just like different tabs in an existing buffer yeah so maybe we need to do a separate video sometime where we explain what buffers windows and tabs are because there are really important vim concepts about like what's going on inside of them and the of him but yes so it's all this it's all the same session right so if if it would have changed in this tab right then it will change over there too so you can move those into different tabs you could set up dap ui to do these things automatically as well right so if you always wanted to have one tab that's the scopes you can do that no problem i forget how to navigate through these gt did you teach yeah you're good okay yep thank you think of it as go tab go tab this makes sense this is right and for those of you who don't remember and later in the youtube video this is the time where we'll play bash acting like a dj i just love the what even what did you even say for moving to the next dj yes okay we'll be we will be using that clip many times oh perfect we have it right here we've got the clip all set up for us excellent yeah i promise you i do not have that mapped i did not know this is actually maybe pre-recorded and i actually did know and it's all a conspiracy you'll never know chat bash we're live right now recorded live but how are you telling them that we're recorded [Music] i've invented time travel and i've already time travel i can't even start don't get me started bash [Laughter] i don't want to try and do time travel discussions right now i just started star trek i'm not good enough at science fiction yet to understand i'm just following the begins footsteps okay this is fair okay so anyways though this is where things get pretty exciting because we can actually walk through this test but let's uh let's just press like f5 to run the rest of this test we don't really care what's happening here and hop back over to your config and let's change those key mappings to mappings that you can actually hit on your keyboard yeah honestly it's like so rude that's so uh so rude of mac to like be so aggressive in not letting me do things okay um f yeah so i did something like i did i think i did most of my like f one two three four five i have for dap right now and they're like then as the numbers get bigger the step sizes get bigger so like step into was like one step over was f2 and step out was like f3 or something like that i just made it up for me as like a mnemonic to think about like as the numbers get bigger i like um i i am doing a bigger jump if that makes sense this makes sense you can pick whatever you want i'll probably change these later but for now i'll i'll just go ahead and do these i think yeah so the main ones that we want right now are just step into and step over because those are the interesting ones yeah and so you can map those to be whatever you want um okay nice i like it slightly and then the other ones for us to uh for us to note here is that we have this leader capital b which is conditional break points so this is really cool and we can check that one out momentarily as well but there's also the last the last thing that i want to show because this one feels absolutely magical when it's working is this nvim uh dap virtual text so it doesn't look like you have this in the setup yet so if you put this inside of your lua what i just pasted in the chat right um you'll be able to uh you'll you'll really like what happens next i think inside of the the debugging so we just need to put this setup call somewhere around the dap ui stuff or whatever is good um again oh yeah we like yours oh this is just uh it doesn't need it's not in a key mapping it just goes by the setup like it's i'm sorry i don't know why it might bring yeah oh you're good you're good we're doing like 20 different things out once bash and i was also streaming until 1am and making porn choices oh smart so yeah i i came prepared [Laughter] okay okay well with uh with with this new stuff let's let's go try these let's go ahead and write this and head back over to where you have the test we'll restart neo vim to make sure we get like all the stuff that we wanted and then we can set a new breakpoint inside of one of these functions again doesn't really matter where um oh oh we didn't we the other thing we need to do is add a mapping for that like go lang test uh debug one that i had pasted a while ago i can just paste it into the chat again if you don't have it uh lua required dapco debug test that's the one yep [Music] yeah so it should just be instead of dapp.repel open there in this one we should just have it say um dap dash go debug test yeah dap dash go quote dot debug underscore test and we can change that to be leader td or whatever for debug test or leader dt or something for debug test that's a pretty good mnemonic i guess wait what leader d t for debug test seems legit seems legit okay cool now we've got that we can easily uh do the start the test again once we're there we don't yeah yeah that's perfect okay and then i do dt meter dt yep starting debug session yup and you'll notice that things changed and so now though before we open up the ui we can i can also show you how to automatically open up the ui if you just uh like let's step over so we can just step over a few times nice i'm remembered so yeah keep so do it a couple more times look at this virtual text here this tells you to the right of where those things are defined right where it says db that tells you like what the current type is and its current values nice that's not like the default values or something like that right if you step over this one more time like and go to the next one it'll tell you that got this tells you what god actually is in virtual text so that as you're going through you can get a quick overview is there a way to wrap that or like see it and like can i use telescope to like see what all of them are or can i just have the text wrap so i can see all of it so you actually probably don't want that because these names are like incredibly long because it could be like list of a 10 000 things right so if you wrapped it you would just see like one one continuous line this the information that's displayed inside of those is inside of that locals tab that we had open when we had the uh dap ui so like it's the same it's the same information but this lets you like really easily see okay sure like got is this thing instead of like going through that whole tab when you want to get more information that's when i would move over to that to that tab to do things nice and that's just with this uh new vmdap virtual text dot setup that we did yep yep so that's what that does is uh that virtual text will just integrate with tree sitter to find where basically the names of different things are defined and then it says okay see that got is defined here and so i'm going to display the information from dap inside of this this is like it's just so exciting to see all of these pieces getting used so like composably with each other right the debug adapter protocol tree sitter lua like and they all play together so nice yeah i actually need to learn more about true sitter i haven't really i feel like i haven't really used it for that much so this is like the first thing that i'm really doing with tree sitter sounds like an another bash to basics we'll have to do something um okay so cool so this is this is really good now we can do uh the lua require dap dash ui ui.open again to open up your dap like stuff oh like actually i think i have a keybind for it dap ui that one is oh wait lua required wait do i have to do a thing here so you'll what you'll need to do right now and i'm just about to teach you how to do this without having to type it is to open up the ui you need to tell the ui hey it's time to open so that's uh dap ui so require quote dap ui no dash i think yep just like this and then dot open boom now it's open cool and so now that's that configuration that you had originally inside of dap ui that's where you can decide what things you want open and how you want them displayed like if you never use like uh watches right or something like that like that watches are like you can type some expression actually we should just do this because it's pretty cool if you go up to that top window the dap watches or the dap watches uh buffer up there yep uh one more oh one more i thought that okay i'm just confused okay we're good we're good and if you just uh type want just w-a-n-t and then enter like in insert mode yep hit enter oh because it's not evaluated perfect yeah so now press like whatever your button is to step over okay which is f3 and then now if i were to do it oh i didn't even have to redo it automatically evaluate for whatever frame you're in so if want was something that changed over time you would actually see that value up there change whenever you're doing that so those get evaluated every frame that you stop basically does that make sense yeah yeah yeah that's very cool yeah okay yeah this is so if you typed got in that in that one right now like it got is another variable that you have those are the two different things that you have and so you could even type um like got uh if you type something like oh yeah and you can expand them just like you you could in the other spots too i think it will even work to evaluate like expressions so if you type want like bracket zero right so like you're accessing the thing at the first index up here oh yeah and hit enter that will work so you can even check like what's inside of a particular thing and it will keep on evaluating that wow is that super cool that is super cool yeah i'm gonna ask i have to ask again what is how do i make the top how do i make like one of these windows its own like full yeah so control w is for windows so lots of commands start with control w so if you do control w capital t that moves something to its own new tab and then gt is like go tab and that will help you move through them wow okay that's really cool yes i i use it quite a bit especially on stream i don't know on off stream do you program with a lot smaller font size yeah where do you use this month yeah i have the same i have the same thing so like on stream i often have to like use tabs instead of splits um and so i use these these quite a bit because on when i'm normally like just coding myself i can just make the font size a lot smaller and i can read more text on the same page yeah like i think mine's usually mine's usually like that small probably yeah i know yeah i know the feeling yeah so it's like if you go if you go back to like your main page and you go to that font size it's like oh hey that that actually like i i maybe don't need to make eight different tabs for each of them but it's cool that you can yeah can you also send the tab back to the main debugger yeah of course so that's just a buffer right so if you go back to the main like uh the main one that you have here right if you did like colon new to make a new buffer here right and you did like telescope buffers for example yep and then you oh these are unlisted so they don't show up okay um i think we have hidden i don't even remember what the thing is um it doesn't it but like these are all just they're all just actual buffers so you could do like colon buffers or something instead and it will show you what what you want we don't have to go into how all of those actually work but you can actually like look at what the buffers are and see them and you could put these buffers back if you wanted as well or like open a new tab and edit them buffers are always the same and shared regardless of where um they're found so yeah okay cool so yeah this is so now we're basically at the point though right where hey we've got debugging we've got the ability to watch variables we have the ability to set breakpoints what are some other cool things that we can do another really cool thing that you can do that's super helpful when you're trying to debug stuff is to set conditional breakpoints so if you go down to line 37 here and you do leader d capital b i think is what you've got oh wait oh no what is it again capital b oh leader just capital b yeah leader just capital b so this is breakpoint condition so this lets you write code so we could do i equals one equals equals one yep perfect like this so now this will only get triggered to stop when i equals one so if you need to debug the 37th item in a list instead of step step step step step step step right over and over and over you write this conditional break point you throw it in and then it'll only uh stop here again when that condition is true buffer i barely know her i hate it thank you thanks [Laughter] that's awesome okay that's actually that's super helpful that's kind of the worst is when you're yeah you know that it's like it's breaking after this like after it's at this index or whatever and you can actually just do that and not have to hit next yeah and so the other nice thing particularly as well right is for like if you're running an application not just a particular test you can set that break point to be whatever the case is the only one that you care about right so like you don't have to debug your whole like step through a million times till you get to the exact case you're hoping for you can do like set the break point till oh i only want to break i only want to stop here when the user is bash bunny right instead of other places which is really helpful for like a non-test case debugging sessions oh that's awesome yeah wow so that part so that part's all good now we can we can just talk about a few you know just a few small sort of like nice to haves when we're doing debugging um so the first one would be being able to set up uh dap ui to just open automatically when you start debugging a test right oh yeah nice you can uh write code in here to ask ask questions to the debugger as well oh how do i what questions so like if you do dot scopes or something tell you what's inside of your current locals and stuff so some of this information is already displayed elsewhere but this is basically like um a rebel inside of uh this that can talk to your uh debug adapter hmm yeah interesting interest and there's there's a bunch of other stuff that you can do inside of there uh to tell the debug adapter what to do but we don't have to i don't i don't use that one that much mostly i just use mappings to ask ask the questions that i want uh and that that tends to work out quite well awesome so shall we get uh zap ui to open up automatically yeah that'd be great okay let's do that um so there's basically this concept within um within nvimdap of the idea of listeners now listeners is pretty much just like it's like basically any other uh language where you're thinking about listeners which pretty much nvim-dap emits certain events and when it emits those events you can give a function that you would like to run and so if we go to i think it's probably easier than me trying to place this into twitch chat if you go to the dap ui um readme we can show uh some examples of stuff that that uh that we'll need to copy paste in to get this to work okay uh someone asked though what is uh what is dap dap is his own protocol it is made by microsoft it's kind of like in some ways a sister protocol to lsp except it's focused on debugging instead of like language server stuff and uh there are many different clients implemented 4dap neovim has one in nvidap as well as like vim spectre hopefully that gives the info people are wondering okay so uh what part of this should i look at yeah so just in the usage section just beneath where it has how it says dap ui.open.close.toggle there's a a list of basically like local dap comma dap ui do you see that that section there that chunk okay so we can just copy that whole section in to your uh config just beneath where you have your dot setups basically all right yeah okay so what does this do well bash i bet you can just read the code and tell me all right so we're setting uh local variables for dap and dave ui that are basically just opening up the plugins dap and dap ui uh it's then calling dap.listeners.after.event initialized wi-config so i guess once the config is loaded question mark it um it's calling this function that oh that does dap ui so one stop okay so once dap is loaded it opens up dap ui and then down at line 74 um after the event terminated so after basically after you've closed up then it will close dap ui and then once you exit the event it does it also closes yeah so terminated or exited all right so clean exit or if you did like control c or something i don't know if that's actually something exactly yeah oh so those are that's exactly right the only uh tweak is basically to note that um event initialized and so these events um the key here so dap ui config is basically just like a unique way of specifying the function that you run so that it only runs one time like no matter how many times you resource this file it always gets saved to the same spot in the map um so what it actually is is whenever dap and vimdap not nwmwi has an event where it initializes any time it's initialized after it's done initializing it's going to call all of the functions that are like registered in this table and for us that's going to be ui config and then it's going to call dap ui open so if we go back to your go project and we quit and like open up again right and we restart debugging um a test this time instead of just showing the arrow when it connects right it's going to actually open up the app ui for you and so you could actually do whatever you wanted in that function right it's just lua code so if you wanted to like set up some smaller version of dap ui or you wanted to add additional key maps or you know like any of those different kinds of things uh you can just you can do that super easily by doing this but now automatically opens right away for you nice okay so if i do i understand that correctly so these are all these are all the event initialized dap you adapt config so those are all named the same thing so that it's only being called once yeah so like uh you're good so if i changed if i like changed one of these to have a different a different name of like dap ui maybe underscore c or something like that there's a chance that that could break it um it won't it won't break it you can put whatever key you want in there so as long as you like if you put bash bunny that's totally fine but what you don't want to do is have dap ui open called by two different keys does that make sense so you want basically like so this is just this is telling nvim dap hey i've got something i'd like you to run okay right and we're going to basically like name space it with the app ui config if you made another one that was also called bash money and also called that ui.open that would be kind of bad because then like you'd try and open the ui twice and it would look really goofy to do that right um so it doesn't matter what the actual key is it's just make sure that that's like unique and so what happens is uh if you ran this file again it's like if you saved and sourced this file and you sourced it five times instead of accidentally having five different things registered as listeners you just are basically overwriting the same key every single time uh for for nvembe some good that's my teaching style so that's perfect um cool okay well that's uh that's the main that's the main stuff that i wanted to go over with nvim dap and sort of like the basics of getting things initialized there's some more things that you can do in terms of like theming like you can change what the icons are for break points or like you can change the colors um those are all in the config i i i haven't really done that except i put the among us unicode symbol as my debugger guy because he's scrolling through the code which is kind of fun so that's awesome but otherwise i mean i i feel like once you're at this point oh the only other thing would be that you should um you can try and figure out how to debug basically like an actual executable not just a test so we should we should go over probably doing that for go and then once you do that i mean you're pretty much set unless you have any other questions about it i don't think so i don't think i have any questions right now let's just go should i just like init actually what projects do i have we can do it inside of your project test is good still like we just go to where you have main right or like inside of your project management thing yeah right like you have a main file somewhere or like something that runs maine yeah oh so don't cd into here like start at the base of your project like where the go project actually starts which i'm imagining is right here right here and so let's open up some main file that you have inside of here some main file i don't have a main file in here uh you have a main.go that's information like it's okay yeah it's okay if it's recursive that's good okay i'm saying you should just make sure that you have your like base right here i think yeah so you should have funk main somewhere inside here i'm assuming i think i do yeah oh wait that's yes nice so let's just put a breakpoint right here all right and then press f5 this time oh shoot because we don't have any tests right so there's no tests you're on inside this so press f5 and then let's just see if you run one to debug let's see if it actually works i don't know if it will or not failed okay that's fine let's try it again and do a debug package the second option i think so f5 and then otherwise we can we'll have to go into some more stuff about how this actually works but maybe this will maybe this will work ah darn that's okay darn oh snap um okay i actually thought that dapgo would handle this for you i thought that was kind of the whole point of uh of doing this yeah same um i guess the only other option would be you could try running this from let's actually try cd-ing into this uh directory okay there's a go oh wait a second oh no it's here it's here it's here it worked that's it it was just slow to respond okay awesome first try nice try doubters got it outers doubters um okay cool well there you go so now if you do something like step into i like your f one or f two i don't remember which one you chose for that oh wait i did stuff yeah i think you stepped over i yeah here i stepped into this one look at this bash it works yeah and so now i think you're pretty much just like waiting for something to happen which it's just gonna be like inside of you just ran through the whole program that's totally fine it finished done uh so yeah so that's so that actually worked that's great um there's also the possibility of connecting to remote uh processes as well delve has that capability that's a bit more complicated it's a bit more complicated to do um and maybe we'll maybe we'll have to record that another time because it will take a bit of setup and it'll be kind of boring to fumble through everything yeah and i also have to go back to work at some point but we could maybe record it and we should post it on your youtube channel bash wow i have a playlist did you guys know bash has a youtube channel i do smash that sub button right now someone link it i think it's the youtube command thanks george appreciate it nice wow okay so there you go but that works for running your own tests which is really great you can just debug a single test and it also works for running an entire project um so for you you have to do debug package it might be a little bit faster this time there we go absolutely um so that's good it was probably just compiling the whole project so it took a second to compile which makes sense and you can set the debug breakpoint anywhere you want it doesn't have to be inside of this main like area which is cool the last thing would be like attaching to remote process that's a little bit like it's a little bit more complicated but it's not insane and then the something that we'll we can talk about um as well if we do another video or something or we could just come back to this next month for the next bash to basics yeah is you can also set up your own custom uh debug like commands that will run custom sets of like arguments so right now like you aren't passing any arguments to maine you know what i'm saying you're just like running man you're just running your thing projects or project management whatever the tool name is called yeah but you like expect some arguments like say what you're gonna do right like what do you wanna do like add a new task or something like that right well you'd have to set up some particular command to do that or connect to a remote process those are the ways that you can sort of do special things with that oh yeah that'd be really cool if we can like go in in details on that in a future video yeah yeah okay that's well that's next month then you guys have to come back yeah by the way second second wednesday of every month second wednesday of every month bash to basics that's us that's us yes okay bash any final questions before i have to leave uh let's see wait you can run a function and pass the expected parameters yourself so someone said yes you can actually do that so if we went into control sub commands like if you went to the definition of that remember this is still just a neovim window on the right so you can like navigate down to 39 and press go to definition right inside of control inside of your like main yes over here on the on the right side on the right i'm saying oh yeah like you just go to control sub commands you hit whatever your go to definition for shortcut i think gd right yeah yeah so this all still works right so if you go inside of here like you can just change what uh what projects is right like you can debug and you can just change what the variables uh what the actual like variables are you can just set them to new variables for some stuff which is kind of fun because you're debugging so it's possible that you could like run this without changing other stuff so you could just change this to be like no no not like that no so if you press right if you go um down to your like adapter window there at the bottom yeah this one i think you should just be able to say like um name equals hello or something like that you know like we're not currently in a scope where that's gonna matter but i think this i i don't know that that's i don't remember exactly how that works but you can set variables and change their values at least most uh debuggers allow that i don't remember if go does or not um if yeah so so we could go over some we'll just have to do an advanced topics video for next month uh because we don't have enough we don't have quite enough time to do all of that today and we gotta we gotta leave you know do a little tease of course yeah of course of course of course of course okay well uh with that i gotta run bash okay we got debugging working though yeah thank you so much i'm so this is very exciting very happy i can uninstall vs code once again nice good man that makes my day i'm a happy i'm a happy maintainer you know so cool okay well then i'm gonna head out um we do this like like bash said we do this the second wednesday of every month uh of course you can uh watch bash all the time for great neo tips and tricks and don't forget to subscribe to her youtube channel and same with teach by the way
Info
Channel: TJ DeVries
Views: 94,222
Rating: undefined out of 5
Keywords:
Id: 0moS8UHupGc
Channel Id: undefined
Length: 62min 16sec (3736 seconds)
Published: Fri Jun 03 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.