Visual Studio Online Search–Get in Now!

SourceCode-MatrixMost anyone that has been using a version control system for any amount of time has come to that point in their development career where they’ve asked the question – “I know I’ve seen that code before but where?” You don’t want to go through the hassle of having to recreate something you (or someone else) has already spent a great deal of time and effort building, testing and tweaking until it fits your needs perfectly. You just want to find it and reuse it!

If your version control system happens to be Team Foundation Server or Visual Studio Online then you have likely done something like this before (or at least have thought about doing it):

  1. “Get Latest” (or git fetch) on all source code projects you want to search in.
  2. Wait while all the source code is downloaded (hopefully not filling up your disk storage in the process – especially for Git-based repos!).
  3. Use a tool such as Agent Ransack to search, within files, for the code your looking for.
  4. Curse all the false positives that turn up in comments, string literals, etc.

What you really want is a search feature that truly understands the semantics of your code and is built into your version control system. As of a couple of days ago, Microsoft has released, in Limited Preview, a new VSO Search feature that does exactly this.

Before we jump into some of the capabilities of this new search feature, let’s cover the limitations (as it is offered today in the Limited Preview version):

  • The Search feature is currently available for VSO accounts hosted in the North Central or South Central U.S. region. This feature will eventually come to all regions, just not yet.
  • The Search feature is currently limited to Git repos only. Support for TFVC repositories will be available in a future release.
  • READ CLOSELY: The Search feature is currently available by request only. If you want to try the new Search feature out, e-mail Microsoft @ vsosrch@microsoft.com along with the name of your VSO account (e.g. myaccount.visualstudio.com). There are a limited number of seats available for the Limited Preview so act quickly!

That said, what can VSO Search do for you? Well, it can:

  • Search for code in one or all of your VSO projects using the search box on your account’s overview page:

    image

  • Search for code in the current project only while in the Code tab:

    image

  • Go to the SEARCH tab to search across one or more projects:

    image

Within the Search field, enter your search text and press <Enter>. You can combine multiple criteria using AND, OR, or NOT (must be in uppercase). You can also use parentheses to group parts of your query and set precedence.

You can also make use of wildcard characters such as * and ?.

Searching for the text ‘Order’ might return something like this:

image

Each instance of the text found based on the query has been highlighted.

Note that in the above example, the word ‘order’ shows up both as a variable name (order) and a class name (Order). What if we want to return results only where Order is used as a class name? simple, just prefix the search text with “class:” (without the double quotes).

Searching for “class:order” returns the following:

image

Notice that only the class name Order is highlighted. The usages of order in OrderId and OrderDate are not highlighted – because they are not class declarations.

The current search type limiters include:


Code where “findThis” appears
as


Search for

argument

arg:findThis

base type

basetype:findThis

class definition or declaration

class:findThis

class declaration

classdecl:findThis

class definition

classdef:findThis

comment

comment:findThis

constructor

ctor:findThis

declaration

decl:findThis

definition

def:findThis

destructor

dtor:findThis

enumerator

enum:findThis

extern

extern:findThis

field

field:findThis

friend function

friend:findThis

function

func:findThis

function declaration

funcdecl:findThis

function definition

funcdef:findThis

global

global:findThis

header

header:findThis

interface

interface:findThis

macro

macro:findThis

macro definition

macrodef:findThis

macro reference

macroref:findThis

method

method:findThis

method declaration

methoddecl:findThis

method definition

methoddef:findThis

namespace

namespace:findThis

property

prop:findThis

reference

ref:findThis

string literal

strlit:findThis

struct

struct:findThis

struct declaration

structdecl:findThis

struct definition

structdef:findThis

template argument

tmplarg:findThis

template specification

tmplspec:findThis

type

type:findThis

typedef

typedef:findThis

union

union:findThis

You can view the full list of search features on the “Find your code” help page here.

Although this feature is currently in Limited Preview I have already found it to be an invaluable feature. I can only image it is going to get better with time as Microsoft gains feedback from early adopters. I look forward to this feature being available across all VSO accounts and repo types!

Remember, if you’re interested in trying this out for yourself, request access now!

You can read more about this new feature here.

Related Posts