Skip to content

Commit

Permalink
Merge pull request #354 from aeisenberg/aesienberg/database-commands
Browse files Browse the repository at this point in the history
Rename database and open database directory
  • Loading branch information
jcreedcmu authored May 8, 2020
2 parents 8f84989 + 81cbf26 commit ab020f2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
10 changes: 6 additions & 4 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

- Add a suggestion in alerts view to view raw results, when there are
raw results but no alerts.

- Add the ability to rename databases in the database view.
- Add the ability to open the directory in the filesystem
of a database.

## 1.1.2 - 28 April 2020

- Implement syntax highlighting for the new `unique` aggregate.
Expand Down Expand Up @@ -54,7 +57,7 @@
## 1.0.3 - 13 January 2020

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

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

## 1.0.1 - 21 November 2019
Expand Down
18 changes: 18 additions & 0 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@
"command": "codeQLDatabases.upgradeDatabase",
"title": "Upgrade Database"
},
{
"command": "codeQLDatabases.renameDatabase",
"title": "Rename Database"
},
{
"command": "codeQLDatabases.openDatabaseFolder",
"title": "Show Database Directory"
},
{
"command": "codeQLDatabases.sortByName",
"title": "Sort by Name",
Expand Down Expand Up @@ -302,6 +310,16 @@
"group": "9_qlCommands",
"when": "view == codeQLDatabases"
},
{
"command": "codeQLDatabases.renameDatabase",
"group": "9_qlCommands",
"when": "view == codeQLDatabases"
},
{
"command": "codeQLDatabases.openDatabaseFolder",
"group": "9_qlCommands",
"when": "view == codeQLDatabases"
},
{
"command": "codeQLQueryHistory.openQuery",
"group": "9_qlCommands",
Expand Down
29 changes: 27 additions & 2 deletions extensions/ql-vscode/src/databases-ui.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as path from 'path';
import { DisposableObject } from 'semmle-vscode-utils';
import { commands, Event, EventEmitter, ExtensionContext, ProviderResult, TreeDataProvider, TreeItem, Uri, window } from 'vscode';
import { commands, Event, EventEmitter, ExtensionContext, ProviderResult, TreeDataProvider, TreeItem, Uri, window, env } from 'vscode';
import * as cli from './cli';
import { DatabaseItem, DatabaseManager, getUpgradesDirectories } from './databases';
import { getOnDiskWorkspaceFolders } from './helpers';
import { getOnDiskWorkspaceFolders, showAndLogErrorMessage } from './helpers';
import { logger } from './logging';
import { clearCacheInDatabase, UserCancellationException } from './run-queries';
import * as qsClient from './queryserver-client';
Expand Down Expand Up @@ -180,6 +180,8 @@ export class DatabaseUI extends DisposableObject {
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.sortByDateAdded', this.handleSortByDateAdded));
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.removeDatabase', this.handleRemoveDatabase));
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.upgradeDatabase', this.handleUpgradeDatabase));
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.renameDatabase', this.handleRenameDatabase));
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.openDatabaseFolder', this.handleOpenFolder));
}

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

private handleRenameDatabase = async (databaseItem: DatabaseItem): Promise<void> => {
try {
const newName = await window.showInputBox({
prompt: 'Choose new database name',
value: databaseItem.name
});

if (newName) {
this.databaseManager.renameDatabaseItem(databaseItem, newName);
}
} catch (e) {
showAndLogErrorMessage(e.message);
}
}

private handleOpenFolder = async (databaseItem: DatabaseItem): Promise<void> => {
try {
await env.openExternal(databaseItem.databaseUri);
} catch (e) {
showAndLogErrorMessage(e.message);
}
}

/**
* Return the current database directory. If we don't already have a
* current database, ask the user for one, and return that, or
Expand Down
13 changes: 12 additions & 1 deletion extensions/ql-vscode/src/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export interface DatabaseItem {
/** The URI of the database */
readonly databaseUri: vscode.Uri;
/** The name of the database to be displayed in the UI */
readonly name: string;
name: string;
/** The URI of the database's source archive, or `undefined` if no source archive is to be used. */
readonly sourceArchive: vscode.Uri | undefined;
/**
Expand Down Expand Up @@ -287,6 +287,10 @@ class DatabaseItemImpl implements DatabaseItem {
}
}

public set name(newName: string) {
this.options.displayName = newName;
}

public get sourceArchive(): vscode.Uri | undefined {
if (this.options.ignoreSourceArchive || (this._contents === undefined)) {
return undefined;
Expand Down Expand Up @@ -461,6 +465,7 @@ function eventFired<T>(event: vscode.Event<T>, timeoutMs = 1000): Promise<T | un
export class DatabaseManager extends DisposableObject {
private readonly _onDidChangeDatabaseItem =
this.push(new vscode.EventEmitter<DatabaseItem | undefined>());

readonly onDidChangeDatabaseItem = this._onDidChangeDatabaseItem.event;

private readonly _onDidChangeCurrentDatabaseItem =
Expand Down Expand Up @@ -642,6 +647,12 @@ export class DatabaseManager extends DisposableObject {
this._onDidChangeDatabaseItem.fire(undefined);
}

public async renameDatabaseItem(item: DatabaseItem, newName: string) {
item.name = newName;
this.updatePersistedDatabaseList();
this._onDidChangeDatabaseItem.fire(item);
}

public removeDatabaseItem(item: DatabaseItem) {
if (this._currentDatabaseItem == item)
this._currentDatabaseItem = undefined;
Expand Down

0 comments on commit ab020f2

Please sign in to comment.