Skip to content

Interface: SearchService ​

Defined in: packages/sdk/src/search-service.ts:131

Cross-file content search, exposed as ExtensionContext.search. Runs a native search engine in the host (off the UI thread) over the workspace, honoring .gitignore, and resolves with matches grouped by file.

The contract is intentionally extensible: a future replace capability can be added as an additional method without breaking this one, and SearchMatch.ranges + SearchFileResult.path already carry the precise locations such a replace would target.

Methods ​

ts
search(query, options?): Promise<SearchResponse>;

Defined in: packages/sdk/src/search-service.ts:148

Search file contents under SearchOptions.cwd (the active workspace folder by default). Resolves with an empty SearchResponse for an empty query. Rejects only if the search could not be started (e.g. the cwd is denied); a search that simply finds nothing resolves with no files.

Parameters ​

query ​

string

The text or regex (see SearchOptions.regex) to find.

options? ​

SearchOptions

Optional SearchOptions.

Returns ​

Promise<SearchResponse>

Example ​

ts
const { files, totalMatches } = await ctx.search.search("tokyo", {
  caseSensitive: false,
  excludeGlobs: ["**/dist/**"],
});