searchModule
MS Code Extension API / core/extensionAPI/modules/searchModule
core/extensionAPI/modules/searchModule
Interfaces
FindOptions
Defined in: core/extensionAPI/modules/searchModule.ts:25
Extended by
Properties
excludes?
optionalexcludes?:string[]
Defined in: core/extensionAPI/modules/searchModule.ts:33
Glob patterns for files to exclude, e.g. ['node_modules', '*.min.js']
includes?
optionalincludes?:string[]
Defined in: core/extensionAPI/modules/searchModule.ts:31
Glob patterns for files to include, e.g. ['*.ts', 'src/**']
matchCase?
optionalmatchCase?:boolean
Defined in: core/extensionAPI/modules/searchModule.ts:27
query
query:
string
Defined in: core/extensionAPI/modules/searchModule.ts:26
useRegex?
optionaluseRegex?:boolean
Defined in: core/extensionAPI/modules/searchModule.ts:29
wholeWord?
optionalwholeWord?:boolean
Defined in: core/extensionAPI/modules/searchModule.ts:28
ReplaceOptions
Defined in: core/extensionAPI/modules/searchModule.ts:36
Properties
filePath?
optionalfilePath?:string
Defined in: core/extensionAPI/modules/searchModule.ts:39
If omitted, replaces all matches across all files
matchId?
optionalmatchId?:string
Defined in: core/extensionAPI/modules/searchModule.ts:41
If omitted, replaces all matches in the given file
replacement
replacement:
string
Defined in: core/extensionAPI/modules/searchModule.ts:37
SilentSearchOptions
Defined in: core/extensionAPI/modules/searchModule.ts:44
Extends
Properties
basePath?
optionalbasePath?:string
Defined in: core/extensionAPI/modules/searchModule.ts:46
Override the workspace root for this search
excludes?
optionalexcludes?:string[]
Defined in: core/extensionAPI/modules/searchModule.ts:33
Glob patterns for files to exclude, e.g. ['node_modules', '*.min.js']
Inherited from
includes?
optionalincludes?:string[]
Defined in: core/extensionAPI/modules/searchModule.ts:31
Glob patterns for files to include, e.g. ['*.ts', 'src/**']
Inherited from
matchCase?
optionalmatchCase?:boolean
Defined in: core/extensionAPI/modules/searchModule.ts:27
Inherited from
query
query:
string
Defined in: core/extensionAPI/modules/searchModule.ts:26
Inherited from
useRegex?
optionaluseRegex?:boolean
Defined in: core/extensionAPI/modules/searchModule.ts:29
Inherited from
wholeWord?
optionalwholeWord?:boolean
Defined in: core/extensionAPI/modules/searchModule.ts:28
Inherited from
Type Aliases
SearchModule
SearchModule =
ReturnType<typeofcreateSearchModule>
Defined in: core/extensionAPI/modules/searchModule.ts:210
Functions
createSearchModule()
createSearchModule(
_extId):object
Defined in: core/extensionAPI/modules/searchModule.ts:70
Parameters
_extId
string
Returns
clearResults
clearResults: () =>
void
Clear all Search Panel results.
Returns
void
findInFiles
findInFiles: (
opts) =>Promise<SearchFileResult[]>
Search the workspace and show results in the Search Panel sidebar. Returns the matched results so the caller can also process them.
Parameters
opts
Returns
Promise<SearchFileResult[]>
Example
const results = await mscode.search.findInFiles({
query: 'TODO',
matchCase: false,
includes: ['*.ts'],
});
console.log(`Found ${results.length} files`);
getResults
getResults: () =>
SearchFileResult[]
Return the current Search Panel results without running a new search.
Returns
SearchFileResult[]
getResultsForFile
getResultsForFile: (
filePath) =>SearchFileResult|undefined
Get all results from a specific file path (if it has matches).
Parameters
filePath
string
Returns
SearchFileResult | undefined
getTotalMatchCount
getTotalMatchCount: () =>
number
Total number of matches across all current results. Useful for badge counters in custom sidebar panels.
Returns
number
replaceInFiles
replaceInFiles: (
opts) =>Promise<void>
Replace text in the workspace and refresh the Search Panel.
• No filePath → replaces ALL matches across ALL files • filePath only → replaces ALL matches in that file • filePath + matchId → replaces ONE specific match
Parameters
opts
Returns
Promise<void>
Example
// Replace a single match
await mscode.search.replaceInFiles({
replacement: 'newName',
filePath: '/sdcard/project/src/index.ts',
matchId: 'match-42',
});
search
search: (
opts) =>Promise<SearchFileResult[]>
Run a search silently using the native engine. The Search Panel state is NOT touched — perfect for background operations like "find all usages", rename-symbol preview, dependency analysis, etc.
Parameters
opts
Returns
Promise<SearchFileResult[]>
Example
const results = await mscode.search.search({
query: 'useAuthStore',
includes: ['*.ts', '*.tsx'],
excludes: ['*.test.ts'],
});
const totalHits = results.reduce((n, f) => n + f.matches.length, 0);
mscode.window.showInformationMessage(`Found ${totalHits} references`);