Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One Provider per Type #191136

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/vs/workbench/api/browser/mainThreadAiRelatedInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle';
import { ExtHostAiRelatedInformationShape, ExtHostContext, MainContext, MainThreadAiRelatedInformationShape } from 'vs/workbench/api/common/extHost.protocol';
import { RelatedInformationType } from 'vs/workbench/api/common/extHostTypes';
import { IAiRelatedInformationProvider, IAiRelatedInformationService } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformation';
import { IAiRelatedInformationProvider, IAiRelatedInformationService, RelatedInformationResult } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformation';
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { RelatedInformationResult } from 'vscode';

@extHostNamedCustomer(MainContext.MainThreadAiRelatedInformation)
export class MainThreadAiRelatedInformation extends Disposable implements MainThreadAiRelatedInformationShape {
Expand All @@ -29,13 +28,13 @@ export class MainThreadAiRelatedInformation extends Disposable implements MainTh
return this._aiRelatedInformationService.getRelatedInformation(query, types, CancellationToken.None);
}

$registerAiRelatedInformationProvider(handle: number, types: RelatedInformationType[]): void {
$registerAiRelatedInformationProvider(handle: number, type: RelatedInformationType): void {
const provider: IAiRelatedInformationProvider = {
provideAiRelatedInformation: (query, types, token) => {
return this._proxy.$provideAiRelatedInformation(handle, query, types, token);
provideAiRelatedInformation: (query, token) => {
return this._proxy.$provideAiRelatedInformation(handle, query, token);
},
};
this._registrations.set(handle, this._aiRelatedInformationService.registerAiRelatedInformationProvider(types, provider));
this._registrations.set(handle, this._aiRelatedInformationService.registerAiRelatedInformationProvider(type, provider));
}

$unregisterAiRelatedInformationProvider(handle: number): void {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1332,9 +1332,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension, 'aiRelatedInformation');
return extHostAiRelatedInformation.getRelatedInformation(extension, query, types);
},
registerRelatedInformationProvider(types: vscode.RelatedInformationType[], provider: vscode.RelatedInformationProvider) {
registerRelatedInformationProvider(type: vscode.RelatedInformationType, provider: vscode.RelatedInformationProvider) {
checkProposedApiEnabled(extension, 'aiRelatedInformation');
return extHostAiRelatedInformation.registerRelatedInformationProvider(extension, types, provider);
return extHostAiRelatedInformation.registerRelatedInformationProvider(extension, type, provider);
},
registerEmbeddingVectorProvider(model: string, provider: vscode.EmbeddingVectorProvider) {
checkProposedApiEnabled(extension, 'aiRelatedInformation');
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,12 +1675,12 @@ export interface MainThreadSemanticSimilarityShape extends IDisposable {
}

export interface ExtHostAiRelatedInformationShape {
$provideAiRelatedInformation(handle: number, query: string, types: RelatedInformationType[], token: CancellationToken): Promise<RelatedInformationResult[]>;
$provideAiRelatedInformation(handle: number, query: string, token: CancellationToken): Promise<RelatedInformationResult[]>;
}

export interface MainThreadAiRelatedInformationShape {
$getAiRelatedInformation(query: string, types: RelatedInformationType[]): Promise<RelatedInformationResult[]>;
$registerAiRelatedInformationProvider(handle: number, types: RelatedInformationType[]): void;
$registerAiRelatedInformationProvider(handle: number, type: RelatedInformationType): void;
$unregisterAiRelatedInformationProvider(handle: number): void;
}

Expand Down
11 changes: 5 additions & 6 deletions src/vs/workbench/api/common/extHostAiRelatedInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ExtHostAiRelatedInformationShape, IMainContext, MainContext, MainThreadAiRelatedInformationShape } from 'vs/workbench/api/common/extHost.protocol';
import type { CancellationToken, RelatedInformationProvider, RelatedInformationResult, RelatedInformationType } from 'vscode';
import type { CancellationToken, RelatedInformationProvider, RelatedInformationType, RelatedInformationResult } from 'vscode';
import { Disposable } from 'vs/workbench/api/common/extHostTypes';

export class ExtHostRelatedInformation implements ExtHostAiRelatedInformationShape {
Expand All @@ -18,7 +18,7 @@ export class ExtHostRelatedInformation implements ExtHostAiRelatedInformationSha
this._proxy = mainContext.getProxy(MainContext.MainThreadAiRelatedInformation);
}

async $provideAiRelatedInformation(handle: number, query: string, types: RelatedInformationType[], token: CancellationToken): Promise<RelatedInformationResult[]> {
async $provideAiRelatedInformation(handle: number, query: string, token: CancellationToken): Promise<RelatedInformationResult[]> {
if (this._relatedInformationProviders.size === 0) {
throw new Error('No semantic similarity providers registered');
}
Expand All @@ -28,20 +28,19 @@ export class ExtHostRelatedInformation implements ExtHostAiRelatedInformationSha
throw new Error('Semantic similarity provider not found');
}

// TODO: should this return undefined or an empty array?
const result = await provider.provideRelatedInformation(query, types, token) ?? [];
const result = await provider.provideRelatedInformation(query, token) ?? [];
return result;
}

getRelatedInformation(extension: IExtensionDescription, query: string, types: RelatedInformationType[]): Promise<RelatedInformationResult[]> {
return this._proxy.$getAiRelatedInformation(query, types);
}

registerRelatedInformationProvider(extension: IExtensionDescription, types: RelatedInformationType[], provider: RelatedInformationProvider): Disposable {
registerRelatedInformationProvider(extension: IExtensionDescription, type: RelatedInformationType, provider: RelatedInformationProvider): Disposable {
const handle = this._nextHandle;
this._nextHandle++;
this._relatedInformationProviders.set(handle, provider);
this._proxy.$registerAiRelatedInformationProvider(handle, types);
this._proxy.$registerAiRelatedInformationProvider(handle, type);
return new Disposable(() => {
this._proxy.$unregisterAiRelatedInformationProvider(handle);
this._relatedInformationProviders.delete(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ export enum RelatedInformationType {
SettingInformation = 4
}

export interface RelatedInformationResult {
interface RelatedInformationBaseResult {
type: RelatedInformationType;
weight: number;
}

export interface CommandInformationResult extends RelatedInformationResult {
export interface CommandInformationResult extends RelatedInformationBaseResult {
type: RelatedInformationType.CommandInformation;
command: string;
}

export interface SettingInformationResult extends RelatedInformationResult {
export interface SettingInformationResult extends RelatedInformationBaseResult {
type: RelatedInformationType.SettingInformation;
setting: string;
}

export type RelatedInformationResult = CommandInformationResult | SettingInformationResult;

export interface IAiRelatedInformationService {
readonly _serviceBrand: undefined;

isEnabled(): boolean;
getRelatedInformation(query: string, types: RelatedInformationType[], token: CancellationToken): Promise<RelatedInformationResult[]>;
registerAiRelatedInformationProvider(types: RelatedInformationType[], provider: IAiRelatedInformationProvider): IDisposable;
registerAiRelatedInformationProvider(type: RelatedInformationType, provider: IAiRelatedInformationProvider): IDisposable;
}

export interface IAiRelatedInformationProvider {
provideAiRelatedInformation(query: string, types: RelatedInformationType[], token: CancellationToken): Promise<RelatedInformationResult[]>;
provideAiRelatedInformation(query: string, token: CancellationToken): Promise<RelatedInformationResult[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,21 @@ export class AiRelatedInformationService implements IAiRelatedInformationService
return this._providers.size > 0;
}

registerAiRelatedInformationProvider(types: RelatedInformationType[], provider: IAiRelatedInformationProvider): IDisposable {
for (const type of types) {
const providers = this._providers.get(type) ?? [];
providers.push(provider);
this._providers.set(type, providers);
}
registerAiRelatedInformationProvider(type: RelatedInformationType, provider: IAiRelatedInformationProvider): IDisposable {
const providers = this._providers.get(type) ?? [];
providers.push(provider);
this._providers.set(type, providers);


return {
dispose: () => {
for (const type of types) {
const providers = this._providers.get(type) ?? [];
const index = providers.indexOf(provider);
if (index !== -1) {
providers.splice(index, 1);
}
if (providers.length === 0) {
this._providers.delete(type);
}
const providers = this._providers.get(type) ?? [];
const index = providers.indexOf(provider);
if (index !== -1) {
providers.splice(index, 1);
}
if (providers.length === 0) {
this._providers.delete(type);
}
}
};
Expand Down Expand Up @@ -78,7 +75,7 @@ export class AiRelatedInformationService implements IAiRelatedInformationService
for (const provider of providers) {
cancellablePromises.push(createCancelablePromise(async t => {
try {
const result = await provider.provideAiRelatedInformation(query, types, t);
const result = await provider.provideAiRelatedInformation(query, t);
// double filter just in case
return result.filter(r => types.includes(r.type));
} catch (e) {
Expand Down
27 changes: 7 additions & 20 deletions src/vscode-dts/vscode.proposed.aiRelatedInformation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,34 @@ declare module 'vscode' {

// https://github.com/microsoft/vscode/issues/190909

export interface SearchResult {
// from Andrea
preview: string;
resource: Uri;
location: Range;
}

export enum RelatedInformationType {
SymbolInformation = 1,
CommandInformation = 2,
SearchInformation = 3,
SettingInformation = 4
}

export interface RelatedInformationResult {
interface RelatedInformationBaseResult {
type: RelatedInformationType;
weight: number;
}

export interface SymbolInformationResult extends RelatedInformationResult {
type: RelatedInformationType.SymbolInformation;
symbolInformation: SymbolInformation;
}
// TODO: Symbols and Search

export interface CommandInformationResult extends RelatedInformationResult {
export interface CommandInformationResult extends RelatedInformationBaseResult {
type: RelatedInformationType.CommandInformation;
command: string;
}

export interface SettingInformationResult extends RelatedInformationResult {
export interface SettingInformationResult extends RelatedInformationBaseResult {
type: RelatedInformationType.SettingInformation;
setting: string;
}

export interface SearchInformationResult extends RelatedInformationResult {
type: RelatedInformationType.SearchInformation;
searchResult: SearchResult;
}
export type RelatedInformationResult = CommandInformationResult | SettingInformationResult;

export interface RelatedInformationProvider {
provideRelatedInformation(query: string, types: RelatedInformationType[], token: CancellationToken): ProviderResult<RelatedInformationResult[]>;
provideRelatedInformation(query: string, token: CancellationToken): ProviderResult<RelatedInformationResult[]>;
}

export interface EmbeddingVectorProvider {
Expand All @@ -56,7 +43,7 @@ declare module 'vscode' {

export namespace ai {
export function getRelatedInformation(query: string, types: RelatedInformationType[], token: CancellationToken): Thenable<RelatedInformationResult[]>;
export function registerRelatedInformationProvider(types: RelatedInformationType[], provider: RelatedInformationProvider): Disposable;
export function registerRelatedInformationProvider(type: RelatedInformationType, provider: RelatedInformationProvider): Disposable;
export function registerEmbeddingVectorProvider(model: string, provider: EmbeddingVectorProvider): Disposable;
}
}