Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/remoteSearch/common/codeOrDocsSearchClient.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type { CancellationToken } from 'vscode';
7
import { createServiceIdentifier } from '../../../util/common/services';
8
import { CodeOrDocsSearchRepoError } from './codeOrDocsSearchErrors';
9
10
/**
11
* Represents the base scoping query for code or docs search. A scoping query is used to provide what exactly you want to search through.
12
*/
13
export interface ICodeOrDocsSearchBaseScopingQuery {
14
/**
15
* The repo(s) to search in. When only one is specified, any errors are thrown. If multiple repos are specified,
16
* then they are returned in the response.
17
*/
18
repo: string | string[];
19
20
/**
21
* The language to search for. If not provided, all languages will be searched.
22
*/
23
lang?: string[];
24
25
/**
26
* The language to exclude from the search. If not provided, no languages will be excluded.
27
*/
28
notLang?: string[];
29
30
/**
31
* The path to search for. If not provided, all paths will be searched.
32
*/
33
path?: string[];
34
35
/**
36
* The path to exclude from the search. If not provided, no paths will be excluded.
37
*/
38
notPath?: string[];
39
}
40
41
/**
42
* 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.
43
*/
44
export interface ICodeOrDocsSearchSingleRepoScopingQuery extends ICodeOrDocsSearchBaseScopingQuery {
45
repo: string;
46
}
47
48
/**
49
* 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.
50
*/
51
export interface ICodeOrDocsSearchMultiRepoScopingQuery extends ICodeOrDocsSearchBaseScopingQuery {
52
repo: string[];
53
}
54
55
/**
56
* What one of the results looks like that is returned by codesearch or docssearch.
57
*/
58
export interface ICodeOrDocsSearchItem {
59
path: string;
60
contents: string;
61
title?: string;
62
score: number;
63
repoName: string;
64
repoOwner: string;
65
range: { start: number; end: number };
66
languageId: string;
67
languageName: string;
68
type: 'snippet' | string;
69
url: string;
70
ref: string;
71
commitOID?: string;
72
algorithm?: 'semantic' | 'bm25';
73
}
74
75
/**
76
* The result of a code or docs search.
77
*/
78
export interface ICodeOrDocsSearchResult {
79
results: ICodeOrDocsSearchItem[];
80
errors: CodeOrDocsSearchRepoError[];
81
}
82
83
export interface ICodeOrDocsSearchOptions {
84
/**
85
* The number of results to return. Default is 6.
86
*/
87
limit?: number;
88
89
/**
90
* How similar you want results to be.
91
*/
92
similarity?: number;
93
}
94
95
/**
96
* The interface for the docs search client.
97
*/
98
export interface IDocsSearchClient {
99
readonly _serviceBrand: undefined;
100
101
/**
102
* Search for related chunks using GitHub's search APIs
103
* @note When only a single repo is specified, we return the results as an array and also throw errors.
104
* @param query The search query
105
* @param scopingQuery A scoping query with a single repo specified.
106
* @param options The search options
107
*/
108
search(
109
query: string,
110
scopingQuery: ICodeOrDocsSearchSingleRepoScopingQuery,
111
options?: ICodeOrDocsSearchOptions,
112
cancellationToken?: CancellationToken
113
): Promise<ICodeOrDocsSearchItem[]>;
114
115
/**
116
* Search for related chunks using GitHub's search APIs
117
* @note When multiple repos are specified, we return the results and errors together. You are responsible for handling errors how you would like.
118
* @param query The search query
119
* @param scopingQuery A scoping query with multiple repos specified.
120
* @param options The search options
121
*/
122
search(
123
query: string,
124
scopingQuery: ICodeOrDocsSearchMultiRepoScopingQuery,
125
options?: ICodeOrDocsSearchOptions,
126
cancellationToken?: CancellationToken
127
): Promise<ICodeOrDocsSearchResult>;
128
}
129
130
131
export const IDocsSearchClient = createServiceIdentifier<IDocsSearchClient>('docsSearchClient');
132
133