SSMS - develop an extension to modify selected strings to be with quotes and comma separated - visual-studio-2017

While working in SSMS - it's a very frequent operation to copy some array of strings separated with a new line (\r\n) and then quote it and separate with a comma (just to use in IN SQL clause). Now I have to hold ALT key and do a vertical selection. I would like to develop an add-in to SSMS and assign it to hotkeys, but actually there is no info at all for the modern SSMS (starting with 17 version) how to do this.
There is a lot docs how to develop extensions for VS, but no for SSMS.
I realize this not a SO question, but don't know where to ask - maybe there is some doc how to develop SSMS extensions starting from v17?
P.S. Maybe SSMS already have an extension to quote and separate with commas strings selected?
EDIT:
Ok, I made an extension and it works well with VS, have no idea how to "move" it into SSMS

The idea is to create VSIX project using Visual Studio, compile it and copy to SSMS extension folder.
After that you need to configure SSMS to skip validation for 'unknown' VSIX extensions.
I recommend to check this approach:
https://github.com/benlaan/sqlformat
Tutorial from MS:
https://learn.microsoft.com/en-in/visualstudio/extensibility/extensibility-hello-world?view=vs-2017
Code-project tutorial:
https://www.codeproject.com/Articles/1243356/Create-Your-Own-SQL-Server-Management-Studio-SSMS

Related

Auto Formatting statements in VS Code

I am new to VS Code coming from Visual Studio 2017 and I really miss the auto-formatting options there. Like:
Automatically format statement after I type a ;
Automatically format block when I type }
Automatically format braces when they are automatically completed
My question is that is there any way to get these on options on VS Code, such as some tweaks on the settings.json?
I assume the C++ extension is enabled. To check if it is, go to the extensions tab on the left, and at the top click the three dot button and click "Show Built-in Extensions." That's where the C++ extension would be.
And I assume you've already checked this out, but there is some additional info here in the docs about including a .clang-format file and the fallback option if you don't.
vscode-cpp-docs
In theory you should be able to format using the provided "editor.formatOnType" setting. If not, try installing the Clang-Format extension and see if that works.
Clang-Format

Enforcing coding styles in Visual Studio and VIM

I work with a medium sized team of developers, with half being Linux developers using VIM on Ubuntu and MacVIM on OSX, and the other half being Windows developers using Visual Studio 2010 or later.
A fair bit of time has been wasted in the past when handling things like SVN operations failing due to mixed line endings, or changes to code reviews due to a mix of hard-tabs versus spaces-as-tabs (and sometimes of varying lengths, ie: 4 spaces vs 2 spaces vs 8 spaces, etc), and I would like to put an end to it.
The plan is to adapt a common coding style we've designed, which is almost identical to the Linux Kernel coding style. For all developers, we could require them to run their code through the checkpatch.pl script used by Linux kernel devs, but our code includes C, C++, and C#, so we would need to generalize the rule checker script beyond just ANSI C.
Is there a generic way to implement a rule set for VIM, and another for Visual studio? We'd like to generate a script that checks entire files, which could be hooked into our version control system so that it's run on code before commits complete, and perhaps as a run-time script to enforce the style as coders type?
Thank you.
EditorConfig seems to do exactly what you want in Vim, Visual Studio, and a lot of other editors and IDEs.
The run-time "script" is the best first-line of defense. In this case, it will be various Vim and Visual Studio settings to help enforce your code style. That alone will catch quite a few problems. Keep in mind, this won't catch everything, but will encourage the coding style you want.
I've worked across Linux & Visual Studio in a team before (and sometimes by myself). The whole Tabs/Spaces issue drove me nuts as there would be wholesale groups of lines that were either shifted WAY over or not enough. To solve this, I ended up using these three settings in Vim (also set similar values in Visual Studio), thus catching one class of issues at the root.
Vim
set expandtab
set shiftwidth=4 " Mainly for if/for/while/general {} block indentation. 4 spaces.
set softtabstop=-1 " Allows us to use the Tab key and have it act like shiftwidth.
Visual Studio
Insert spaces when Tab key is pressed.
Shift 4 spaces on indent inside code block
They key is getting rid of the Tab characters, or at least having both systems use the SAME SETTINGS (i.e. both using Tab with the same values or SPACEs substituting as Tabs)
Something to watch out for:
Someone copying a file from one Operating System to a different one and then checking the file into SVN on that machine. SVN will blindly commit, say, a DOS line-ending file from a UNIX system. You want to checkout/commit files on the same system only. Otherwise, checking out/editing/committing files all on the same OS should present no issues, as SVN can convert the line endings upon checkout. You can "fix" this by loading a file into Vim and then converting the line-endings to the particular OS you want by typing ":set fileformat=dos" (if you want to change to Windows-style), ":set fileformat=unix" (for unix style), or finally ":set fileformat=mac" for Mac.
As far as the code style goes, as you probably already know, both Vim and Visual Studio offer lots of flexibility there. While I cannot give you the specific settings for Vim, the options to look at are
autoindent
cindent
cinoptions (implied from cindent)
cinkeys (implied from cindent)
comments (default is probably fine, but here for thoroughness)
So, you will want
set autoindent
and cindent should be automatically set when editing a C or C++ file. The defaults for cinoptions and cinkeys are ok for me, but I have tweaked them in the past when working with a different group.
Don't forget about using the '=' command over a selected range of lines to reformat the code! This can be very handy!
I shy away from the completely automatic SVN backend method because it may take longer than you expect to get it right, and when it screws up, it will probably take more time out of your day than you expect as well. After all, you really just want to be productive, right?.
Discipline up front is key!

