Skip to main content

searchModule

MS Code Extension API


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?

optional excludes?: string[]

Defined in: core/extensionAPI/modules/searchModule.ts:33

Glob patterns for files to exclude, e.g. ['node_modules', '*.min.js']

includes?

optional includes?: string[]

Defined in: core/extensionAPI/modules/searchModule.ts:31

Glob patterns for files to include, e.g. ['*.ts', 'src/**']

matchCase?

optional matchCase?: boolean

Defined in: core/extensionAPI/modules/searchModule.ts:27

query

query: string

Defined in: core/extensionAPI/modules/searchModule.ts:26

useRegex?

optional useRegex?: boolean

Defined in: core/extensionAPI/modules/searchModule.ts:29

wholeWord?

optional wholeWord?: boolean

Defined in: core/extensionAPI/modules/searchModule.ts:28


ReplaceOptions

Defined in: core/extensionAPI/modules/searchModule.ts:36

Properties

filePath?

optional filePath?: string

Defined in: core/extensionAPI/modules/searchModule.ts:39

If omitted, replaces all matches across all files

matchId?

optional matchId?: 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?

optional basePath?: string

Defined in: core/extensionAPI/modules/searchModule.ts:46

Override the workspace root for this search

excludes?

optional excludes?: string[]

Defined in: core/extensionAPI/modules/searchModule.ts:33

Glob patterns for files to exclude, e.g. ['node_modules', '*.min.js']

Inherited from

FindOptions.excludes

includes?

optional includes?: string[]

Defined in: core/extensionAPI/modules/searchModule.ts:31

Glob patterns for files to include, e.g. ['*.ts', 'src/**']

Inherited from

FindOptions.includes

matchCase?

optional matchCase?: boolean

Defined in: core/extensionAPI/modules/searchModule.ts:27

Inherited from

FindOptions.matchCase

query

query: string

Defined in: core/extensionAPI/modules/searchModule.ts:26

Inherited from

FindOptions.query

useRegex?

optional useRegex?: boolean

Defined in: core/extensionAPI/modules/searchModule.ts:29

Inherited from

FindOptions.useRegex

wholeWord?

optional wholeWord?: boolean

Defined in: core/extensionAPI/modules/searchModule.ts:28

Inherited from

FindOptions.wholeWord

Type Aliases

SearchModule

SearchModule = ReturnType<typeof createSearchModule>

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

FindOptions

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

ReplaceOptions

Returns

Promise<void>

Example
// Replace a single match
await mscode.search.replaceInFiles({
replacement: 'newName',
filePath: '/sdcard/project/src/index.ts',
matchId: 'match-42',
});

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

SilentSearchOptions

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`);