![]() ![]() I hope you enjoyed or learned something from the various trials and tribulations I’ve been through over the past couple weeks trying to get all of this working. With that, if you made it this far, thank you, friend. And while it solves HALF of the communication issue, Part III will go into greater depths on how to get TWO-WAY communication between them. So, Part II will discuss how to get the Code Lens provider talking to the main extension / project. There you have it – a working Code Lens provider for Visual Studio! I’m going to end this post here, as it’s getting a bit long, but I’ll follow up in a short while to illustrate something that I ran into (and maybe you haven’t considered this yet, but…), since the Code Lens process runs “out of process” with your main extension / Visual Studio – your custom Code Lens provider can’t talk to your main extension if you need any services / data / etc., that you already have in place there. Opening the same solution / project in the Experimental instance, you should get something like this (sorry for the highlighting difference between code and screenshot here) – Our Custom Code Lens entries are working!Īs you can see, our Description property shows up inline (second because of our Priority) of the other CodeLens entries, TooltipText shows up when hovering the entry, and since we return a null CodeLensDetailDescriptor from our GetDetailsAsync, clicking on the CodeLens entry pops up a secondary pane with no data as seen below – Clicking the Code Lens entry shows a secondary pane for extra dataįinally, you can disable our “Custom Code Lens Provider” by unchecking the box in the CodeLens settings of the Options dialog – Enable / Disable Code Lens from the Options dialog Now with any luck, this will build, and you can run it in the Experimental instance of Visual Studio! Public event AsyncEventHandler InvalidatedAsync Public class CodeLevelMetricsProvider : IAsyncCodeLensDataPointProvider You should end up with something like this – First, create a new class, CodeLensDataPointProvider.cs and implement the interface IAsyncCodeLensDataPointProvider. You will need two new classes that follow a certain pattern to accomplish this. I won’t go through that here, so let’s assume you have a new, empty, Class Library project called CodeLensProvider.csproj in your (existing) Visual Studio extension solution. Like I said, first you’ll need a new project within your existing Visual Studio extension solution. With that in mind, let’s jump into some code. It runs out-of-process from your main extension / Visual Studio.It requires a separate project in your solution.The biggest things to note about extending CodeLens is that – Having said that, MAYBE it is possible in VS2017, but I’m not diving any deeper into that rabbit hole to figure it out. ![]() This mainly boils down to the various interfaces, packages / references that need to be used. ![]() If you have your own Visual Studio extension, and you want to add your own custom CodeLens entries – I’m here to help, because I just (finally!) figured out how to do this (plus a few extras!)įirst, let me start by saying that I’ve only “proven” this method with VS2019 and “disproven” it with VS2017, but I see no reason why it wouldn’t / shouldn’t work with VS2022.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |