Skip to content

Commit 4bb4627

Browse files
committed
Move DatabaseItem to separate file
1 parent 6331cdd commit 4bb4627

2 files changed

Lines changed: 97 additions & 90 deletions

File tree

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

Lines changed: 6 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ import { QlPackGenerator } from "../qlpack-generator";
3535
import { QueryLanguage } from "../common/query-language";
3636
import { App } from "../common/app";
3737
import { existsSync } from "fs";
38+
import { FullDatabaseOptions } from "./local-databases/database-options";
3839
import {
39-
DatabaseOptions,
40-
FullDatabaseOptions,
41-
} from "./local-databases/database-options";
40+
DatabaseItem,
41+
PersistedDatabaseItem,
42+
} from "./local-databases/database-item";
43+
44+
export { DatabaseItem } from "./local-databases/database-item";
4245

4346
/**
4447
* databases.ts
@@ -62,11 +65,6 @@ const CURRENT_DB = "currentDatabase";
6265
*/
6366
const DB_LIST = "databaseList";
6467

65-
interface PersistedDatabaseItem {
66-
uri: string;
67-
options?: DatabaseOptions;
68-
}
69-
7068
/**
7169
* The layout of the database.
7270
*/
@@ -226,88 +224,6 @@ export class DatabaseResolver {
226224
}
227225
}
228226

