Changing text of editor for Visual Studio 2017 - visual-studio

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.

Related

VS 2019 Extensibility

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

Where is the documentation on Visual Studio's decorators?

Note: This is not for Visual Studio Code, but for the full version of Visual Studio.
When developing extensions for Visual Studio Code, there is something called Decorators, which can add icons next to each line of code.
I'd like to do the same, but for Visual Studio instead. However, I can't find anything by the name "Decorators" in the documentation. Is it even called that within the full Visual Studio?
Can anyone point me in the right direction?
More specifically, I am interested in making an extension that can produce the icons seen here, and I am unsure what these icons are called in the scope of Visual Studio:
Vertical part where icons are shown is called "glyph margin" and icons in it are called "margin glyphs". Provided link will lead you to a MSDN walkthrough to create your own glyph for a line that has a "todo" text in a comment.
I found a sample that describes it pretty well:
https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/Todo_Classification

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.

How to view code documentation in Visual Studio without opening an external browser instance?

If I want to see the full documentation for a class or method in Visual Studio, I have to press F1. This opens an external browser window where I can look it up.
Now, I'd like to see the documentation within the IDE, in an integrated window, without having to mess around with a separate browser window. Additionally I'd like the documentation window to update as soon as I switch the cursor to another method/class/etc. This feature is fairly common in the Java IDEs.
Is there any way to achieve this behavior in Visual Studio?
You can install Help Viewer. See also Video.
If help viewer is already installed follow the instructions here to enable it:
When you install Visual Studio, you get the Help Viewer. To start reading help topics in the Help Viewer rather than on the MSDN download site, go to the Help menu in Visual Studio, select Set Help Preference, and then select Launch in Help Viewer. The off-line help topics for a given version of Visual Studio are available only after the final release of that version.
Beware, downloading help content for offline viewing can take a large amount of disk space!
One thing you can do is to be on any method and while pressing on control, click the method. It will open up the method or class metadata file which gives out information about the available properties and values to be passed while giving out a summary of the method/class.
Screen shot of IIdentityMessageService and what method it implements with a small desciption inside visual studio

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

Resources