Adds logging to contextualization service (#24269)

* Adds logging to contextualization service

* Code review changes
This commit is contained in:
Lewis Sanchez
2023-09-01 15:09:29 -07:00
committed by GitHub
parent a390390405
commit 2d3b4a55e2

View File

@@ -11,6 +11,7 @@ import { IServerContextualizationService } from 'sql/workbench/services/contextu
import { Disposable } from 'vs/base/common/lifecycle'; import { Disposable } from 'vs/base/common/lifecycle';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; 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'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
export class ServerContextualizationService extends Disposable implements IServerContextualizationService { export class ServerContextualizationService extends Disposable implements IServerContextualizationService {
@@ -21,7 +22,8 @@ export class ServerContextualizationService extends Disposable implements IServe
@IConnectionManagementService private readonly _connectionManagementService: IConnectionManagementService, @IConnectionManagementService private readonly _connectionManagementService: IConnectionManagementService,
@IConfigurationService private readonly _configurationService: IConfigurationService, @IConfigurationService private readonly _configurationService: IConfigurationService,
@IExtensionService private readonly _extensionService: IExtensionService, @IExtensionService private readonly _extensionService: IExtensionService,
@ICommandService private readonly _commandService: ICommandService @ICommandService private readonly _commandService: ICommandService,
@ILogService private readonly _logService: ILogService
) { ) {
super(); super();
} }
@@ -50,9 +52,11 @@ export class ServerContextualizationService extends Disposable implements IServe
public getProvider(providerId: string): azdata.contextualization.ServerContextualizationProvider { public getProvider(providerId: string): azdata.contextualization.ServerContextualizationProvider {
const provider = this._providers.get(providerId); const provider = this._providers.get(providerId);
if (provider) { if (provider) {
this._logService.info(`Found server contextualization provider for ${providerId}`);
return provider; return provider;
} }
this._logService.info(`No server contextualization provider found for ${providerId}`);
throw invalidProvider(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 // Don't need to take any actions if contextualization is not enabled and can return
const isContextualizationNeeded = await this.isContextualizationNeeded(); const isContextualizationNeeded = await this.isContextualizationNeeded();
if (!isContextualizationNeeded) { if (!isContextualizationNeeded) {
this._logService.info('Contextualization is not needed because the GitHub Copilot extension is not installed and/or contextualization is disabled.');
return; return;
} }
const getServerContextualizationResult = await this.getServerContextualization(uri); const getServerContextualizationResult = await this.getServerContextualization(uri);
if (getServerContextualizationResult.context) { 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); await this.sendServerContextualizationToCopilot(getServerContextualizationResult.context);
} }
else { else {
this._logService.info(`Server contextualization was not previously generated for the URI (${uri}) connection. Generating now...`);
const generateServerContextualizationResult = await this.generateServerContextualization(uri); const generateServerContextualizationResult = await this.generateServerContextualization(uri);
if (generateServerContextualizationResult.context) { 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); 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 providerName = this._connectionManagementService.getProviderIdFromUri(ownerUri);
const handler = this.getProvider(providerName); const handler = this.getProvider(providerName);
if (handler) { if (handler) {
this._logService.info(`Generating server contextualization for ${ownerUri}`);
return await handler.generateServerContextualization(ownerUri); return await handler.generateServerContextualization(ownerUri);
} }
else { else {
this._logService.info(`No server contextualization provider found for ${ownerUri}`);
return Promise.resolve({ return Promise.resolve({
context: undefined context: undefined
}); });
@@ -105,9 +123,13 @@ export class ServerContextualizationService extends Disposable implements IServe
const providerName = this._connectionManagementService.getProviderIdFromUri(ownerUri); const providerName = this._connectionManagementService.getProviderIdFromUri(ownerUri);
const handler = this.getProvider(providerName); const handler = this.getProvider(providerName);
if (handler) { if (handler) {
this._logService.info(`Getting server contextualization for ${ownerUri}`);
return await handler.getServerContextualization(ownerUri); return await handler.getServerContextualization(ownerUri);
} }
else { else {
this._logService.info(`No server contextualization provider found for ${ownerUri}`);
return Promise.resolve({ return Promise.resolve({
context: undefined context: undefined
}); });
@@ -120,6 +142,8 @@ export class ServerContextualizationService extends Disposable implements IServe
*/ */
private async sendServerContextualizationToCopilot(serverContext: string | undefined): Promise<void> { private async sendServerContextualizationToCopilot(serverContext: string | undefined): Promise<void> {
if (serverContext) { 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" // 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', { await this._commandService.executeCommand('github.copilot.provideContext', '**/*.sql', {
value: serverContext value: serverContext
@@ -134,7 +158,14 @@ export class ServerContextualizationService extends Disposable implements IServe
*/ */
private async isContextualizationNeeded(): Promise<boolean> { private async isContextualizationNeeded(): Promise<boolean> {
const copilotExt = await this._extensionService.getExtension('github.copilot'); 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<IQueryEditorConfiguration>('queryEditor').githubCopilotContextualizationEnabled const isContextualizationEnabled = this._configurationService.getValue<IQueryEditorConfiguration>('queryEditor').githubCopilotContextualizationEnabled
if (!isContextualizationEnabled) {
this._logService.info('GitHub Copilot contextualization is disabled, so contextualization is not needed.');
}
return (copilotExt && isContextualizationEnabled); return (copilotExt && isContextualizationEnabled);
} }