mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-13 17:22:15 -05:00
Adds logging to contextualization service (#24269)
* Adds logging to contextualization service * Code review changes
This commit is contained in:
@@ -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<void> {
|
||||
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<boolean> {
|
||||
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
|
||||
if (!isContextualizationEnabled) {
|
||||
this._logService.info('GitHub Copilot contextualization is disabled, so contextualization is not needed.');
|
||||
}
|
||||
|
||||
return (copilotExt && isContextualizationEnabled);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user