diff --git a/extensions/query-history/src/main.ts b/extensions/query-history/src/main.ts index 41b9f52deb..0e9689bdd5 100644 --- a/extensions/query-history/src/main.ts +++ b/extensions/query-history/src/main.ts @@ -9,7 +9,12 @@ import { DOUBLE_CLICK_ACTION_CONFIG_SECTION, ITEM_SELECTED_COMMAND_ID, QUERY_HIS import { QueryHistoryItem } from './queryHistoryItem'; import { QueryHistoryProvider, setLoadingContext } from './queryHistoryProvider'; import { promises as fs } from 'fs'; -import { TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry'; +import { sendSettingChangedEvent, TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry'; + +type DoubleClickAction = 'open' | 'run'; + +const DEFAULT_DOUBLECLICK_ACTION: DoubleClickAction = 'open'; +let doubleClickAction: string = DEFAULT_DOUBLECLICK_ACTION; let lastSelectedItem: { item: QueryHistoryItem | undefined, time: number | undefined } = { item: undefined, @@ -39,13 +44,21 @@ export async function activate(context: vscode.ExtensionContext): Promise canSelectMany: false }); context.subscriptions.push(treeView); + context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async e => { + if (e.affectsConfiguration(`${QUERY_HISTORY_CONFIG_SECTION}.${DOUBLE_CLICK_ACTION_CONFIG_SECTION}`)) { + const newDoubleClickAction = getDoubleClickAction(); + if (newDoubleClickAction !== doubleClickAction) { + sendSettingChangedEvent('DoubleClickAction', doubleClickAction, newDoubleClickAction); + } + doubleClickAction = newDoubleClickAction; + } + })); // This is an internal-only command so not adding to package.json context.subscriptions.push(vscode.commands.registerCommand(ITEM_SELECTED_COMMAND_ID, async (selectedItem: QueryHistoryItem) => { // VS Code doesn't provide a native way to detect a double-click so we track it ourselves by keeping track of the last item clicked and // when it was clicked to compare, then if a click happens on the same element quickly enough we trigger the configured action const clickTime = new Date().getTime(); if (lastSelectedItem.item === selectedItem && lastSelectedItem.time && (clickTime - lastSelectedItem.time) < DOUBLE_CLICK_TIMEOUT_MS) { - const doubleClickAction = vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION).get(DOUBLE_CLICK_ACTION_CONFIG_SECTION); TelemetryReporter.sendActionEvent(TelemetryViews.QueryHistory, TelemetryActions.DoubleClick, doubleClickAction); switch (doubleClickAction) { case 'run': @@ -126,5 +139,8 @@ async function runQuery(item: QueryHistoryItem): Promise { .withAdditionalProperties({ step }) .send(); } - +} + +export function getDoubleClickAction(): string { + return vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION).get(DOUBLE_CLICK_ACTION_CONFIG_SECTION, DEFAULT_DOUBLECLICK_ACTION); } diff --git a/extensions/query-history/src/queryHistoryProvider.ts b/extensions/query-history/src/queryHistoryProvider.ts index 0670242646..84f704714e 100644 --- a/extensions/query-history/src/queryHistoryProvider.ts +++ b/extensions/query-history/src/queryHistoryProvider.ts @@ -13,6 +13,7 @@ import * as path from 'path'; import * as crypto from 'crypto'; import * as loc from './localizedConstants'; import { sendSettingChangedEvent, TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry'; +import { getDoubleClickAction } from './main'; const STORAGE_IV_KEY = 'queryHistory.storage-iv'; const STORAGE_KEY_KEY = 'queryHistory.storage-key'; @@ -55,10 +56,17 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider initializeAction.send()); + this._initPromise = this.initialize().then(() => { + initializeAction.withAdditionalProperties({ + 'setting.persistHistory': String(this._persistHistory), + 'setting.maxEntries': String(this._maxEntries), + 'setting.captureEnabled': String(this._captureEnabled), + 'setting.doubleClickAction': getDoubleClickAction() + }).send(); + }); this._disposables.push(vscode.workspace.onDidChangeConfiguration(async e => { - if (e.affectsConfiguration(QUERY_HISTORY_CONFIG_SECTION) || e.affectsConfiguration(MAX_ENTRIES_CONFIG_SECTION)) { - await this.updateConfigurationValues(); + if (e.affectsConfiguration(QUERY_HISTORY_CONFIG_SECTION)) { + await this.updateConfigurationValues(true); } })); this._disposables.push(azdata.queryeditor.registerQueryEventListener({ @@ -249,23 +257,25 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider { + private async updateConfigurationValues(sendChangedEvents: boolean = false): Promise { const configSection = vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION); const newCaptureEnabled = configSection.get(CAPTURE_ENABLED_CONFIG_SECTION, DEFAULT_CAPTURE_ENABLED); - if (this._captureEnabled !== newCaptureEnabled) { + if (sendChangedEvents && this._captureEnabled !== newCaptureEnabled) { sendSettingChangedEvent('CaptureEnabled', String(this._captureEnabled), String(newCaptureEnabled)); - this._captureEnabled = newCaptureEnabled; } + this._captureEnabled = newCaptureEnabled; + const newPersistHistory = configSection.get(PERSIST_HISTORY_CONFIG_SECTION, DEFAULT_PERSIST_HISTORY); - if (this._persistHistory !== newPersistHistory) { + if (sendChangedEvents && this._persistHistory !== newPersistHistory) { sendSettingChangedEvent('PersistHistory', String(this._persistHistory), String(newPersistHistory)); - this._persistHistory = newPersistHistory; } + this._persistHistory = newPersistHistory; + const newMaxEntries = configSection.get(MAX_ENTRIES_CONFIG_SECTION, DEFAULT_MAX_ENTRIES); - if (this._maxEntries !== newMaxEntries) { + if (sendChangedEvents && this._maxEntries !== newMaxEntries) { sendSettingChangedEvent('MaxEntries', String(this._maxEntries), String(newMaxEntries)); - this._maxEntries = newMaxEntries; } + this._maxEntries = newMaxEntries; this.trimExtraEntries(); if (!this._persistHistory) { // We're not persisting history so we can immediately set loading to false to immediately