Skip to content

Commit ab020f2

Browse files
authored
Merge pull request #354 from aeisenberg/aesienberg/database-commands
Rename database and open database directory
2 parents 8f84989 + 81cbf26 commit ab020f2

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

extensions/ql-vscode/CHANGELOG.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
- Add a suggestion in alerts view to view raw results, when there are
66
raw results but no alerts.
7-
7+
- Add the ability to rename databases in the database view.
8+
- Add the ability to open the directory in the filesystem
9+
of a database.
10+
811
## 1.1.2 - 28 April 2020
912

1013
- Implement syntax highlighting for the new `unique` aggregate.
@@ -54,7 +57,7 @@
5457
## 1.0.3 - 13 January 2020
5558

5659
- Reduce the frequency of CodeQL CLI update checks to help avoid hitting GitHub API limits of 60 requests per
57-
hour for unauthenticated IPs.
60+
hour for unauthenticated IPs.
5861
- Fix sorting of result sets with names containing special characters.
5962

6063
## 1.0.2 - 13 December 2019
@@ -63,8 +66,7 @@ hour for unauthenticated IPs.
6366
- Allow customization of query history labels from settings and from
6467
query history view context menu.
6568
- Show number of results in results view.
66-
- Add commands `CodeQL: Show Next Step on Path` and `CodeQL: Show
67-
Previous Step on Path` for navigating the steps on the currently
69+
- Add commands `CodeQL: Show Next Step on Path` and `CodeQL: Show Previous Step on Path` for navigating the steps on the currently
6870
shown path result.
6971

7072
## 1.0.1 - 21 November 2019

extensions/ql-vscode/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@
203203
"command": "codeQLDatabases.upgradeDatabase",
204204
"title": "Upgrade Database"
205205
},
206+
{
207+
"command": "codeQLDatabases.renameDatabase",
208+
"title": "Rename Database"
209+
},
210+
{
211+
"command": "codeQLDatabases.openDatabaseFolder",
212+
"title": "Show Database Directory"
213+
},
206214
{
207215
"command": "codeQLDatabases.sortByName",
208216
"title": "Sort by Name",
@@ -302,6 +310,16 @@
302310
"group": "9_qlCommands",
303311
"when": "view == codeQLDatabases"
304312
},
313+
{
314+
"command": "codeQLDatabases.renameDatabase",
315+
"group": "9_qlCommands",
316+
"when": "view == codeQLDatabases"
317+
},
318+
{
319+
"command": "codeQLDatabases.openDatabaseFolder",
320+
"group": "9_qlCommands",
321+
"when": "view == codeQLDatabases"
322+
},
305323
{
306324
"command": "codeQLQueryHistory.openQuery",
307325
"group": "9_qlCommands",

extensions/ql-vscode/src/databases-ui.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as path from 'path';
22
import { DisposableObject } from 'semmle-vscode-utils';
3-
import { commands, Event, EventEmitter, ExtensionContext, ProviderResult, TreeDataProvider, TreeItem, Uri, window } from 'vscode';
3+
import { commands, Event, EventEmitter, ExtensionContext, ProviderResult, TreeDataProvider, TreeItem, Uri, window, env } from 'vscode';
44
import * as cli from './cli';
55
import { DatabaseItem, DatabaseManager, getUpgradesDirectories } from './databases';
6-
import { getOnDiskWorkspaceFolders } from './helpers';
6+
import { getOnDiskWorkspaceFolders, showAndLogErrorMessage } from './helpers';
77
import { logger } from './logging';
88
import { clearCacheInDatabase, UserCancellationException } from './run-queries';
99
import * as qsClient from './queryserver-client';
@@ -180,6 +180,8 @@ export class DatabaseUI extends DisposableObject {
180180
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.sortByDateAdded', this.handleSortByDateAdded));
181181
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.removeDatabase', this.handleRemoveDatabase));
182182
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.upgradeDatabase', this.handleUpgradeDatabase));
183+
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.renameDatabase', this.handleRenameDatabase));
184+
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.openDatabaseFolder', this.handleOpenFolder));
183185
}
184186

185187
private handleMakeCurrentDatabase = async (databaseItem: DatabaseItem): Promise<void> => {
@@ -272,6 +274,29 @@ export class DatabaseUI extends DisposableObject {
272274
this.databaseManager.removeDatabaseItem(databaseItem);
273275
}
274276

277+
private handleRenameDatabase = async (databaseItem: DatabaseItem): Promise<void> => {
278+
try {
279+
const newName = await window.showInputBox({
280+
prompt: 'Choose new database name',
281+
value: databaseItem.name
282+
});
283+
284+
if (newName) {
285+
this.databaseManager.renameDatabaseItem(databaseItem, newName);
286+
}
287+
} catch (e) {
288+
showAndLogErrorMessage(e.message);
289+
}
290+
}
291+
292+
private handleOpenFolder = async (databaseItem: DatabaseItem): Promise<void> => {
293+
try {
294+
await env.openExternal(databaseItem.databaseUri);
295+
} catch (e) {
296+
showAndLogErrorMessage(e.message);
297+
}
298+
}
299+
275300
/**
276301
* Return the current database directory. If we don't already have a
277302
* current database, ask the user for one, and return that, or

extensions/ql-vscode/src/databases.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export interface DatabaseItem {
203203
/** The URI of the database */
204204
readonly databaseUri: vscode.Uri;
205205
/** The name of the database to be displayed in the UI */
206-
readonly name: string;
206+
name: string;
207207
/** The URI of the database's source archive, or `undefined` if no source archive is to be used. */
208208
readonly sourceArchive: vscode.Uri | undefined;
209209
/**
@@ -287,6 +287,10 @@ class DatabaseItemImpl implements DatabaseItem {
287287
}
288288
}
289289

290+
public set name(newName: string) {
291+
this.options.displayName = newName;
292+
}
293+
290294
public get sourceArchive(): vscode.Uri | undefined {
291295
if (this.options.ignoreSourceArchive || (this._contents === undefined)) {
292296
return undefined;
@@ -461,6 +465,7 @@ function eventFired<T>(event: vscode.Event<T>, timeoutMs = 1000): Promise<T | un
461465
export class DatabaseManager extends DisposableObject {
462466
private readonly _onDidChangeDatabaseItem =
463467
this.push(new vscode.EventEmitter<DatabaseItem | undefined>());
468+
464469
readonly onDidChangeDatabaseItem = this._onDidChangeDatabaseItem.event;
465470

466471
private readonly _onDidChangeCurrentDatabaseItem =
@@ -642,6 +647,12 @@ export class DatabaseManager extends DisposableObject {
642647
this._onDidChangeDatabaseItem.fire(undefined);
643648
}
644649

650+
public async renameDatabaseItem(item: DatabaseItem, newName: string) {
651+
item.name = newName;
652+
this.updatePersistedDatabaseList();
653+
this._onDidChangeDatabaseItem.fire(item);
654+
}
655+
645656
public removeDatabaseItem(item: DatabaseItem) {
646657
if (this._currentDatabaseItem == item)
647658
this._currentDatabaseItem = undefined;

0 commit comments

Comments
 (0)