Path: blob/main/extensions/copilot/src/platform/remoteSearch/common/codeOrDocsSearchClient.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type { CancellationToken } from 'vscode';6import { createServiceIdentifier } from '../../../util/common/services';7import { CodeOrDocsSearchRepoError } from './codeOrDocsSearchErrors';89/**10* Represents the base scoping query for code or docs search. A scoping query is used to provide what exactly you want to search through.11*/12export interface ICodeOrDocsSearchBaseScopingQuery {13/**14* The repo(s) to search in. When only one is specified, any errors are thrown. If multiple repos are specified,15* then they are returned in the response.16*/17repo: string | string[];1819/**20* The language to search for. If not provided, all languages will be searched.21*/22lang?: string[];2324/**25* The language to exclude from the search. If not provided, no languages will be excluded.26*/27notLang?: string[];2829/**30* The path to search for. If not provided, all paths will be searched.31*/32path?: string[];3334/**35* The path to exclude from the search. If not provided, no paths will be excluded.36*/37notPath?: string[];38}3940/**41* Represents a scoping query for code or docs search with only 1 repo. A scoping query is used to provide what exactly you want to search through.42*/43export interface ICodeOrDocsSearchSingleRepoScopingQuery extends ICodeOrDocsSearchBaseScopingQuery {44repo: string;45}4647/**48* Represents a scoping query for code or docs search with multiple repos. A scoping query is used to provide what exactly you want to search through.49*/50export interface ICodeOrDocsSearchMultiRepoScopingQuery extends ICodeOrDocsSearchBaseScopingQuery {51repo: string[];52}5354/**55* What one of the results looks like that is returned by codesearch or docssearch.56*/57export interface ICodeOrDocsSearchItem {58path: string;59contents: string;60title?: string;61score: number;62repoName: string;63repoOwner: string;64range: { start: number; end: number };65languageId: string;66languageName: string;67type: 'snippet' | string;68url: string;69ref: string;70commitOID?: string;71algorithm?: 'semantic' | 'bm25';72}7374/**75* The result of a code or docs search.76*/77export interface ICodeOrDocsSearchResult {78results: ICodeOrDocsSearchItem[];79errors: CodeOrDocsSearchRepoError[];80}8182export interface ICodeOrDocsSearchOptions {83/**84* The number of results to return. Default is 6.85*/86limit?: number;8788/**89* How similar you want results to be.90*/91similarity?: number;92}9394/**95* The interface for the docs search client.96*/97export interface IDocsSearchClient {98readonly _serviceBrand: undefined;99100/**101* Search for related chunks using GitHub's search APIs102* @note When only a single repo is specified, we return the results as an array and also throw errors.103* @param query The search query104* @param scopingQuery A scoping query with a single repo specified.105* @param options The search options106*/107search(108query: string,109scopingQuery: ICodeOrDocsSearchSingleRepoScopingQuery,110options?: ICodeOrDocsSearchOptions,111cancellationToken?: CancellationToken112): Promise<ICodeOrDocsSearchItem[]>;113114/**115* Search for related chunks using GitHub's search APIs116* @note When multiple repos are specified, we return the results and errors together. You are responsible for handling errors how you would like.117* @param query The search query118* @param scopingQuery A scoping query with multiple repos specified.119* @param options The search options120*/121search(122query: string,123scopingQuery: ICodeOrDocsSearchMultiRepoScopingQuery,124options?: ICodeOrDocsSearchOptions,125cancellationToken?: CancellationToken126): Promise<ICodeOrDocsSearchResult>;127}128129130export const IDocsSearchClient = createServiceIdentifier<IDocsSearchClient>('docsSearchClient');131132133