How can you "global replace" in Crystal without visual studio?

I had to replace a DB table with embedded SQL in Crystal.
Now I find myself completely amazed that (apparently) I have to open thirty or more formulas one at a time and replace the table name with "Command"
If I select "All formulas" in the replace widget, all the replace controls are disabled.
This is so stupid that I figure I am missing something.
I am working the Crystal files directly in the Crystal IDE. Not able to fire up a C# or VB program to do it for me. I did try a couple of times in the past to edit things in Crystal files with regexp/perl/editors and similar, but that failed due to the Crystal file format.
(S.O. says my question "appears subjective and is likely to be closed." Huh?)
Transitioning from linked tables (Database 'expert') to a command (or the other direction) has always been painful (I've been using the product since v4)--CR doesn't have a good (or even mediocre) way to do this. You should be able to map your command to a single table, but you'll lose field (from the canvas) during the process (because CR will remove unmapped fields). Best practice is to always use a command or to wrap each table.field element in a formula field.
With earlier version of the product, I might have suggested using the SDK to make the change. However, this level of control has been shifted to BusinessObjects' RAS SDK.
If you are interested, have a look at my RptToXml project or its C# replacement.

Are there any Visual Studio add-ins for true 'smart tabs'?

'Smart Tabs' concept allows to automatically insert tab character for block indentation and space characters for in-block formatting. It's described here. Unfortunately, Visual Studio's 'smart tabs' option in text editor settings just indents text on enter press. Same name, completely different and near useless thing :). So, maybe someone knows of a visual studio addin that can change how 'tab' key work so it will insert tab characters and space characters according to rules mentioned above? Any hints are welcome.
Update: I need it for C++. According to comments, ReSharper can do something like this, but only for Basic and C#.
I have mapped the tab-button to Edit.FormatSelection in Visual Studio to achieve this and it works very well for me. I have also remapped the normal functionality of tab so that I still can access them (Edit.InsertTab and Edit.TabLeft).
If no one comes up with an "as-you-type" utility, then Astyle with its convert-tabs and indent=tab options will reformat code after-the-fact.
ReSharper does this pretty well, and is highly configurable.
Have you looked at Visual Assist?
It's been a while since I used it (back on VC++ 6.0!), and I can't see a mention of "Smart Tabs" on the home page, but it might be there somewhere.

Is there a way to prevent a "keyword" from being syntax highlited in MS Visual Studio

MS Visual Studio editor highlights some non-keyword identifiers as keywords
in C++ files. Particularly "event" and "array" are treated as keywords.
That's very annoying to me, because they are not C++ keywords.
I know how to add my own keywords to the list of syntax-highlighted identifiers,
but how to remove existing built-in ones?
I'm aware that this may require patching some executable files.
So does anyone know how to do this?
Thanks to article mentioned by Steve Guidi, I was able to find executable file that contains Colorizer and IScanner classes. It is named vcpkg.dll and located in /Microsoft Visual Studio 8/VC/vcpackages. (I'm using Visual C++ 2005 Express Edition, things may be different in other versions.)
The vcpkg.dll contains null-terminated UTF-16 encoded strings. I've opened it with hex editor, and searched for "array". There is only one such string in the file, so I've replaced it with "arrry". (It is important to maintain relative alphabetical order with respect to other keywords.) Then I've searched for "event", it shows up in several places, but there is only one that isn't part of some longer string, so I've replaced this one with "evvvt". After starting Visual Studio, it turned out that "array" and "event" weren't any longer highlighted, but "arrry" and "evvvt" were!
Of course this is an ugly hack, and it will void your warranty,
and probably goes against Microsoft EULA, but what a relief for the eyes!
Anyway, if you want to do it, be careful and remember to backup the file.
It doesn't look like a disable-syntax-coloring feature is exposed in a user-friendly way.
The only way I can think of selectively disabling syntax coloring is to create a new syntax coloring plugin for the IDE, and list all of the keywords you want colored. Microsoft gives information in this article on how to accomplish this task.
The drawback to this approach is that your IDE will now have two C++ languages and I'm not sure how it will select which plug-in to choose from once it loads a .h or .cpp file. However, this article suggests that you can override the existing C++ plug-ins by rewriting some registry keys.
I think the only "semi-practical" way to accomplish this to create a Visual Studio package that uses Text Markers to selectively cover up the keywords you don't want colored. Even that is not a little one-day task. Edit: Probably not even a full week task for someone not intricately familiar with the Visual Studio API and all its quirks, especially not getting it bug-free.
In other words, you probably want to just ignore them.