Functional code search
Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018
Find the code you need faster with functional code search. This article explains how to refine your search across repositories using code types and other functions with the Code Search Marketplace extension for Azure DevOps.
- Install Code Search
For more information, see Install and configure search.
- To use Code Search, you must have at least Basic access.
- Users with Stakeholder access don't have access to code, so they can't search for code.
- Users with Stakeholder access for a public project have full access to code, so they can search for code. To access code in a private project, you must have at least Basic access.
- When you're searching across the organization or collection, only results for which a project member has access are listed.
Code search best practices
- Start with a broad search and then use filter operators to narrow it down by project, repository, path, file name, and more.
- If you don’t know the exact term, use wildcards to expand your search and Boolean operators to refine it.
- To get more information about a code item, hover over it and use the shortcut menu to search for that text in all your projects and files.
- To trace how your code works, use the shortcut menu to search for related items like definitions and references in a file or in the search results.
- To find the implementation of an API or other code element, use code type filters to search for specific kinds of code such as:
- namespaces, and more.
Code search does not work for forked repositories.
Functions to find specific types of code
To create your query faster, choose functions and keywords from the drop-down list as you type. Select Show more to see all the options. You can combine different functions as needed.
You can also use filters from the left column to narrow your search. Show more shows you all the functions and keywords.
Or, you can type the functions and parameters in the search box. The table below lists the functions for finding specific types or members in your C#, C, C++, Java, and Visual Basic.NET code.
|To find code where findThis appears as a ...||... search for argument arg:findThis|
|Class definition or declaration||class:findThis|
Functions to select projects, repositories, paths, and files
Functions make it easy to narrow the search to specified locations, specific types of files within these locations, or specified filenames. Narrow the search to a specific location using the
path filters. Mix and match the following functions as required.
|Find all occurrences of the word QueueJobsNow in the Fabrikam project.||
|Find all occurrences of the word QueueJobsNow in the Contoso repository.||
|Find all occurrences of the word QueueJobsNow in the path VisualStudio/Services/Framework and its subpaths.||
|Enclose the argument to the filter in double-quotes if it contains a space.||
|Find all occurrences of the word QueueJobsNow in all files where the filename starts with queueRegister.||
|Find all files with the name QueueRegister without an extension. Use quotes to find files without extensions.||
|Find all occurrences of the word QueueJobsNow in only C# source files. A plain text search string that doesn't include file type functions also finds files where the string matches part of the filename.||
Find related items or other terms
Code Search lets you interactively expand your search based on previous results. For example, you can widen your search to related files when you are tracing or debugging code.
Right-click on a term in the file and start a new search for other files with the same term. You can search for it as text, or as a definition or reference if it is an object name.
For more information about the following search functions, see Get started with search
- Exact match
- Boolean operators
More code search operations
Here are some more code search functions. You can search for code types in C#, C, C++, Java, and Visual Basic.NET files. To open the search results in a new tab, select Ctrl + Enter from the main search box. To switch to the new tab in Google Chrome, select Ctrl + Shift + Enter.
|Find all comments||History:Keyword|
|Find all instances of "ToDo" comments in your code||Select
|Search in specific locations, such as within a particular path||Use a search string such as
|Search for files by name or just by file extension||
Search Git projects and repositories
A Git project has a list of repositories. To expand your search, check the project and repository boxes. You can search all or more projects, or fewer projects and repositories. If there are many projects or repositories, select Show more to see them all.
Code Search can index different branches in a Git repository. It only indexes files in the default branch of your Git repositories by default. The default branch is usually main. To index other branches, go to the Options tab in the Repositories section of the project settings page.
Search TFVC projects
TFVC projects display only the folders that you can read. You can't see any other projects or folders. To filter your search, choose folders from the tree.
Code Search saves your last settings, such as the project and repository or path that you searched in. When you want to search in a different scope, select Clear all links to clear the checkboxes and search across all projects. The first 100 hits or matches in the target files are highlighted by Code Search in the results pane.
Search code with REST API
You can use APIs to extend or supplement the capabilities listed in this article. For information about Code Search with REST API, see Fetch Code Search Results.