Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/common/extHostAiSettingsSearch.ts
3296 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 { SettingsSearchProvider, SettingsSearchResult } from 'vscode';
7
import { CancellationToken } from '../../../base/common/cancellation.js';
8
import { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
9
import { AiSettingsSearchProviderOptions } from '../../services/aiSettingsSearch/common/aiSettingsSearch.js';
10
import { ExtHostAiSettingsSearchShape, IMainContext, MainContext, MainThreadAiSettingsSearchShape } from './extHost.protocol.js';
11
import { Disposable } from './extHostTypes.js';
12
import { Progress } from '../../../platform/progress/common/progress.js';
13
import { AiSettingsSearch } from './extHostTypeConverters.js';
14
15
export class ExtHostAiSettingsSearch implements ExtHostAiSettingsSearchShape {
16
private _settingsSearchProviders: Map<number, SettingsSearchProvider> = new Map();
17
private _nextHandle = 0;
18
19
private readonly _proxy: MainThreadAiSettingsSearchShape;
20
21
constructor(mainContext: IMainContext) {
22
this._proxy = mainContext.getProxy(MainContext.MainThreadAiSettingsSearch);
23
}
24
25
async $startSearch(handle: number, query: string, option: AiSettingsSearchProviderOptions, token: CancellationToken): Promise<void> {
26
if (this._settingsSearchProviders.size === 0) {
27
throw new Error('No related information providers registered');
28
}
29
30
const provider = this._settingsSearchProviders.get(handle);
31
if (!provider) {
32
throw new Error('Settings search provider not found');
33
}
34
35
const progressReporter = new Progress<SettingsSearchResult>((data) => {
36
this._proxy.$handleSearchResult(handle, AiSettingsSearch.fromSettingsSearchResult(data));
37
});
38
39
return provider.provideSettingsSearchResults(query, option, progressReporter, token);
40
}
41
42
registerSettingsSearchProvider(extension: IExtensionDescription, provider: SettingsSearchProvider): Disposable {
43
const handle = this._nextHandle;
44
this._nextHandle++;
45
this._settingsSearchProviders.set(handle, provider);
46
this._proxy.$registerAiSettingsSearchProvider(handle);
47
return new Disposable(() => {
48
this._proxy.$unregisterAiSettingsSearchProvider(handle);
49
this._settingsSearchProviders.delete(handle);
50
});
51
}
52
}
53
54