VS 2019 Extensibility - visual-studio

I've been searching the internet for the last week and can't find a working example. I'm trying to build a visual studio extension that formats the code. I've read up all the walk-throughs on Microsoft documentation. I just want to know how to create a shortcut that when pressed, will read all the text in the editor and allow me to format it and write back to the editor. I'm working with the Visual Studio 2019 SDK.
Does anyone know of a simple way to do this? Any help here would be appreciated as I'm out of ideas where to look.

You need to create a VS command, see https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-menu-command?view=vs-2019
and then assign a shortcut to it in VS options or programmatically.
In the command, get dte.ActiveDocument and use txtDoc.StartPoint.CreateEditPoint() and other points to read and modify text, see https://learn.microsoft.com/en-us/dotnet/api/envdte.textdocument.startpoint?view=visualstudiosdk-2019

Related

Can Visual Studio Intellisense display options for formating values?

I attached an image to show exactly what I mean.
Is there a way to make Visual Studio to display that dropdown menu with the different options for formating?
Thanks in Advance
Can Visual Studio Intellisense display options for formating values?
I am afraid that you cannot get what you want so far on VS.
Actually, VS Intellisense does not have such function and do not have different formatting options in the drop-down box just as your picture shows.
Also, I cannot find any VS extensions to implement this function.
So if you still want this feature on VS, I suggest you could suggest a feature on our User Voice Forum.
Besides, when you finish it, you could also share your idea ticket here and anyone who is interested in it will vote it so that it will get more Team's attention.

Refactor on save in Visual Studio 2019

I love Prettier for VS Code. I want to do similar things in Visual Studio (2019).
It now has 'Wrap, indent, and align parameters or arguments' for example (https://learn.microsoft.com/en-us/visualstudio/ide/reference/wrap-align-indent-parameters?view=vs-2019); and I'd like to do this automatically whenever I save the file.
Does anyone know if this is possible? Or if there's a free extension that can do this?
Mads Kristensen (a Microsoft employee who makes scads of Visual Studio extensions and teaches you to too!) made a JsPrettier extension for "classic" Visual Studio (ie, not VS Code):
https://github.com/madskristensen/JavaScriptPrettier
It does not format on save if you set that up in its settings.
If it's literally Prettier in Visual Studio that you're after, this isn't a bad option.
I don't know of a free plugin but you can get quite a long way towards this with some muscle memory and the built in autoformat command.
CTRL+E, CTRL+D, CTRL+S
will do code indentation and formatting, and save the file.
If you have Resharper (sorry), there's a configurable code cleanup tool which will do what you want and CTRL+E, CTRL+F, CTRL+S will do the cleanup and save.
The Format document on Save VS extension does exactly what you want, with one exception. It automatically runs Visual Studio's code cleanup command on save.
Visual Studio's code cleanup commands covers many code style preferences and can be configured with a .editorconfig file. Unfortunately one thing that is not supported by VS yet (not counting Resharper) is line wrap preferences. There is an open ticket for this: dotnet/roslyn#33872
If and when Roslyn supports line wrap preferences (presumably as a new .editorconfig preference), then Visual Studio code cleanup will enforce it and the extension will apply it on save.

Visual Studio 2017 help not working

I am using Visual Studio 2017 community. If I hit F1 anywhere in the IDE text editor nothing happens. What I really want is to highlight a method name or property, hit F1 and be taken to the online help page for that keyword, if its part of .Net.
How do I enable this? I cannot seem to find the setting to make this work, but to be honest this should be configured out of the box, right?
Ta!
Yes, It should be configured out of the box with F1 open Help page. Have you installed extensions like Resharper or other big Powerful tools? Then it could be overwritten.
Look in Tools-> Options->Enviroment-> KeyBoard and search for "Help.F1Help" there you see the Shortcut for Help

Changing text of editor for Visual Studio 2017

I'm trying to create a cool extension where I want to do something like below.
Once you have my extension installed, It will get the current line code of visual studio editor when you press some shortcut and then add something at the end of a current line of code.
P.S. I'm not building any analyzer I'm creating a productivity extension which will help people increase their productivity.
I have already gone through the MSDN documentation available for that but I'm really confused which one I should use. See the below link.
https://msdn.microsoft.com/en-us/library/dd885474.aspx
Can anybody who has created an extension guide me.

Filtering the Visual Studio toolbox

Does anyone know if it is possible at all to filter the Toolbox's items in Visual Studio using an add-in?
Visual Studio 2010 introduced the ability to search but I want to filter, for example: type in button and it must show all items containing "button", same as on this on this Delphi XE screenshot:
This is a very good answer for this question. I copied from the VS blog:
In VS 2010 Beta2, we’ve added the ability to search for controls in the toolbox by name. To use it, put focus in the toolbox (by clicking in it, for example) and start typing the name of the control you want to find. As you type, the selection will move to the next item that matches what you've typed so far.
http://blogs.msdn.com/b/visualstudio/archive/2009/10/26/toolbox-search.aspx
This is something not possible as microsoft does not reveal the secret of adding toolbox controls details completely. They make change the process for each platform and for each versions of visual studio. if we have a clear details of how they add, we can also do the similar kind of small application with search capability and add it as add-in.
Luckily Visual Studio 2012 now has that feature!

Resources