Visual Studio Keymaps using F#
I always try and avoid using mouse, for example even for browsing internet I don’t use mouse rather I use vimperator and within VS.NET I use ViEmu. So for VS.NET I am always looking for keyboard shortcuts for the things that I cannot do through ViEmu. To do that in VS.NET I would have jump through hoops to figure out a keyboard shortcut for a command, I would have to navigate to Tools/Options/Environment/Keyboard, which is a pain.
There is also a plugin for ReSharper to do the same.
So I wanted something like the plugin, but something that I can query for. So I was planning to write one ,as a Visual Studio addin which is supposed to couple of things
- Pass a partial command name , which returns list of commands and their corresponding keyboardshortcuts
- Pass a Partial keyboardshortcut , which returns list of commands that have the keys as binding
And that’s when I stumbled upon Accessing Visual Studio’s Automation API from F# Interactive . That’s awesome and it gives the great power for automation with succinct code.
Here is the code for doing the things that I wanted to write
let convert (c:Command) = ((c.Bindings) : ?> System.Object |> Seq.cast<string>) let keymapsearch key = myDTE.Commands |> Seq.cast<Command> |> Seq.filter(fun k -> convert k |> Seq.exists(fun k -> k.Contains(key))) |> Seq.map(fun k -> (k.Name, (convert k ) |> Seq.head)) let commandkeysearch c = myDTE.Commands |> Seq.cast<Command> |> Seq.filter( fun k -> k.Name.StartsWith(c)) |> Seq.map( fun k -> (k.Name, convert k ))
FYI this code has to be sent to interactive FSI window within Visual Studio .NET and to use this you would still rest of the code which is available from the original post.
And here is the usage of the above functions
val it : seq<string * seq<string>> =
[("Debug.BreakAll", seq ["Global::Ctrl+Alt+Break"]);
(“Debug.Breakpoints”, seq ); (“Debug.BreakInFile”, seq );
(“Debug.BreakatFunction”, seq ); …]
val it : seq<string * string> =
("Data.SqlEditorValidateSqlSyntax", "Transact-SQL Editor::Ctrl+F5")]
The automation provides REPL to VS.NET which is really handy.