diff --git a/src/sql/workbench/services/contextualization/common/serverContextualizationService.ts b/src/sql/workbench/services/contextualization/common/serverContextualizationService.ts index 098aa35756..a7f9a9a8f0 100644 --- a/src/sql/workbench/services/contextualization/common/serverContextualizationService.ts +++ b/src/sql/workbench/services/contextualization/common/serverContextualizationService.ts @@ -11,6 +11,7 @@ import { IServerContextualizationService } from 'sql/workbench/services/contextu import { Disposable } from 'vs/base/common/lifecycle'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { ILogService } from 'vs/platform/log/common/log'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; export class ServerContextualizationService extends Disposable implements IServerContextualizationService { @@ -21,7 +22,8 @@ export class ServerContextualizationService extends Disposable implements IServe @IConnectionManagementService private readonly _connectionManagementService: IConnectionManagementService, @IConfigurationService private readonly _configurationService: IConfigurationService, @IExtensionService private readonly _extensionService: IExtensionService, - @ICommandService private readonly _commandService: ICommandService + @ICommandService private readonly _commandService: ICommandService, + @ILogService private readonly _logService: ILogService ) { super(); } @@ -50,9 +52,11 @@ export class ServerContextualizationService extends Disposable implements IServe public getProvider(providerId: string): azdata.contextualization.ServerContextualizationProvider { const provider = this._providers.get(providerId); if (provider) { + this._logService.info(`Found server contextualization provider for ${providerId}`); return provider; } + this._logService.info(`No server contextualization provider found for ${providerId}`); throw invalidProvider(providerId); } @@ -65,18 +69,28 @@ export class ServerContextualizationService extends Disposable implements IServe // Don't need to take any actions if contextualization is not enabled and can return const isContextualizationNeeded = await this.isContextualizationNeeded(); if (!isContextualizationNeeded) { + this._logService.info('Contextualization is not needed because the GitHub Copilot extension is not installed and/or contextualization is disabled.'); return; } const getServerContextualizationResult = await this.getServerContextualization(uri); if (getServerContextualizationResult.context) { + this._logService.info(`Server contextualization was previously generated for the URI (${uri}) connection, so sending that to Copilot for context.`); + await this.sendServerContextualizationToCopilot(getServerContextualizationResult.context); } else { + this._logService.info(`Server contextualization was not previously generated for the URI (${uri}) connection. Generating now...`); + const generateServerContextualizationResult = await this.generateServerContextualization(uri); if (generateServerContextualizationResult.context) { + this._logService.info(`Server contextualization was generated for the URI (${uri}) connection, so sending that to Copilot.`); + await this.sendServerContextualizationToCopilot(generateServerContextualizationResult.context); } + else { + this._logService.warn(`Server contextualization was not generated for the URI (${uri}) connection, so no context will be sent to Copilot.`); + } } } @@ -88,9 +102,13 @@ export class ServerContextualizationService extends Disposable implements IServe const providerName = this._connectionManagementService.getProviderIdFromUri(ownerUri); const handler = this.getProvider(providerName); if (handler) { + this._logService.info(`Generating server contextualization for ${ownerUri}`); + return await handler.generateServerContextualization(ownerUri); } else { + this._logService.info(`No server contextualization provider found for ${ownerUri}`); + return Promise.resolve({ context: undefined }); @@ -105,9 +123,13 @@ export class ServerContextualizationService extends Disposable implements IServe const providerName = this._connectionManagementService.getProviderIdFromUri(ownerUri); const handler = this.getProvider(providerName); if (handler) { + this._logService.info(`Getting server contextualization for ${ownerUri}`); + return await handler.getServerContextualization(ownerUri); } else { + this._logService.info(`No server contextualization provider found for ${ownerUri}`); + return Promise.resolve({ context: undefined }); @@ -120,6 +142,8 @@ export class ServerContextualizationService extends Disposable implements IServe */ private async sendServerContextualizationToCopilot(serverContext: string | undefined): Promise { if (serverContext) { + this._logService.info('Sending server contextualization to Copilot'); + // LEWISSANCHEZ TODO: Find way to set context on untitled query editor files. Need to save first for Copilot status to say "Has Context" await this._commandService.executeCommand('github.copilot.provideContext', '**/*.sql', { value: serverContext @@ -134,7 +158,14 @@ export class ServerContextualizationService extends Disposable implements IServe */ private async isContextualizationNeeded(): Promise { const copilotExt = await this._extensionService.getExtension('github.copilot'); + if (!copilotExt) { + this._logService.info('GitHub Copilot extension is not installed, so contextualization is not needed.'); + } + const isContextualizationEnabled = this._configurationService.getValue('queryEditor').githubCopilotContextualizationEnabled + if (!isContextualizationEnabled) { + this._logService.info('GitHub Copilot contextualization is disabled, so contextualization is not needed.'); + } return (copilotExt && isContextualizationEnabled); }