Skip to content

Commit a1b020a

Browse files
committed
Create new folder and split classes into it
1 parent b9c8983 commit a1b020a

File tree

8 files changed

+205
-193
lines changed

8 files changed

+205
-193
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TemplatePrintCfgProvider,
77
} from "./contextual/templateProvider";
88
import { AstCfgCommands } from "./common/commands";
9-
import { LocalQueries } from "./local-queries";
9+
import { LocalQueries } from "./local-queries/local-queries";
1010

1111
type AstCfgOptions = {
1212
localQueries: LocalQueries;

extensions/ql-vscode/src/debugger/debug-configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
WorkspaceFolder,
66
} from "vscode";
77
import { getOnDiskWorkspaceFolders, showAndLogErrorMessage } from "../helpers";
8-
import { LocalQueries } from "../local-queries";
8+
import { LocalQueries } from "../local-queries/local-queries";
99
import { getQuickEvalContext, validateQueryPath } from "../run-queries-shared";
1010
import * as CodeQLProtocol from "./debug-protocol";
1111
import { getErrorMessage } from "../pure/helpers-pure";

extensions/ql-vscode/src/debugger/debugger-factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ProviderResult,
1010
} from "vscode";
1111
import { isCanary } from "../config";
12-
import { LocalQueries } from "../local-queries";
12+
import { LocalQueries } from "../local-queries/local-queries";
1313
import { DisposableObject } from "../pure/disposable-object";
1414
import { QueryRunner } from "../queryRunner";
1515
import { QLDebugConfigurationProvider } from "./debug-configuration";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "vscode";
1010
import { DebuggerCommands } from "../common/commands";
1111
import { DatabaseManager } from "../local-databases";
12-
import { LocalQueries, LocalQueryRun } from "../local-queries";
12+
import { LocalQueries } from "../local-queries/local-queries";
1313
import { DisposableObject } from "../pure/disposable-object";
1414
import { CoreQueryResults } from "../queryRunner";
1515
import {
@@ -20,6 +20,7 @@ import {
2020
import { QLResolvedDebugConfiguration } from "./debug-configuration";
2121
import * as CodeQLProtocol from "./debug-protocol";
2222
import { App } from "../common/app";
23+
import { LocalQueryRun } from "../local-queries/local-query-run";
2324

2425
/**
2526
* Listens to messages passing between VS Code and the debug adapter, so that we can supplement the

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ import {
117117
PreActivationCommands,
118118
QueryServerCommands,
119119
} from "./common/commands";
120-
import { LocalQueries } from "./local-queries";
120+
import { LocalQueries } from "./local-queries/local-queries";
121121
import { getAstCfgCommands } from "./ast-cfg-commands";
122122
import { getQueryEditorCommands } from "./query-editor";
123123
import { App } from "./common/app";

extensions/ql-vscode/src/local-queries.ts renamed to extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 21 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ProgressCallback, ProgressUpdate, withProgress } from "./progress";
1+
import { ProgressCallback, ProgressUpdate, withProgress } from "../progress";
22
import {
33
CancellationToken,
44
CancellationTokenSource,
@@ -8,76 +8,46 @@ import {
88
window,
99
workspace,
1010
} from "vscode";
11-
import { BaseLogger, extLogger, Logger, TeeLogger } from "./common";
12-
import { isCanary, MAX_QUERIES } from "./config";
13-
import { gatherQlFiles } from "./pure/files";
11+
import { extLogger, TeeLogger } from "../common";
12+
import { isCanary, MAX_QUERIES } from "../config";
13+
import { gatherQlFiles } from "../pure/files";
1414
import { basename } from "path";
1515
import {
1616
createTimestampFile,
1717
findLanguage,
1818
getOnDiskWorkspaceFolders,
1919
showAndLogErrorMessage,
20-
showAndLogExceptionWithTelemetry,
2120
showAndLogWarningMessage,
2221
showBinaryChoiceDialog,
23-
tryGetQueryMetadata,
24-
} from "./helpers";
25-
import { displayQuickQuery } from "./quick-query";
26-
import {
27-
CoreCompletedQuery,
28-
CoreQueryResults,
29-
QueryRunner,
30-
} from "./queryRunner";
31-
import { QueryHistoryManager } from "./query-history/query-history-manager";
32-
import { DatabaseUI } from "./local-databases-ui";
33-
import { ResultsView } from "./interface";
34-
import { DatabaseItem, DatabaseManager } from "./local-databases";
22+
} from "../helpers";
23+
import { displayQuickQuery } from "../quick-query";
24+
import { CoreCompletedQuery, QueryRunner } from "../queryRunner";
25+
import { QueryHistoryManager } from "../query-history/query-history-manager";
26+
import { DatabaseUI } from "../local-databases-ui";
27+
import { ResultsView } from "../interface";
28+
import { DatabaseItem, DatabaseManager } from "../local-databases";
3529
import {
3630
createInitialQueryInfo,
37-
EvaluatorLogPaths,
38-
generateEvalLogSummaries,
3931
getQuickEvalContext,
40-
logEndSummary,
4132
promptUserToSaveChanges,
42-
QueryEvaluationInfo,
4333
QueryOutputDir,
44-
QueryWithResults,
4534
SelectedQuery,
4635
validateQueryUri,
47-
} from "./run-queries-shared";
48-
import { CompletedLocalQueryInfo, LocalQueryInfo } from "./query-results";
49-
import { WebviewReveal } from "./interface-utils";
50-
import { asError, getErrorMessage } from "./pure/helpers-pure";
51-
import { CodeQLCliServer } from "./cli";
52-
import { LocalQueryCommands } from "./common/commands";
53-
import { App } from "./common/app";
54-
import { DisposableObject } from "./pure/disposable-object";
55-
import { QueryResultType } from "./pure/new-messages";
56-
import { redactableError } from "./pure/errors";
57-
import { SkeletonQueryWizard } from "./skeleton-query-wizard";
36+
} from "../run-queries-shared";
37+
import { CompletedLocalQueryInfo, LocalQueryInfo } from "../query-results";
38+
import { WebviewReveal } from "../interface-utils";
39+
import { asError, getErrorMessage } from "../pure/helpers-pure";
40+
import { CodeQLCliServer } from "../cli";
41+
import { LocalQueryCommands } from "../common/commands";
42+
import { App } from "../common/app";
43+
import { DisposableObject } from "../pure/disposable-object";
44+
import { SkeletonQueryWizard } from "../skeleton-query-wizard";
45+
import { LocalQueryRun } from "./local-query-run";
5846

5947
interface DatabaseQuickPickItem extends QuickPickItem {
6048
databaseItem: DatabaseItem;
6149
}
6250

63-
function formatResultMessage(result: CoreQueryResults): string {
64-
switch (result.resultType) {
65-
case QueryResultType.CANCELLATION:
66-
return `cancelled after ${Math.round(
67-
result.evaluationTime / 1000,
68-
)} seconds`;
69-
case QueryResultType.OOM:
70-
return "out of memory";
71-
case QueryResultType.SUCCESS:
72-
return `finished in ${Math.round(result.evaluationTime / 1000)} seconds`;
73-
case QueryResultType.COMPILATION_ERROR:
74-
return `compilation failed: ${result.message}`;
75-
case QueryResultType.OTHER_ERROR:
76-
default:
77-
return result.message ? `failed: ${result.message}` : "failed";
78-
}
79-
}
80-
8151
/**
8252
* If either the query file or the quickeval file is dirty, give the user the chance to save them.
8353
*/
@@ -97,142 +67,6 @@ async function promptToSaveQueryIfNeeded(query: SelectedQuery): Promise<void> {
9767
}
9868
}
9969

100-
/**
101-
* Tracks the evaluation of a local query, including its interactions with the UI.
102-
*
103-
* The client creates an instance of `LocalQueryRun` when the evaluation starts, and then invokes
104-
* the `complete()` function once the query has completed (successfully or otherwise).
105-
*
106-
* Having the client tell the `LocalQueryRun` when the evaluation is complete, rather than having
107-
* the `LocalQueryRun` manage the evaluation itself, may seem a bit clunky. It's done this way
108-
* because once we move query evaluation into a Debug Adapter, the debugging UI drives the
109-
* evaluation, and we can only respond to events from the debug adapter.
110-
*/
111-
export class LocalQueryRun {
112-
public constructor(
113-
private readonly outputDir: QueryOutputDir,
114-
private readonly localQueries: LocalQueries,
115-
private readonly queryInfo: LocalQueryInfo,
116-
private readonly dbItem: DatabaseItem,
117-
public readonly logger: Logger, // Public so that other clients, like the debug adapter, know where to send log output
118-
private readonly queryHistoryManager: QueryHistoryManager,
119-
private readonly cliServer: CodeQLCliServer,
120-
) {}
121-
122-
/**
123-
* Updates the UI based on the results of the query evaluation. This creates the evaluator log
124-
* summaries, updates the query history item for the evaluation with the results and evaluation
125-
* time, and displays the results view.
126-
*
127-
* This function must be called when the evaluation completes, whether the evaluation was
128-
* successful or not.
129-
* */
130-
public async complete(results: CoreQueryResults): Promise<void> {
131-
const evalLogPaths = await this.summarizeEvalLog(
132-
results.resultType,
133-
this.outputDir,
134-
this.logger,
135-
);
136-
if (evalLogPaths !== undefined) {
137-
this.queryInfo.setEvaluatorLogPaths(evalLogPaths);
138-
}
139-
const queryWithResults = await this.getCompletedQueryInfo(results);
140-
this.queryHistoryManager.completeQuery(this.queryInfo, queryWithResults);
141-
await this.localQueries.showResultsForCompletedQuery(
142-
this.queryInfo as CompletedLocalQueryInfo,
143-
WebviewReveal.Forced,
144-
);
145-
// Note we must update the query history view after showing results as the
146-
// display and sorting might depend on the number of results
147-
await this.queryHistoryManager.refreshTreeView();
148-
}
149-
150-
/**
151-
* Updates the UI in the case where query evaluation throws an exception.
152-
*/
153-
public async fail(err: Error): Promise<void> {
154-
err.message = `Error running query: ${err.message}`;
155-
this.queryInfo.failureReason = err.message;
156-
await this.queryHistoryManager.refreshTreeView();
157-
}
158-
159-
/**
160-
* Generate summaries of the structured evaluator log.
161-
*/
162-
private async summarizeEvalLog(
163-
resultType: QueryResultType,
164-
outputDir: QueryOutputDir,
165-
logger: BaseLogger,
166-
): Promise<EvaluatorLogPaths | undefined> {
167-
const evalLogPaths = await generateEvalLogSummaries(
168-
this.cliServer,
169-
outputDir,
170-
);
171-
if (evalLogPaths !== undefined) {
172-
if (evalLogPaths.endSummary !== undefined) {
173-
void logEndSummary(evalLogPaths.endSummary, logger); // Logged asynchrnously
174-
}
175-
} else {
176-
// Raw evaluator log was not found. Notify the user, unless we know why it wasn't found.
177-
if (resultType === QueryResultType.SUCCESS) {
178-
void showAndLogWarningMessage(
179-
`Failed to write structured evaluator log to ${outputDir.evalLogPath}.`,
180-
);
181-
} else {
182-
// Don't bother notifying the user if there's no log. For some errors, like compilation
183-
// errors, we don't expect a log. For cancellations and OOM errors, whether or not we have
184-
// a log depends on how far execution got before termination.
185-
}
186-
}
187-
188-
return evalLogPaths;
189-
}
190-
191-
/**
192-
* Gets a `QueryWithResults` containing information about the evaluation of the query and its
193-
* result, in the form expected by the query history UI.
194-
*/
195-
private async getCompletedQueryInfo(
196-
results: CoreQueryResults,
197-
): Promise<QueryWithResults> {
198-
// Read the query metadata if possible, to use in the UI.
199-
const metadata = await tryGetQueryMetadata(
200-
this.cliServer,
201-
this.queryInfo.initialInfo.queryPath,
202-
);
203-
const query = new QueryEvaluationInfo(
204-
this.outputDir.querySaveDir,
205-
this.dbItem.databaseUri.fsPath,
206-
await this.dbItem.hasMetadataFile(),
207-
this.queryInfo.initialInfo.quickEvalPosition,
208-
metadata,
209-
);
210-
211-
if (results.resultType !== QueryResultType.SUCCESS) {
212-
const message = results.message
213-
? redactableError`Failed to run query: ${results.message}`
214-
: redactableError`Failed to run query`;
215-
void showAndLogExceptionWithTelemetry(message);
216-
}
217-
const message = formatResultMessage(results);
218-
const successful = results.resultType === QueryResultType.SUCCESS;
219-
return {
220-
query,
221-
result: {
222-
evaluationTime: results.evaluationTime,
223-
queryId: 0,
224-
resultType: successful
225-
? QueryResultType.SUCCESS
226-
: QueryResultType.OTHER_ERROR,
227-
runId: 0,
228-
message,
229-
},
230-
message,
231-
successful,
232-
};
233-
}
234-
}
235-
23670
export class LocalQueries extends DisposableObject {
23771
public constructor(
23872
private readonly app: App,

0 commit comments

Comments
 (0)