Add query history persistence (#20700)

* initial

* Fix and revert secret storage changes

* persist to file

* Add debounce and write on dispose

* Fix run

* No ext dependencies and show warning message

* Remove test stuff

* comments

* Fix tests and console logs
This commit is contained in:
Charles Gagnon
2022-09-30 16:48:55 -07:00
committed by GitHub
parent 3aa416df6d
commit d6d75d8817
10 changed files with 255 additions and 38 deletions

View File

@@ -8,6 +8,7 @@ import * as vscode from 'vscode';
import { DOUBLE_CLICK_ACTION_CONFIG_SECTION, ITEM_SELECTED_COMMAND_ID, QUERY_HISTORY_CONFIG_SECTION } from './constants';
import { QueryHistoryItem } from './queryHistoryItem';
import { QueryHistoryProvider } from './queryHistoryProvider';
import { promises as fs } from 'fs';
let lastSelectedItem: { item: QueryHistoryItem | undefined, time: number | undefined } = {
item: undefined,
@@ -19,7 +20,15 @@ let lastSelectedItem: { item: QueryHistoryItem | undefined, time: number | undef
const DOUBLE_CLICK_TIMEOUT_MS = 500;
export async function activate(context: vscode.ExtensionContext): Promise<void> {
const treeDataProvider = new QueryHistoryProvider();
// Create the global storage folder now for storing the query history persistance file
try {
await fs.mkdir(context.globalStorageUri.fsPath);
} catch (err) {
if (err.code !== 'EEXIST') {
console.error(`Error creating query history global storage folder ${context.globalStorageUri.fsPath}. ${err}`);
}
}
const treeDataProvider = new QueryHistoryProvider(context);
context.subscriptions.push(treeDataProvider);
const treeView = vscode.window.createTreeView('queryHistory', {
treeDataProvider,
@@ -63,10 +72,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
return runQuery(item);
}));
context.subscriptions.push(vscode.commands.registerCommand('queryHistory.delete', (item: QueryHistoryItem) => {
treeDataProvider.deleteItem(item);
return treeDataProvider.deleteItem(item);
}));
context.subscriptions.push(vscode.commands.registerCommand('queryHistory.clear', () => {
treeDataProvider.clearAll();
return treeDataProvider.clearAll();
}));
context.subscriptions.push(vscode.commands.registerCommand('queryHistory.disableCapture', async () => {
return treeDataProvider.setCaptureEnabled(false);
@@ -88,6 +97,10 @@ async function runQuery(item: QueryHistoryItem): Promise<void> {
{
content: item.queryText
}, item.connectionProfile?.providerId);
await azdata.queryeditor.connect(doc.uri, item.connectionProfile?.connectionId || '');
if (item.connectionProfile) {
await doc.connect(item.connectionProfile);
} else {
await azdata.queryeditor.connect(doc.uri, '');
}
azdata.queryeditor.runQuery(doc.uri);
}