Visual studio SDK - Get current line seperator - visual-studio

I'm working on a visual studio extension that requires me inserting lines of text into the current user document. Since line separators are not a universal thing, and every operating system, text editor or end user uses a different style, I would like to make sure I am using the correct style for the current environment when I am inserting text.
I tried looking for some VS SDK global that stores this value but I couldn't find it. All I found was VSConstants.VSStd97CmdID.LineBreak which is supposed to be the command number for inserting a line break. Unfortunately I need this as a string and not a command.
So, does there exist such a global somewhere ? The editor itself defiantly stores this since there is a menu option for it

Related

Visual Studio -> wrap every parameter

Using Visual Studio 2019, I found a really useful refactoring option in 'Quick actions and refactoring':
(might come from PowerTools, whatever)
I just wondered how:
I can make this wrapping settings a default formatting settings
Or apply this formatting on my whole solution at once (without resharper)
For the later, a solution with Visual Studio Code would be perfect as well !
Thanks for your help
You can try using Rewrap extension which formats code, comments, and other text to a given line length (80 by default).
The main Rewrap command is: Rewrap Code / Comment, by default bound to
Alt+Q. Put the text cursor inside a comment line, block or plain text
paragraph and invoke the command to wrap. You can also select just a few lines, or multiple comments in one selection.
There is currently an Open request for this in the VS Code Issue tracker on GitHub

Untabify not making changes in TFS

I have some old source code which uses tabs as white space (\t), and some newer code after we changed our source code convention which uses 4 spaces instead. Those two look the same on Windows just fine, but on Linux in Vim a tab is 8 spaces, so new code with 4 spaces and old code with 8 spaces looks all funky.
I tried to untabify the source files, and check them in, but the TFS update just completely ignores those, and I get nothing changed when checking in. How can I check in the change from Tab to 4 spaces?
This may due to your Visual Studio side setting and thus the changes could not be display.
For the mixed tabs and spaces , try to change your visual studio text editor setting. You can decide if you want visual studio to insert spaces or tabs here:
Tools/Options/ -> Text Editor/All Languages/Tabs, select the "Keep Tabs" option.
After setting this, the tab will changed as → instead of -like space.

Generate code with user's formatting in VS extension

I have a Visual Studio extension that generates some code. How do I respect the user's formatting settings (like Tab vs Spaces, this. qualifier, etc) when generating it?
I know you can make a syntax tree in Roslyn but you still need to specify what exactly is in all of the whitespace. Is there a global way to apply this formatting or do we need to try and read all the individual settings?
If so, how would I read the tab vs space and this. prefix settings, respecting .EditorConfig files?
Currently my extension just builds a string assuming default settings, writes it to a file and adds it to the solution.
You need the VisualStudioWorkspace object (which I assume you already have, otherwise take a look at Josh Varity's blog post here)
Generate your text and add it to the project using AddDocument
Call GetOptionsAsync to get the set of options (.editorconfig, user settings, etc) that apply to this document
Call Formatter.FormatAsync passing in the optionset that was given to you by GetOptionsAsync
Update the formatted document by calling WithDocumentText on the solution.

Convert virtual spaces into real tabs in Visual Studio sdk

My Visual Studio extension, is arranging Tab Sizes using ITextParagraphPropertiesFactoryService interface. That class is doing a great job, and helps me to set tab widths for all existing lines, but I have a problem to set tab sizes for new virtual line.
In other words, Visual Studio is setting caret position in VirtualSnapshotPoint, and converting it to real tabs only when user enters some symbols.
Now, Is it possible to force Visual Studio to create real tabs instead of virtual spaces? I try to create edit on view, and insert real '\t' symbols, but VS still converts it back to virtual... This happen for both, block and smart indent tab settings
So the behavior of blank lines being virtual space only is by design, and as best I know not changeable. If there's a specific problem with it, please update the question and we can go from there.

How to triple-slash selected text in Visual Studio 2010

In Visual Studio 2010 we can Comment selected text via Ctrl+E,C - This prefixes selected lines with the double-slash.
Is there a way to select text and have VS2010 prefix the selected lines with a triple-slash?
For the curious; I am adding XML comments to my c# code. Specifically, I am adding example code within the <example><code></code></example> section of my comments. I'm am building the sample code in a throw-away console app (just to make sure I'm creating code that works). When satisfied with the sample code, I copy/paste it into my app that I'm adding XML Comments to. When I paste the sample code, I have to manually add all the triple-slashes. I'm getting kinda bored doing this, so I'm hoping there is a way I can have VS2010 do this for me.
There is no built-in command to do that, AFAIK.
However, you can do it using VS's built-in advanced text-editing features.
Hold down Alt, select a zero-width column of text at the beginning of the lines, then type ///. This will type into all of the lines simultaneously.
You can select that with the keyboard by pressing Home (as applicable), then repeatedly pressing Alt+Shift+↓.

Resources