Vibe Coding C# Code Fixup Solutions For Our Roslyn Analyzer
December 15, 2025
• 398 views
agentic codingclaude codeai agentsagentic airoslyncopilotvisual studio copilotagentic developmentvibe codinggenerative aiai agentai codingartificial intelligenceai automationai agents use casessoftware developmentdotnetcsharpC#how to use copilothow to use an ai agentcopilot instructionsdev leadernick cosentinogpt5ai assisted codingprogrammingcodinggithub copilotgithub copilot spacessoftware engineeringauth0
We've previously looked at vibe coding Roslyn analyzers but what about helpful tools to fix up those analyzer errors? That's where code fixup and source generators come into play! Let's vibe code one of these!
View Transcript
In this video, we're going to look at more vibe coding in C, but instead of looking at Roslin analyzers, we're going to look at the other side of this with code fixup and source generators. We're going to jump over to Visual Studio. And in this example, we're going to be looking at our analyzer, which was targeting arrange act, assert comments. So if I put something in my code that says arrange and then I put act and then I put assert here you can see that I have an analyzer running that we vibe coded in a previous video and that's actually telling us that we should not have a range act assert comments. Now, a friendly reminder if you haven't watched that previous video, this might seem like a little bit of a silly analyzer, but this was just an example that we could show that
you can literally go look at comments, you can look at other code structure, and you can write Roslin analyzers that will go trigger on these things. But what I wanted to show is that you see this little light bulb when I hover over here. There should be a way that we can have code fixup added into this menu. So, right now, you can see that it says fix with co-pilot. You can see that we can suppress it, but there is no menu option that basically says go fix this thing. And that's what we're going to go build today. And the really cool part is that we can ask C-Pilot to go build that for us. I wanted to show you this kind of thing because if you're not familiar with source generators, just like if you weren't familiar with Roslin analyzers in the previous video,
we can still explore this stuff. We still have access to AI where we can go ask it questions. So that doesn't mean that we're going in completely blind. It means that sure we might be going into this and we might not have all of the information to go write it from scratch, but that does mean that we can ask AI questions and get it to help explain things in ways that we can understand. So, let's try it out. I'm going to go over to the chat here and I have it in agent mode. Let's see. I have Opus 4.5. At the time of recording this, I think uh I've tried GPT 5.1 is not working so well for me. It seems like in agent mode in Visual Studio, it's not really executing things. It's kind of just answering stuff for me. I tried GPT 5.2
as well. I think in VS Code also not working. But at the time of recording this, Opus 4.5 and GPT5. I kind of go between those two because at least they're executing things in agent mode without kind of being this frustrating in between. I'll answer things for you but not do the work. So, I'm going to leave it in Opus 4.5. By the time you're watching this, who knows what models we'll have, but I'm just going to speak into my microphone and have it basically type into the chat here. So, I would like you to create a new project in the solution that is for source generators. And the idea behind this project is that we want to have code fixup for the different analyzers that we have in the solution. Those analyzers can be found inside of vibecodedanalyzers.ananalyzers.croj. Just going to start with that
to see because there's going to be Oh, nice. It actually did an okay job with the um the wording. So, you can see down here, right? Uh when I type when I speak to type this kind of stuff out, especially when there's names of things, it gets a little bit weird, but it actually did a good job. Didn't have to really do anything there. The first code fix up that I would like us to have a source generator for is specifically for the arrange act assert analyzer. This code fixup will be responsible for removing the arrange act assert comments that are causing the analyzer to trigger. I'm just going to start with this. Now, a couple things that I'm expecting is that if uh Copilot goes and creates this new project, probably what's going to happen is that in order for us to see it
working and be loaded up in Visual Studio, and I don't just mean showing up here in the left nav in the solution explorer, I mean actually having the menu system and everything. We probably will have to relaunch Visual Studio. I'm not sure at the time of recording this if there is a way that you can kind of just refresh Visual Studio while it's running. But I've personally in my own experience kind of seen it where I make changes to the the generator. So the code fix up in this case and then I have to reload Visual Studio for those changes to take effect. But let me go run that. And maybe the other thing that I'm expecting is that because it's a new project, I've seen it sometimes where Visual Studio will not actually load the project in the solution explorer and then when we
try to it it basically wants to kill off the chat as it's executing. So, we'll see what happens there. But I find with new projects being added, sometimes it gets a little bit awkward. Uh but nothing that we can't go figure out. So, let me go uh get rid of that. We can see more. So you can see that it created a plan in the chat. Um I think and oh actually it's right on in front of my screen too. And I think that uh a lot of the time now especially with uh some of the better uh the better models when we get these planning steps this helps tremendously. You'll also notice that in Visual Studio uh unless they change this by the time you're watching it there is a cut off point where if the context that it needs to go look at
is small enough it will skip planning altogether. But I generally find that when it puts a little plan like this together, it seems to stick to it quite well, especially if you have more complicated things. This is basically a whole new project uh with code patterns that aren't established yet. But you can see already that I have this little uh popup on my screen saying it wants to refresh this solution. I also don't know why this window behind the out window is enormous, but I can't um I can't reload this yet. Um, and I can't reload it because if I press the reload button, it's going to uh try to kill the chat. So, let me ignore for now. It should be able to try building with MS build. But you can see it's convinced the solution has five projects. Now, if we look in
the left, 1 2 3 4. So, I do have to close and reopen this. But, uh, it says that it's done. Maybe I can just try doing this. Actually, let me go add just going to go add this project in. And we have this whole file added here, right? Lots of code. But the sort of idea with doing this is that yes, at the time of recording this, what you're looking at right in front of us, I haven't seen this code at all. Right? Do I know what this code is doing? Absolutely not yet. But just because we don't know what the code is doing yet, doesn't mean that we can't walk through it and try to understand what it's doing. Right? So the nice thing that I have found with doing this kind of approach for analyzers and code fix up is that you
know especially if you're not working on huge teams where this uh you know not understanding everything fully is potentially going to be problematic. If it's for your own projects and you're exploring this kind of stuff then if it's not working exactly as you like what's really cool is you can ask co-pilot to go help you address it. This is what I was doing with the analyzer stuff. If I found some patterns where it wasn't picking up on them or it was being too aggressive with them, then I could ask co-pilot and say like, "Hey, we have this scenario that should or should not be covered. We should add this to the set of tests and then make sure that we're addressing it." We can do the same kind of thing with the code fix up stuff as well. So, we do have this code in
front of us. What I would like to do though is double check that if we go over to some of the tests, let me close some of these things off. um this here, right? If I hover over it, probably still doesn't have the menu, which is unfortunate, but that's kind of how things are right now. I'm going to close Visual Studio, relaunch it, and we'll see if we get the generator coming back. Building AI agents is a lot of fun. Building AI agents with AI is even more fun. But that also means that we have to be a lot more careful because we've all experienced this kind of thing, right? We're building with these tools that allow us to move so much faster using AI. But that means that we can go from ideas to having something rapidly put together. And it means that we
can often skip over some of these steps that are truly important. Things like security, things like tokens and authentication. And we've all seen the memes. We've seen the posts on Twitter where people have accidentally leaked their credentials into production. That's where Ozero for AI agents comes into play. It's the complete solution to balance that speed with security. You can use features like user authentication and fine-rained authorization to ensure that your agents can only access the information that users are intended to. Their token vault functionality simplifies connecting to external thirdparty tools so you don't have to manage all of that by yourself. And for more advanced workflows, you can leverage asynchronous authorization. And that means that you can keep a human in the loop when you need to. [music] If you're serious about building secure, scalable AI agents, I highly recommend Ozero for AI agents. Check
out the link in the description to start building with Ozero today. Okay, I've relaunched Visual Studio and let's see if we have the menu available for us. We still don't. So, if I go over here, sorry, I'm trying to get the light bulb to come back up. We still don't have it. So, what I'm going to do is basically go into the chat again and talk to Copilot. My suspicion is that we don't have the generators included as a reference for the projects and that way Visual Studio does not know that it needs to include that. I have found personally that this is more of a problem the first time getting your first set of generators added in. And if you're adding new generators afterwards, then uh you still might have to reload Visual Studio, but at least the references and stuff are uh less
of a problem. So I see that we have the generator project added into the solution. However, when I'm looking at the fun with numbers tests, we have arrange act assert comments being picked up by the analyzer, but I still do not see any of the code fixup menus in Visual Studio for these highlighted analyzer errors. Okay, so let's see. And I'm going to, it probably doesn't matter, but I just going to name it like this so that we actually have it matching the name. We have the active document included in the context, so it shouldn't be an issue. But, uh, I'm giving copilot this information and keeping it high level because I want to see in the chat if it's discovering the issue. Right? The test project references the analyzer project as an analyzer, but it doesn't reference the code fixup one. We got to
make that output window significantly smaller. That's crazy talk. Let's get rid of that. Okay. Um, so you can see I've added vibecoded analyzers.codefixes project as an analyzer reference to the test project. Right. It says we might need to restart Visual Studio, but let's go look at the change. You can see that from before we had the analyzers included like this, but we did not have this new one for the generators. So, let's add that. Close that off. Um, and then even if we go rebuild it, I still think that we need to restart Visual Studio. I'm walking through these steps for you so you can kind of see. Yeah. So, it's not included. I just want to show you that so you're not wasting time on your own. You can kind of see what it looks like on my side. And then if you're like,
hey, like why isn't it showing up? This is why. I'm going to restart one more time. Okay, we have Visual Studio open yet again. Let's check it out and see. So, first thing you might notice, little detail, but we have the little red uh circle with the X through it. And then you can see that now we have this new menu item that says remove arrange act assert comment. Okay, so it shows you a preview of what it's going to do, which is what I want. Um, you can also see that we have fix all occurrences in document project and solution which is pretty cool. However, we don't actually know if this is even going to work at all. This is completely vibecoded. So, this is my friendly reminder to you that hopefully if you're doing this kind of thing at this point, make sure
you have everything committed, you have your changes saved in Git or whatever you're using for source control because if this doesn't work the way that you expect, you might accidentally delete more code than you're hoping for. So, let's go fix all occurrences. I'm just going to do it um for this one actually. Okay, so it worked. [laughter] It removed the comment, but you can see that this is ridiculously awkward. And if I go uh try it on here, uh I'm going to go fix in document. So, we should see that act and assert also get addressed, but I'm suspecting the formatting is going to be quite bizarre. So, we get a little bit of a preview. This preview window is very tiny. Sorry. So, so not too terrible, but you can kind of see that something weird's happening, right? Like if we undo it, basically
it seems to be not respecting the white space. So, if I reapply this, what I'm going to do is just copy this. Okay, so this is the sort of uh the outcome and I'm going to undo it and then I'm going to tell C-Pilot that it has this problem. We're going to see if Copilot is able to make the changes to the code fix up because again we're vibe coding this. When it makes the changes hopefully we can go review those and see exactly what it was trying to do. I just want to show that we don't have to fully understand what the source generator is doing, but we should be able to look at the changes and try to understand like a little bit better what's going on. I don't recommend that you do this kind of thing for all of the code that
you're generating because I think that over time you kind of get into this situation where you have a lot of code and you have no idea how it works. So, I do recommend you spend more time learning and understanding. But, let's go try this out. So I'm going to paste in the after. And so let's say this is what the code looked like after. I'm going to mark it with the triple back tick. Sometimes I like doing this when I'm putting in code examples mixed with just other text. Uh I haven't actually, you know, collected data to prove whether or not that helps uh significantly or not, but I prefer to kind of do it this way. And then I'm going to take this bit of code as well. Triple back tick. And so above I'm going to say um let me kind of speak
it out cuz I want to collect my thoughts. The code fix up generator mostly worked as in it removed the comments. However, it did not respect the indentation of the remaining lines that were kept in the method. And then I'm going to say here is what the code looked like before the fixup was applied. And then we'll have it. And then I will say note that the lines that are remaining inside of the method have been indented further instead of remaining at their original indentation. And we'll send this over. Now I do find that sometimes whites space is a little bit of a weird thing when you're putting into the chat. Um, you know, sometimes if you're just kind of being lazy with your prompting and stuff, it doesn't seem to really notice or care about whites space, but I have seen it work through
things where it is genuinely interpreting the whites space if you're explicitly telling it to go look at it. So, uh, we'll see. And I'm hoping that when it makes the changes, we can go review. Can already see that it started We'll probably have to restart Visual Studio again to see uh the new generator get applied. But I want to look at the code for it first. Okay, so it seems to say it's done. Let's see what it explained though. The problem is in the certain method here. The code removes the comment trivia. Uh, trivia is a word when we're talking about expressions and it's doing the sort of the Roslin part like looking through the code. The end of line after the comment, the white space before the comment. However, the issue is that the white space that belongs to the next statement line is
part of the leading trivia of that statement's token. So, if this sounds kind of confusing, this is because it's u going through and like impsing the expressions that we have in the code, right? This is why this stuff is pretty complicated, especially if you're not familiar with it. And you know, full disclosure, I said this in the previous videos, I am not an expert in any means with uh Rossin analyzers or source generators. Part of me making these videos is to show you that I am leveraging them and that I am trying to learn more about them. So, if you're watching this, you're probably uh either ahead of me on this stuff, right there with me, or maybe even just a little bit behind, but I am certainly not far ahead of you. When we remove the white space at index minus one, we're removing
the indentation that was meant for the comment line. But after that removal, the next statement's indentation is still intact. The real issue is that when there is an empty line, the structure is different. Okay. So then it says the code fix is now updated. The key change is that we now properly identify which whites space trivia belongs to the comment line by checking if it's preceded by an end of line or it's at the start of the trivia list. Okay, so it actually has it written in comments in the code. Usually I don't um I don't love this kind of thing in my code where there's a lot of comments like this, but to be honest, if this isn't a generator, I don't really mind. Usually what I'm more bothered by is if the comments reflect like the transient change. So if it leaves a
comment that's like what we just did is, you know, made this change, I'm like, I don't need to know that. I want to know the state of the code. So let's see anything else. Okay. No, it's all it's all in this spot of the code. So let's see. First check if there's white space immediately before the comment that's on the same line. Check if there's white space at the start of the comment line. Okay. And then it marks whether or not it's removing uh remove the leading white space. And then down here it's rechecking that right now. Remove the leading whites space if applicable. So before it did have some code that says if there's leading white space before the comment, right? It's just that it was doing this part incorrectly. That's interesting. I'm trying to see if there's anything else I really want to
call out. If you're kind of like, this is generally what I like to do. Like if you're not very familiar with what the code itself is doing. This might sound kind of odd, but I kind of like to look at the shape of the code. And you can see that like this line here, I'm trying to highlight it. Sorry, it's highlighting too much. This line that I have highlighted is the same as that's on one uh line 102. Okay. So it's um it's interesting that the logic itself was not really uh far off. And if I highlight this line down here, you can see that this is not the same, but it's very very similar to what we have inside of that other if statement. So on line 106, um you can see that it was saying index equals equals 1, and then it does
this uh trivia array index. It's looking for end of line trivia. So this in my opinion is really the part that needed to change compared inside here. Obviously this stuff was moved um beforehand instead of after. So that is a little different as well. But overall it's very similar in terms of shape. Let's go ahead and keep those changes. We still are going to have to restart this to get the new change. So let me just go ahead and rebuild it so we have it. Okay. It's going to fail because of these comments. We'll restart Visual Studio now. Okay. Visual Studio is back open. We'll see. We have arrange act assert and let's go try out the code fix up. We're going to do one line at a time. So that actually worked perfectly, right? So it trimmed off just the comment and kept the
indentation the same. I'm going to try it on these two for the document now. And we should see both change, but the indentation ideally remains the same. And there we go. So with that little adjustment, we were able to go back and forth with Copilot just a little bit more. And doing that meant that we could enhance it from, you know, sure it's trimming off the comments, but now our code looks kind of silly like this or something, uh, to just having it formatted the way we want. And if we wanted to try this down here, right? So arrange, I'm just kind of showing you that I'm using different casing. I'm not putting any spaces in between. Okay? And if I wanted to do this now, remove it in the project just to show you, right? Just trims those comments right out. So just a
small thing that when you're making analyzers, you can enhance them even more by using code fix up like that. I find that if you have really simple analyzers, having code fix up like that is so nice. And the reason for that is that yes, AI can go through and iterate and try to adjust build errors because you have analyzers marking those types of things as errors. But what I have noticed is that when it's going over a great deal of context, so let's say you had hundreds of test files and they all had a range act and you were trying to do that. I've noticed that AI can do some silly things because it's like, oh, I have a lot of files to go through. let me, you know, do a search and replace or do whatever. And it gets close, but then it gets
kind of stupid along the way. And I've seen it like delete entire tests and it's like it's doing way too much when all it really needs to do is go look for a range, act asert, and trim them out in that example. But um certainly if you have code fix up like that, I find that it helps a great deal. And then you can go trigger that kind of action instead of asking AI to go, you know, remove all the arrange assert comments in your codebase because it can probably do it, but it will probably also go screw up a couple of other things along the way. So, hope that helps. Uh, just a little bit of back and forth with C-Pilot, we can get a generator created for code fixup based on our Roslin analyzers. And in the next video, we'll look at one
more fix up, and that's going to be for our assert true and assert false error messages. Thanks for watching, and I'll see you in the next video.
Frequently Asked Questions
What is the purpose of the Roslyn analyzer discussed in the video?
The Roslyn analyzer in this video targets arrange, act, assert comments in the code. It helps identify when these comments are present, indicating that they shouldn't be used, and provides a way to implement code fixups to remove them.
Why do I need to restart Visual Studio after adding a new project for code fixup?
I find that when you add a new project for code fixup, Visual Studio often requires a restart to properly load the new project and its references. This ensures that the menu options for the code fixup are available and functioning correctly.
How can I improve the functionality of my code fixup generator?
These FAQs were generated by AI from the video transcript.To enhance the functionality of your code fixup generator, I recommend iterating with AI tools like Copilot. You can ask it to refine the code fixup logic, especially if you notice issues like improper indentation or formatting after the comments are removed.
