I’ve grown up reading Tom Clancy and probably most of you have at least seen Red October, so this book caught my eye when browsing used books for a recent trip. It’s a fairly human look at what’s involved in sailing on a Trident missile submarine…
I love writing c# code using visual studio and resharper, it is a really nice experience and resharper does a lot of boiler plate stuff and offers re-writes for you that mean you can concentrate on writing the useful bits of code. T-Sql Clippy is no where near as great as resharper but hopefully starts to show what we could actually do with t-sql and ssdt :).
What is it?
There are some things that we can do using the ScriptDom and the rest of the DacFx to help people write better t-sql code, so the things it does today is:
- Find non-sargable isnull predicates and re-writes them so that they are sargable
- Find the old style of inequality operator != and re-writes them to <>
- Find order by statements that use ordinals rather than column names and replace them with column names
- If you use the query costs highlighter it can show the actual cost rather than just highlighting the text
What does it look like?
What you see here is t-sql clippy has examined each statement, come up with a list of things it could do to automatically re-write the code and put a little circle in the margin with the number of things it can do to each statement. If you right click on the circle you see this little menu that lets you change each individual thing or all of the different things in each category. You can see in this example that it can change some != into <>’s, re-write some isnulls so that they are sargable and replace ordinal column numbers in an order by with the column names.
How to enable it?
To enable it there is a tools menu “Tools–>SSDT Dev Pack–>Enable T-Sql Clippy” – it has a check box that shows you whether or not it is enabled. It is also possible to enable it via a config file so that it is always on, ping me if you want the details.
I am basically paranoid about slowing down visual studio so I think I have struck a good balance between showing suggestions in a timely manor and not killing performance, the long and the short of it is (this has been through lots of cycles in my brain) is that it shouldn’t slow down using visual studio but as a trade off if you do not see the suggestions you need to scroll the text out of view and back again or press page up (this isn’t my idea it is basically how the add-in for visual studio works) – If people find it useful then I will likely work on making it more responsive whilst not sapping the performance but it isn’t straight forward.
If you have a super fast box or a super slow box we can control how reactive it is by using the config file %UserProfile%\SSDTDevPack\Config.xml adding something like:
<?xml version=”1.0″ encoding=”utf-16″?>
Change the CallDelayMilliSeconds to something low if you have a fast box and something high if you have a slow box.
there are some basic things that it does do to help such as ignore all types of files except for SSDT code files so if you do something like add a text file then it probably won’t show you any suggestions.
How to get it?
It is now published on the Visual Studio Gallery so head on over to https://visualstudiogallery.msdn.microsoft.com/435e7238-0e64-4667-8980-5… and grab it from there.
Any questions please shout!