Functional code search
Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018
Functional code search extends your ability to refine your search across repositories beyond what's documented in Get started with search. To do code searches, the Code Search Marketplace extension must be installed for your organization or collection.
- 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
- Get the results you want even faster by starting with a higher-level search. You can narrow your search by using project, repository, path, file name, and other filter operators.
- When you're not sure of the exact term you're looking for, Use wildcards to widen your search and Boolean operators to fine-tune it.
- Find more information about an item of interest faster and with minimal efforts. When you find an item of interest, place the cursor on it and use the shortcut menu to quickly search for that text across all your projects and files.
- Easily trace how your code works by using the shortcut menu to search for related items such as definitions and references – directly from inside a file or from the search results.
- Go quickly to the implementation of, for example, an API your code might be taking dependency on by narrowing down your results to exact code type matches. Use code type filters to search for specific kinds of code such as:
- namespaces, and more.
You can't search code in forked repositories.
Functions to find specific types of code
As you enter your search, select functions and keywords from the drop-down list to quickly create your query. Use the Show more link to display all the available functions and keywords. Mix and match the functions as required.
You can also select one or a combination of filters from the list in the left column. Again, the Show more link displays all the available functions and keywords.
Instead, you can enter the functions and parameters directly into the search. The following table shows a list of functions for selecting 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 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
One of the powerful features of Code Search is the capability to expand your search interactively, based on the results of previous searches. For example, you can easily broaden your search to related files when tracing or debugging code.
Place the insertion point on a term in the file and open the shortcut menu (mouse: right-click) to start a new search for other files containing the selected term. You can search for it as text, for the definition if you select an object name, or for references to a selected object.
For more information about the following search functions, see Get started with search.
- Exact match
- Boolean operators
More code search operations
See the following examples of even more code search functions. You can use the code type search functions with files written in C#, C, C++, Java, and Visual Basic.NET. Open the search results in a new browser tab from the main search box, and select Ctrl + Enter. In Google Chrome, select Ctrl + Shift + Enter to switch the focus to the new browser tab.
|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
In a Git project, you see a list of the repositories that it contains. Use the project and repository checkboxes to widen your search. You can search more or all projects, or narrow your search to fewer projects and repositories. If there are more than a few projects or repositories, use the Show more link to see them all.
Code Search can index multiple branches in a Git repository. By default it indexes files in only the default branch of your Git repositories. Your default branch is usually the main branch. Specify the branches for each repository, indexing in the Options tab of the Repositories section, project settings page.
Search TFVC projects
In a TFVC project, you see a list of folder paths in that project for which you have read access - you won't see any projects and folders for which you don't have read permission. Select paths in the folder tree to narrow your search if necessary.
Code Search remembers your last settings, such as the project and repository or path that you searched in. Clear the checkboxes to search across all projects easily with the Clear all links when you want to search in a different scope. In the results pane, Code Search highlights up to the first 100 hits or matches found in the target files.
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.
Submit and view feedback for