229-
/** An item in the list of available databases */
230-
export interface DatabaseItem {
231-
/** The URI of the database */
232-
readonly databaseUri: vscode.Uri;
233-
/** The name of the database to be displayed in the UI */
234-
name: string;
235-
236-
/** The primary language of the database or empty string if unknown */
237-
readonly language: string;
238-
/** The URI of the database's source archive, or `undefined` if no source archive is to be used. */
239-
readonly sourceArchive: vscode.Uri | undefined;
240-
/**
241-
* The contents of the database.
242-
* Will be `undefined` if the database is invalid. Can be updated by calling `refresh()`.
243-
*/
244-
readonly contents: DatabaseContents | undefined;
245-
246-
/**
247-
* The date this database was added as a unix timestamp. Or undefined if we don't know.
248-
*/
249-
readonly dateAdded: number | undefined;
250-
251-
/** If the database is invalid, describes why. */
252-
readonly error: Error | undefined;
253-
/**
254-
* Resolves the contents of the database.
255-
*
256-
* @remarks
257-
* The contents include the database directory, source archive, and metadata about the database.
258-
* If the database is invalid, `this.error` is updated with the error object that describes why
259-
* the database is invalid. This error is also thrown.
260-
*/
261-
refresh(): Promise<void>;
262-
/**
263-
* Resolves a filename to its URI in the source archive.
264-
*
265-
* @param file Filename within the source archive. May be `undefined` to return a dummy file path.
266-
*/
267-
resolveSourceFile(file: string | undefined): vscode.Uri;
268-
269-
/**
270-
* Holds if the database item has a `.dbinfo` or `codeql-database.yml` file.
271-
*/
272-
hasMetadataFile(): Promise<boolean>;
273-
274-
/**
275-
* Returns `sourceLocationPrefix` of exported database.
276-
*/
277-
getSourceLocationPrefix(server: cli.CodeQLCliServer): Promise<string>;
278-
279-
/**
280-
* Returns dataset folder of exported database.
281-
*/
282-
getDatasetFolder(server: cli.CodeQLCliServer): Promise<string>;
283-
284-
/**
285-
* Returns the root uri of the virtual filesystem for this database's source archive,
286-
* as displayed in the filesystem explorer.
287-
*/
288-
getSourceArchiveExplorerUri(): vscode.Uri;
289-
290-
/**
291-
* Holds if `uri` belongs to this database's source archive.
292-
*/
293-
belongsToSourceArchiveExplorerUri(uri: vscode.Uri): boolean;
294-
295-
/**
296-
* Whether the database may be affected by test execution for the given path.
297-
*/
298-
isAffectedByTest(testPath: string): Promise<boolean>;
299-
300-
/**
301-
* Gets the state of this database, to be persisted in the workspace state.
302-
*/
303-
getPersistedState(): PersistedDatabaseItem;
304-
305-
/**
306-
* Verifies that this database item has a zipped source folder. Returns an error message if it does not.
307-
*/
308-
verifyZippedSources(): string | undefined;
309-
}
310-
311227
export enum DatabaseEventKind {
312228
Add = "Add",
313229
Remove = "Remove",
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import vscode from "vscode";
2+
import * as cli from "../../codeql-cli/cli";
3+
import { DatabaseContents } from "../local-databases";
4+
import { DatabaseOptions } from "./database-options";
5+
6+
/** An item in the list of available databases */
7+
export interface DatabaseItem {
8+
/** The URI of the database */
9+
readonly databaseUri: vscode.Uri;
10+
/** The name of the database to be displayed in the UI */
11+
name: string;
12+
13+
/** The primary language of the database or empty string if unknown */
14+
readonly language: string;
15+
/** The URI of the database's source archive, or `undefined` if no source archive is to be used. */
16+
readonly sourceArchive: vscode.Uri | undefined;
17+
/**
18+
* The contents of the database.
19+
* Will be `undefined` if the database is invalid. Can be updated by calling `refresh()`.
20+
*/
21+
readonly contents: DatabaseContents | undefined;
22+
23+
/**
24+
* The date this database was added as a unix timestamp. Or undefined if we don't know.
25+
*/
26+
readonly dateAdded: number | undefined;
27+
28+
/** If the database is invalid, describes why. */
29+
readonly error: Error | undefined;
30+
/**
31+
* Resolves the contents of the database.
32+
*
33+
* @remarks
34+
* The contents include the database directory, source archive, and metadata about the database.
35+
* If the database is invalid, `this.error` is updated with the error object that describes why
36+
* the database is invalid. This error is also thrown.
37+
*/
38+
refresh(): Promise<void>;
39+
/**
40+
* Resolves a filename to its URI in the source archive.
41+
*
42+
* @param file Filename within the source archive. May be `undefined` to return a dummy file path.
43+
*/
44+
resolveSourceFile(file: string | undefined): vscode.Uri;
45+
46+
/**
47+
* Holds if the database item has a `.dbinfo` or `codeql-database.yml` file.
48+
*/
49+
hasMetadataFile(): Promise<boolean>;
50+
51+
/**
52+
* Returns `sourceLocationPrefix` of exported database.
53+
*/
54+
getSourceLocationPrefix(server: cli.CodeQLCliServer): Promise<string>;
55+
56+
/**
57+
* Returns dataset folder of exported database.
58+
*/
59+
getDatasetFolder(server: cli.CodeQLCliServer): Promise<string>;
60+
61+
/**
62+
* Returns the root uri of the virtual filesystem for this database's source archive,
63+
* as displayed in the filesystem explorer.
64+
*/
65+
getSourceArchiveExplorerUri(): vscode.Uri;
66+
67+
/**
68+
* Holds if `uri` belongs to this database's source archive.
69+
*/
70+
belongsToSourceArchiveExplorerUri(uri: vscode.Uri): boolean;
71+
72+
/**
73+
* Whether the database may be affected by test execution for the given path.
74+
*/
75+
isAffectedByTest(testPath: string): Promise<boolean>;
76+
77+
/**
78+
* Gets the state of this database, to be persisted in the workspace state.
79+
*/
80+
getPersistedState(): PersistedDatabaseItem;
81+
82+
/**
83+
* Verifies that this database item has a zipped source folder. Returns an error message if it does not.
84+
*/
85+
verifyZippedSources(): string | undefined;
86+
}
87+
88+
export interface PersistedDatabaseItem {
89+
uri: string;
90+
options?: DatabaseOptions;
91+
}

0 commit comments

Comments
 (0)