Skip to content

Commit d004f20

Browse files
author
Dave Bartolomeo
committed
Move UI-related code from QueryRunner into LocalQueries
1 parent f99f465 commit d004f20

6 files changed

Lines changed: 502 additions & 578 deletions

File tree

extensions/ql-vscode/src/ast-cfg-commands.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,18 @@ import {
55
TemplatePrintAstProvider,
66
TemplatePrintCfgProvider,
77
} from "./contextual/templateProvider";
8-
import { compileAndRunQuery } from "./local-queries";
9-
import { QueryRunner } from "./queryRunner";
10-
import { QueryHistoryManager } from "./query-history/query-history-manager";
11-
import { DatabaseUI } from "./local-databases-ui";
12-
import { ResultsView } from "./interface";
138
import { AstCfgCommands } from "./common/commands";
9+
import { LocalQueries } from "./local-queries";
1410

1511
type AstCfgOptions = {
16-
queryRunner: QueryRunner;
17-
queryHistoryManager: QueryHistoryManager;
18-
databaseUI: DatabaseUI;
19-
localQueryResultsView: ResultsView;
20-
queryStorageDir: string;
21-
12+
localQueries: LocalQueries;
2213
astViewer: AstViewer;
2314
astTemplateProvider: TemplatePrintAstProvider;
2415
cfgTemplateProvider: TemplatePrintCfgProvider;
2516
};
2617

2718
export function getAstCfgCommands({
28-
queryRunner,
29-
queryHistoryManager,
30-
databaseUI,
31-
localQueryResultsView,
32-
queryStorageDir,
19+
localQueries,
3320
astViewer,
3421
astTemplateProvider,
3522
cfgTemplateProvider,
@@ -59,12 +46,7 @@ export function getAstCfgCommands({
5946
window.activeTextEditor?.document,
6047
);
6148
if (res) {
62-
await compileAndRunQuery(
63-
queryRunner,
64-
queryHistoryManager,
65-
databaseUI,
66-
localQueryResultsView,
67-
queryStorageDir,
49+
await localQueries.compileAndRunQuery(
6850
false,
6951
res[0],
7052
progress,

extensions/ql-vscode/src/extension.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ import {
115115
QueryServerCommands,
116116
TestUICommands,
117117
} from "./common/commands";
118-
import {
119-
getLocalQueryCommands,
120-
showResultsForCompletedQuery,
121-
} from "./local-queries";
118+
import { LocalQueries } from "./local-queries";
122119
import { getAstCfgCommands } from "./ast-cfg-commands";
123120
import { getQueryEditorCommands } from "./query-editor";
124121
import { App } from "./common/app";
@@ -712,12 +709,6 @@ async function activateWithInstalledDistribution(
712709
void extLogger.log("Initializing query history manager.");
713710
const queryHistoryConfigurationListener = new QueryHistoryConfigListener();
714711
ctx.subscriptions.push(queryHistoryConfigurationListener);
715-
const showResults = async (item: CompletedLocalQueryInfo) =>
716-
showResultsForCompletedQuery(
717-
localQueryResultsView,
718-
item,
719-
WebviewReveal.Forced,
720-
);
721712
const queryStorageDir = join(ctx.globalStorageUri.fsPath, "queries");
722713
await ensureDir(queryStorageDir);
723714

@@ -791,8 +782,10 @@ async function activateWithInstalledDistribution(
791782
ctx,
792783
queryHistoryConfigurationListener,
793784
labelProvider,
794-
async (from: CompletedLocalQueryInfo, to: CompletedLocalQueryInfo) =>
795-
showResultsForComparison(compareView, from, to),
785+
async (
786+
from: CompletedLocalQueryInfo,
787+
to: CompletedLocalQueryInfo,
788+
): Promise<void> => showResultsForComparison(compareView, from, to),
796789
);
797790

798791
ctx.subscriptions.push(qhm);
@@ -813,7 +806,8 @@ async function activateWithInstalledDistribution(
813806
cliServer,
814807
queryServerLogger,
815808
labelProvider,
816-
showResults,
809+
async (item: CompletedLocalQueryInfo) =>
810+
localQueries.showResultsForCompletedQuery(item, WebviewReveal.Forced),
817811
);
818812
ctx.subscriptions.push(compareView);
819813

@@ -849,6 +843,18 @@ async function activateWithInstalledDistribution(
849843
true,
850844
);
851845

846+
const localQueries = new LocalQueries(
847+
app,
848+
qs,
849+
qhm,
850+
dbm,
851+
cliServer,
852+
databaseUI,
853+
localQueryResultsView,
854+
queryStorageDir,
855+
);
856+
ctx.subscriptions.push(localQueries);
857+
852858
void extLogger.log("Initializing QLTest interface.");
853859
const testExplorerExtension = extensions.getExtension<TestHub>(
854860
testExplorerExtensionId,
@@ -902,11 +908,7 @@ async function activateWithInstalledDistribution(
902908
...databaseUI.getCommands(),
903909
...dbModule.getCommands(),
904910
...getAstCfgCommands({
905-
queryRunner: qs,
906-
queryHistoryManager: qhm,
907-
databaseUI,
908-
localQueryResultsView,
909-
queryStorageDir,
911+
localQueries,
910912
astViewer,
911913
astTemplateProvider,
912914
cfgTemplateProvider,
@@ -926,16 +928,7 @@ async function activateWithInstalledDistribution(
926928
}
927929

928930
const queryServerCommands: QueryServerCommands = {
929-
...getLocalQueryCommands({
930-
app,
931-
queryRunner: qs,
932-
queryHistoryManager: qhm,
933-
databaseManager: dbm,
934-
cliServer,
935-
databaseUI,
936-
localQueryResultsView,
937-
queryStorageDir,
938-
}),
931+
...localQueries.getCommands(),
939932
};
940933

941934
for (const [commandName, command] of Object.entries(queryServerCommands)) {

extensions/ql-vscode/src/legacy-query-server/legacyRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class LegacyQueryRunner extends QueryRunner {
5757
await clearCacheInDatabase(this.qs, dbItem, progress, token);
5858
}
5959

60-
protected async compileAndRunQueryAgainstDatabaseCore(
60+
public async compileAndRunQueryAgainstDatabaseCore(
6161
dbPath: string,
6262
query: CoreQueryTarget,
6363
additionalPacks: string[],

0 commit comments

Comments
 (0)