mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
Add toggle query history capture command/action (#7427)
* Add toggle query history capture command/action * Add extension updates
This commit is contained in:
committed by
Karl Burtram
parent
7cbc268c52
commit
4018a29a16
@@ -17,10 +17,39 @@ export const IQueryHistoryService = createDecorator<IQueryHistoryService>(SERVIC
|
||||
export interface IQueryHistoryService {
|
||||
_serviceBrand: any;
|
||||
|
||||
/**
|
||||
* Event fired whenever the collection of stored QueryHistoryInfo's is updated
|
||||
*/
|
||||
onInfosUpdated: Event<QueryHistoryInfo[]>;
|
||||
/**
|
||||
* Event fired whenever the Query History capture state has changed
|
||||
*/
|
||||
onQueryHistoryCaptureChanged: Event<boolean>;
|
||||
|
||||
/**
|
||||
* Whether Query History capture is currently enabled
|
||||
*/
|
||||
readonly captureEnabled: boolean;
|
||||
|
||||
/**
|
||||
* Gets the current list of Query History Info objects that have been collected
|
||||
*/
|
||||
getQueryHistoryInfos(): QueryHistoryInfo[];
|
||||
/**
|
||||
* Deletes all QueryHistoryInfo's from the collection that have the same id as the specified one
|
||||
* @param info The QueryHistoryInfo to delete
|
||||
*/
|
||||
deleteQueryHistoryInfo(info: QueryHistoryInfo): void;
|
||||
/**
|
||||
* Clears all Query History - removing all collected items
|
||||
*/
|
||||
clearQueryHistory(): void;
|
||||
/**
|
||||
* Toggles whether Query History capture is enabled
|
||||
*/
|
||||
toggleCaptureEnabled(): Promise<void>;
|
||||
/**
|
||||
* Starts the Query History Service
|
||||
*/
|
||||
start(): void;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import { QueryHistoryInfo, QueryStatus } from 'sql/platform/queryHistory/common/
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
|
||||
import { IConfigurationChangedEvent } from 'sql/workbench/parts/profiler/browser/profilerFindWidget';
|
||||
|
||||
/**
|
||||
* Service that collects the results of executed queries
|
||||
@@ -23,20 +25,30 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
|
||||
// MEMBER VARIABLES ////////////////////////////////////////////////////
|
||||
private _infos: QueryHistoryInfo[] = [];
|
||||
private _onInfosUpdated: Emitter<QueryHistoryInfo[]> = new Emitter<QueryHistoryInfo[]>();
|
||||
|
||||
private _onQueryHistoryCaptureChanged: Emitter<boolean> = new Emitter<boolean>();
|
||||
private _captureEnabled;
|
||||
// EVENTS //////////////////////////////////////////////////////////////
|
||||
public get onInfosUpdated(): Event<QueryHistoryInfo[]> { return this._onInfosUpdated.event; }
|
||||
|
||||
public get onQueryHistoryCaptureChanged(): Event<boolean> { return this._onQueryHistoryCaptureChanged.event; }
|
||||
// CONSTRUCTOR /////////////////////////////////////////////////////////
|
||||
constructor(
|
||||
@IQueryModelService _queryModelService: IQueryModelService,
|
||||
@IModelService _modelService: IModelService,
|
||||
@IConnectionManagementService _connectionManagementService: IConnectionManagementService
|
||||
@IConnectionManagementService _connectionManagementService: IConnectionManagementService,
|
||||
@IConfigurationService private _configurationService: IConfigurationService
|
||||
) {
|
||||
super();
|
||||
|
||||
this._captureEnabled = !!this._configurationService.getValue<boolean>('queryHistory.captureEnabled');
|
||||
|
||||
this._register(this._configurationService.onDidChangeConfiguration((e: IConfigurationChangeEvent) => {
|
||||
if (e.affectedKeys.includes('queryHistory.captureEnabled')) {
|
||||
this.updateCaptureEnabled();
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(_queryModelService.onQueryEvent((e: IQueryEvent) => {
|
||||
if (e.type === 'queryStop') {
|
||||
if (this._captureEnabled && e.type === 'queryStop') {
|
||||
const uri: URI = URI.parse(e.uri);
|
||||
// VS Range is 1 based so offset values by 1. The endLine we get back from SqlToolsService is incremented
|
||||
// by 1 from the original input range sent in as well so take that into account and don't modify
|
||||
@@ -62,6 +74,13 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether Query History capture is currently enabled
|
||||
*/
|
||||
public get captureEnabled(): boolean {
|
||||
return this._captureEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the current query history infos
|
||||
*/
|
||||
@@ -71,9 +90,9 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
|
||||
|
||||
/**
|
||||
* Deletes infos from the cache with the same ID as the given QueryHistoryInfo
|
||||
* @param info TheQueryHistoryInfo to delete
|
||||
* @param info The QueryHistoryInfo to delete
|
||||
*/
|
||||
public deleteQueryHistoryInfo(info: QueryHistoryInfo) {
|
||||
public deleteQueryHistoryInfo(info: QueryHistoryInfo): void {
|
||||
this._infos = this._infos.filter(i => i.id !== info.id);
|
||||
this._onInfosUpdated.fire(this._infos);
|
||||
}
|
||||
@@ -81,11 +100,24 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
|
||||
/**
|
||||
* Clears all infos from the cache
|
||||
*/
|
||||
public clearQueryHistory() {
|
||||
public clearQueryHistory(): void {
|
||||
this._infos = [];
|
||||
this._onInfosUpdated.fire(this._infos);
|
||||
}
|
||||
|
||||
public async toggleCaptureEnabled(): Promise<void> {
|
||||
const captureEnabled = !!this._configurationService.getValue<boolean>('queryHistory.captureEnabled');
|
||||
await this._configurationService.updateValue('queryHistory.captureEnabled', !captureEnabled);
|
||||
}
|
||||
|
||||
private updateCaptureEnabled(): void {
|
||||
const currentCaptureEnabled = this._captureEnabled;
|
||||
this._captureEnabled = !!this._configurationService.getValue<boolean>('queryHistory.captureEnabled');
|
||||
if (currentCaptureEnabled !== this._captureEnabled) {
|
||||
this._onQueryHistoryCaptureChanged.fire(this._captureEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to force initialization of the service so that it can start tracking query events
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user