mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 01:25:36 -05:00
Integrate Contextualization API into Azure Data Studio to get better query recommendations from Copilot (#24044)
* Boilerplate for new metadata API endpoint * Register all server metadata provider * Fully registers data provider * Registers metadata provider * Instantiate metadata service * Generates server metadata when connection is established * Allow queryEditorInput to get server metadata * Minor clean up * Renames metadata provider and request endpoint * Corrects documentation block * Integrates get server metadata request endpoint * Adjusts GetServerMetadataResult scripts type * Add back Cargo.toml file * Fix SQL hygiene error * reflect changes made in in STS for table metadata * Adds feature toggle to serverMetadataService * Places toggle before request to get create scripts * Fix build check issues * Minor review changes * Improves contextualization setting label * Generalize contextualization service names * Additional code review changes * Update extensions/mssql/src/contracts.ts Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * Update src/sql/azdata.proposed.d.ts Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * Code reivew changes * Capitalize c in contextualization * Additional review changes * Update provider type * Simplify type and method names * Unregister MSSQL ServerContextualization provider --------- Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -33,6 +33,7 @@ import { ITableDesignerService } from 'sql/workbench/services/tableDesigner/comm
|
||||
import { IExecutionPlanService } from 'sql/workbench/services/executionPlan/common/interfaces';
|
||||
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
|
||||
import { SqlExtHostContext, SqlMainContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { IServerContextualizationService } from 'sql/workbench/services/contextualization/common/interfaces';
|
||||
|
||||
/**
|
||||
* Main thread class for handling data protocol management registration.
|
||||
@@ -64,7 +65,8 @@ export class MainThreadDataProtocol extends Disposable implements MainThreadData
|
||||
@IDataGridProviderService private _dataGridProviderService: IDataGridProviderService,
|
||||
@IAdsTelemetryService private _telemetryService: IAdsTelemetryService,
|
||||
@ITableDesignerService private _tableDesignerService: ITableDesignerService,
|
||||
@IExecutionPlanService private _executionPlanService: IExecutionPlanService
|
||||
@IExecutionPlanService private _executionPlanService: IExecutionPlanService,
|
||||
@IServerContextualizationService private _serverContextualizationService: IServerContextualizationService
|
||||
) {
|
||||
super();
|
||||
if (extHostContext) {
|
||||
@@ -571,6 +573,14 @@ export class MainThreadDataProtocol extends Disposable implements MainThreadData
|
||||
});
|
||||
}
|
||||
|
||||
// Database server contextualization handler
|
||||
public $registerServerContextualizationProvider(providerId: string, handle: number): void {
|
||||
this._serverContextualizationService.registerProvider(providerId, <azdata.contextualization.ServerContextualizationProvider>{
|
||||
generateServerContextualization: (ownerUri: string) => this._proxy.$generateServerContextualization(handle, ownerUri),
|
||||
getServerContextualization: (ownerUri: string) => this._proxy.$getServerContextualization(handle, ownerUri)
|
||||
});
|
||||
}
|
||||
|
||||
// Connection Management handlers
|
||||
public $onConnectionComplete(handle: number, connectionInfoSummary: azdata.ConnectionInfoSummary): void {
|
||||
this._connectionManagementService.onConnectionComplete(handle, connectionInfoSummary);
|
||||
|
||||
@@ -210,6 +210,12 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape {
|
||||
return rt;
|
||||
}
|
||||
|
||||
$registerServerContextualizationProvider(provider: azdata.contextualization.ServerContextualizationProvider): vscode.Disposable {
|
||||
let rt = this.registerProvider(provider, DataProviderType.ServerContextualizationProvider);
|
||||
this._proxy.$registerServerContextualizationProvider(provider.providerId, provider.handle);
|
||||
return rt;
|
||||
}
|
||||
|
||||
// Capabilities Discovery handlers
|
||||
override $getServerCapabilities(handle: number, client: azdata.DataProtocolClientCapabilities): Thenable<azdata.DataProtocolServerCapabilities> {
|
||||
return this._resolveProvider<azdata.CapabilitiesProvider>(handle).getServerCapabilities(client);
|
||||
@@ -963,4 +969,14 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape {
|
||||
public override $isExecutionPlan(handle: number, value: string): Thenable<azdata.executionPlan.IsExecutionPlanResult> {
|
||||
return this._resolveProvider<azdata.executionPlan.ExecutionPlanProvider>(handle).isExecutionPlan(value);
|
||||
}
|
||||
|
||||
// Database Server Contextualization API
|
||||
|
||||
public override $generateServerContextualization(handle: number, ownerUri: string): void {
|
||||
this._resolveProvider<azdata.contextualization.ServerContextualizationProvider>(handle).generateServerContextualization(ownerUri);
|
||||
}
|
||||
|
||||
public override $getServerContextualization(handle: number, ownerUri: string): Thenable<azdata.contextualization.GetServerContextualizationResult> {
|
||||
return this._resolveProvider<azdata.contextualization.ServerContextualizationProvider>(handle).getServerContextualization(ownerUri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,6 +408,10 @@ export function createAdsApiFactory(accessor: ServicesAccessor): IAdsExtensionAp
|
||||
return extHostDataProvider.$registerExecutionPlanProvider(provider);
|
||||
};
|
||||
|
||||
let registerServerContextualizationProvider = (provider: azdata.contextualization.ServerContextualizationProvider): vscode.Disposable => {
|
||||
return extHostDataProvider.$registerServerContextualizationProvider(provider);
|
||||
};
|
||||
|
||||
// namespace: dataprotocol
|
||||
const dataprotocol: typeof azdata.dataprotocol = {
|
||||
registerBackupProvider,
|
||||
@@ -430,6 +434,7 @@ export function createAdsApiFactory(accessor: ServicesAccessor): IAdsExtensionAp
|
||||
registerDataGridProvider,
|
||||
registerTableDesignerProvider,
|
||||
registerExecutionPlanProvider: registerExecutionPlanProvider,
|
||||
registerServerContextualizationProvider: registerServerContextualizationProvider,
|
||||
onDidChangeLanguageFlavor(listener: (e: azdata.DidChangeLanguageFlavorParams) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
|
||||
return extHostDataProvider.onDidChangeLanguageFlavor(listener, thisArgs, disposables);
|
||||
},
|
||||
|
||||
@@ -595,6 +595,14 @@ export abstract class ExtHostDataProtocolShape {
|
||||
* Determines if the provided value is an execution plan and returns the appropriate file extension.
|
||||
*/
|
||||
$isExecutionPlan(handle: number, value: string): Thenable<azdata.executionPlan.IsExecutionPlanResult> { throw ni(); }
|
||||
/**
|
||||
* Generates server context.
|
||||
*/
|
||||
$generateServerContextualization(handle: number, ownerUri: string): void { throw ni(); }
|
||||
/**
|
||||
* Gets server context.
|
||||
*/
|
||||
$getServerContextualization(handle: number, ownerUri: string): Thenable<azdata.contextualization.GetServerContextualizationResult> { throw ni(); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -687,6 +695,7 @@ export interface MainThreadDataProtocolShape extends IDisposable {
|
||||
$registerDataGridProvider(providerId: string, title: string, handle: number): void;
|
||||
$registerTableDesignerProvider(providerId: string, handle: number): Promise<any>;
|
||||
$registerExecutionPlanProvider(providerId: string, handle: number): void;
|
||||
$registerServerContextualizationProvider(providerId: string, handle: number): void;
|
||||
$unregisterProvider(handle: number): Promise<any>;
|
||||
$onConnectionComplete(handle: number, connectionInfoSummary: azdata.ConnectionInfoSummary): void;
|
||||
$onIntelliSenseCacheComplete(handle: number, connectionUri: string): void;
|
||||
|
||||
@@ -421,7 +421,8 @@ export enum DataProviderType {
|
||||
SqlAssessmentServicesProvider = 'SqlAssessmentServicesProvider',
|
||||
DataGridProvider = 'DataGridProvider',
|
||||
TableDesignerProvider = 'TableDesignerProvider',
|
||||
ExecutionPlanProvider = 'ExecutionPlanProvider'
|
||||
ExecutionPlanProvider = 'ExecutionPlanProvider',
|
||||
ServerContextualizationProvider = 'ServerContextualizationProvider'
|
||||
}
|
||||
|
||||
export enum DeclarativeDataType {
|
||||
|
||||
Reference in New Issue
Block a user