Introducing Bing Code Search for C#
Update: For the folks who have extensions that replace the Visual Studio IntelliSense experience, you can still access the feature using ‘ALT-A’ as a shortcut or assign the ‘Tools.LaunchSnippetSearch’ command to a shortcut of your choosing (under Tools->Options->Environment->Keyboard)
Imagine wanting to read a file line by line, and process those lines. Today, we’d most likely load up a web browser, visit our favorite search engine, and start crafting a well-designed set of keywords that helps the search engine understand the problem we’re trying to solve.
In the ideal case, we’d find high quality official documentation with examples, or a highly voted-on topic from one of the major forums or crowd sourced Q&A web sites. We would then scan through the options, try to figure out what’s relevant to us and do some copy/paste magic.
We wanted this to be become more accessible and make finding relevant code samples for the given tasks you’re trying to complete far easier.
Making it better
We wanted to make that experience better for you. To that end, Visual Studio, Bing and Microsoft Research have teamed up to deliver a DevLabs experience that takes code search to the next level.
When you find yourself looking for a code-sample that you could leverage for a task, you can trigger the new Bing Code Search experience directly from IntelliSense.
That triggers a spacious inline experience similar to Peek-Definition, focused on code-search. You type in the task you’re trying to complete, for instance ‘read a file line by line’, press Enter, and get results that are tailored for your code.
Behind the scenes, that query is securely beamed up to Bing along with contextual pieces that help us hone in on the fuller meaning of that query. We use meta-data like the project type, semantic context (using the new C#/VB compiler services aka ‘Roslyn’!), and a few other sprinkles of Microsoft Research magic.
Those pieces along with the query then leverage Bing’s enormous search index and keyword analysis to track down potential pages that might contain high quality examples you can learn from.
From those pages, we isolate and rank the relevant code samples, using a large number of syntactic and semantic code metrics.
That’s when you conveniently see the ordered results in Visual Studio, right around your code, along with our projected quality estimation of the sample and its source (so you can go dig in).
Leveraging the web
This new technology implementation can use virtually the entire web as its source. However, we found that partnering with a few of the top web sites where some of the richest code examples live was more than sufficient in uncovering answers for many of the top user tasks, and it allows us to focus our efforts.
DevLabs means experimentation
To bring the technology public early on, we selected a sub-set of the problem to tackle first. Specifically, Bing Code Search works solely for C# solutions, and we’ll look for ways to generalize the approach to more languages.
Make sure you grab the extension from the Visual Studio Gallery page, use it and let us know what you think!
Visual Studio, Bing and Microsoft Research teams
|Ala Shiban (@AlaShiban) – Program Manager, Visual Studio Editor