Merge pull request #3172 from github/koesie10/remove-legacy-messages

Remove legacy messages
This commit is contained in:
Koen Vlaswinkel 2023-12-22 16:14:45 +01:00 коммит произвёл GitHub
Родитель 2b625c85e8 2ba39647f2
Коммит d227af4c7b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
16 изменённых файлов: 34 добавлений и 267 удалений

Просмотреть файл

@ -30,11 +30,11 @@ import { walkDirectory } from "../common/files";
import { QueryMetadata, SortDirection } from "../common/interface-types";
import { BaseLogger, Logger } from "../common/logging";
import { ProgressReporter } from "../common/logging/vscode";
import { CompilationMessage } from "../query-server/legacy-messages";
import { sarifParser } from "../common/sarif-parser";
import { App } from "../common/app";
import { QueryLanguage } from "../common/query-language";
import { LINE_ENDINGS, splitStreamAtSeparators } from "../common/split-stream";
import { Position } from "../query-server/new-messages";
/**
* The version of the SARIF format that we are using.
@ -159,6 +159,24 @@ export type ResolvedQueries = string[];
*/
export type ResolvedTests = string[];
/**
* A compilation message for a test message (either an error or a warning)
*/
export interface CompilationMessage {
/**
* The text of the message
*/
message: string;
/**
* The source position associated with the message
*/
position: Position;
/**
* The severity of the message
*/
severity: number;
}
/**
* Event fired by `codeql test run`.
*/

Просмотреть файл

@ -125,12 +125,12 @@ export class CompareView extends AbstractWebview<
// only run interpolation if the label is user-defined
// otherwise we will wind up with duplicated rows
name: this.labelProvider.getShortLabel(from),
status: from.completedQuery.statusString,
status: from.completedQuery.message,
time: from.startTime,
},
toQuery: {
name: this.labelProvider.getShortLabel(to),
status: to.completedQuery.statusString,
status: to.completedQuery.message,
time: to.startTime,
},
},

Просмотреть файл

@ -178,15 +178,6 @@ export class LocalQueryRun {
const successful = results.resultType === QueryResultType.SUCCESS;
return {
query,
result: {
evaluationTime: results.evaluationTime,
queryId: 0,
resultType: successful
? QueryResultType.SUCCESS
: QueryResultType.OTHER_ERROR,
runId: 0,
message,
},
message,
successful,
};

Просмотреть файл

@ -77,14 +77,14 @@ export class HistoryItemLabelProvider {
private getLocalInterpolateReplacements(
item: LocalQueryInfo,
): InterpolateReplacements {
const { resultCount = 0, statusString = "in progress" } =
const { resultCount = 0, message = "in progress" } =
item.completedQuery || {};
return {
t: item.startTime,
q: item.getQueryName(),
d: item.databaseName,
r: `(${resultCount} results)`,
s: statusString,
s: message,
f: item.getQueryFileName(),
l: this.getLanguageLabel(item),
"%": "%",

Просмотреть файл

@ -1058,7 +1058,7 @@ export class QueryHistoryManager extends DisposableObject {
.map((item) => ({
label: this.labelProvider.getLabel(item),
description: item.databaseName,
detail: item.completedQuery.statusString,
detail: item.completedQuery.message,
query: item,
}));
if (comparableQueryLabels.length < 1) {

Просмотреть файл

@ -46,14 +46,6 @@ function mapCompletedQueryToDto(
return {
query: mapQueryEvaluationInfoToDto(query.query),
result: {
runId: query.result.runId,
queryId: query.result.queryId,
resultType: query.result.resultType,
evaluationTime: query.result.evaluationTime,
message: query.result.message,
logFileLocation: query.result.logFileLocation,
},
logFileLocation: query.logFileLocation,
successful: query.successful,
message: query.message,

Просмотреть файл

@ -56,17 +56,9 @@ function mapCompletedQueryInfoToDomainModel(
return new CompletedQueryInfo(
mapQueryEvaluationInfoToDomainModel(completedQuery.query),
{
runId: completedQuery.result.runId,
queryId: completedQuery.result.queryId,
resultType: completedQuery.result.resultType,
evaluationTime: completedQuery.result.evaluationTime,
message: completedQuery.result.message,
logFileLocation: completedQuery.result.logFileLocation,
},
completedQuery.logFileLocation,
completedQuery.successful ?? completedQuery.sucessful,
completedQuery.message,
completedQuery.successful ?? false,
completedQuery.message ?? "",
sortState,
completedQuery.resultCount,
sortedResults,

Просмотреть файл

@ -52,7 +52,6 @@ export interface CompletedQueryInfoDto {
// There once was a typo in the data model, which is why we need to support both
sucessful?: boolean;
result: EvaluationResultDto;
logFileLocation?: string;
resultCount: number;
sortedResultsInfo: Record<string, SortedResultSetInfoDto>;
@ -81,15 +80,6 @@ export enum SortDirectionDto {
desc,
}
interface EvaluationResultDto {
runId: number;
queryId: number;
resultType: number;
evaluationTime: number;
message?: string;
logFileLocation?: string;
}
export interface QueryEvaluationInfoDto {
querySaveDir: string;
dbItemPath: string;

Просмотреть файл

@ -1,7 +1,6 @@
import { CancellationTokenSource, env } from "vscode";
import * as messages from "./query-server/messages-shared";
import * as legacyMessages from "./query-server/legacy-messages";
import * as cli from "./codeql-cli/cli";
import { pathExists } from "fs-extra";
import { basename } from "path";
@ -23,7 +22,6 @@ import {
QueryWithResults,
} from "./run-queries-shared";
import { sarifParser } from "./common/sarif-parser";
import { formatLegacyMessage } from "./query-server/format-legacy-message";
/**
* query-results.ts
@ -54,14 +52,9 @@ export interface InitialQueryInfo {
export class CompletedQueryInfo implements QueryWithResults {
constructor(
public readonly query: QueryEvaluationInfo,
/**
* The legacy result. This is only set when loading from the query history.
*/
public readonly result: legacyMessages.EvaluationResult,
public readonly logFileLocation: string | undefined,
public readonly successful: boolean | undefined,
public readonly message: string | undefined,
public readonly successful: boolean,
public readonly message: string,
/**
* How we're currently sorting alerts. This is not mere interface
* state due to truncation; on re-sort, we want to read in the file
@ -82,16 +75,6 @@ export class CompletedQueryInfo implements QueryWithResults {
this.resultCount = value;
}
get statusString(): string {
if (this.message) {
return this.message;
} else if (this.result) {
return formatLegacyMessage(this.result);
} else {
throw new Error("No status available");
}
}
getResultsPath(selectedTable: string, useSorted = true): string {
if (!useSorted) {
return this.query.resultsPaths.resultsPath;
@ -291,7 +274,6 @@ export class LocalQueryInfo {
completeThisQuery(info: QueryWithResults): void {
this.completedQuery = new CompletedQueryInfo(
info.query,
info.result,
info.query.logPath,
info.successful,
info.message,

Просмотреть файл

@ -1,23 +0,0 @@
import * as legacyMessages from "./legacy-messages";
// Used for formatting the result of a legacy query which might still be in the
// user's query history.
export function formatLegacyMessage(result: legacyMessages.EvaluationResult) {
switch (result.resultType) {
case legacyMessages.QueryResultType.CANCELLATION:
return `cancelled after ${Math.round(
result.evaluationTime / 1000,
)} seconds`;
case legacyMessages.QueryResultType.OOM:
return "out of memory";
case legacyMessages.QueryResultType.SUCCESS:
return `finished in ${Math.round(result.evaluationTime / 1000)} seconds`;
case legacyMessages.QueryResultType.TIMEOUT:
return `timed out after ${Math.round(
result.evaluationTime / 1000,
)} seconds`;
case legacyMessages.QueryResultType.OTHER_ERROR:
default:
return result.message ? `failed: ${result.message}` : "failed";
}
}

Просмотреть файл

@ -1,124 +0,0 @@
/**
* Types for messages exchanged during jsonrpc communication with the
* the CodeQL query server.
*
* This file only contains types for messages that are still in use by
* the extension. Communication with the query server happens through
* messages in new-messages.ts.
*
* A note about the namespaces below, which look like they are
* essentially enums, namely Severity and QueryResultType.
* By design, for the sake of extensibility, clients
* receiving messages of this protocol are supposed to accept any
* number for any of these types. We commit to the given meaning of
* the numbers listed in constants in the namespaces, and we commit to
* the fact that any unknown QueryResultType value counts as an error.
*/
import * as shared from "./messages-shared";
/**
* A compilation message (either an error or a warning)
*/
export interface CompilationMessage {
/**
* The text of the message
*/
message: string;
/**
* The source position associated with the message
*/
position: Position;
/**
* The severity of the message
*/
severity: Severity;
}
export type Severity = number;
/**
* Severity of different messages. This namespace is intentionally not
* an enum, see "for the sake of extensibility" comment above.
*/
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Severity {
/**
* The message is a compilation error.
*/
export const ERROR = 0;
/**
* The message is a compilation warning.
*/
export const WARNING = 1;
}
/**
* The result of a single query
*/
export interface EvaluationResult {
/**
* The id of the run that this query was in
*/
runId: number;
/**
* The id of the query within the run
*/
queryId: number;
/**
* The type of the result. See QueryResultType for
* possible meanings. Any other result should be interpreted as an error.
*/
resultType: QueryResultType;
/**
* The wall clock time it took to evaluate the query.
* The time is from when we initially tried to evaluate the query
* to when we get the results. Hence with parallel evaluation the times may
* look odd.
*/
evaluationTime: number;
/**
* An error message if an error happened
*/
message?: string;
/**
* Full path to file with all log messages emitted while this query was active, if one exists
*/
logFileLocation?: string;
}
export type QueryResultType = number;
/**
* The result of running a query. This namespace is intentionally not
* an enum, see "for the sake of extensibility" comment above.
*/
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace QueryResultType {
/**
* The query ran successfully
*/
export const SUCCESS = 0;
/**
* The query failed due to an reason
* that isn't listed
*/
export const OTHER_ERROR = 1;
/**
* The query failed due to running out of
* memory
*/
export const OOM = 2;
/**
* The query failed due to exceeding the timeout
*/
export const TIMEOUT = 3;
/**
* The query failed because it was cancelled.
*/
export const CANCELLATION = 4;
}
/**
* A position within a QL file.
*/
export type Position = shared.Position;

Просмотреть файл

@ -1,5 +1,4 @@
import * as messages from "./query-server/messages-shared";
import * as legacyMessages from "./query-server/legacy-messages";
import { DatabaseInfo, QueryMetadata } from "./common/interface-types";
import { join, parse, dirname, basename } from "path";
import { Range, TextEditor, Uri, window, workspace } from "vscode";
@ -367,10 +366,9 @@ export class QueryEvaluationInfo extends QueryOutputDir {
export interface QueryWithResults {
readonly query: QueryEvaluationInfo;
readonly result: legacyMessages.EvaluationResult;
readonly logFileLocation?: string;
readonly successful?: boolean;
readonly message?: string;
readonly successful: boolean;
readonly message: string;
}
/**

Просмотреть файл

@ -6,7 +6,6 @@ import {
QueryWithResults,
} from "../../../src/run-queries-shared";
import { CancellationTokenSource } from "vscode";
import { QueryResultType } from "../../../src/query-server/legacy-messages";
import { QueryMetadata } from "../../../src/common/interface-types";
import { QueryLanguage } from "../../../src/common/query-language";
@ -94,11 +93,8 @@ export function createMockQueryWithResults({
metadata,
} as unknown as QueryEvaluationInfo,
successful: didRunSuccessfully,
result: {
evaluationTime: 1,
queryId: 0,
runId: 0,
resultType: QueryResultType.SUCCESS,
},
message: didRunSuccessfully
? "finished in 0 seconds"
: "compilation failed: unknown error",
};
}

Просмотреть файл

@ -9,7 +9,7 @@ import {
} from "vscode";
import * as CodeQLProtocol from "../../../../src/debugger/debug-protocol";
import { DisposableObject } from "../../../../src/common/disposable-object";
import { QueryResultType } from "../../../../src/query-server/legacy-messages";
import { QueryResultType } from "../../../../src/query-server/new-messages";
import { CoreCompletedQuery } from "../../../../src/query-server/query-runner";
import { QueryOutputDir } from "../../../../src/run-queries-shared";
import {

Просмотреть файл

@ -16,7 +16,6 @@ import {
import { DatabaseInfo } from "../../../../../src/common/interface-types";
import { CancellationTokenSource, Uri } from "vscode";
import { tmpDir } from "../../../../../src/tmp-dir";
import { QueryResultType } from "../../../../../src/query-server/legacy-messages";
import { VariantAnalysisHistoryItem } from "../../../../../src/query-history/variant-analysis-history-item";
import { QueryHistoryInfo } from "../../../../../src/query-history/query-history-info";
import { createMockVariantAnalysisHistoryItem } from "../../../../factories/query-history/variant-analysis-history-item";
@ -274,12 +273,6 @@ describe("write and read", () => {
query: queryEvalInfo,
successful: didRunSuccessfully,
message: "foo",
result: {
evaluationTime: 1,
queryId: 0,
runId: 0,
resultType: QueryResultType.SUCCESS,
},
};
return result;

Просмотреть файл

@ -25,13 +25,8 @@ import {
import { CodeQLCliServer, SourceInfo } from "../../../src/codeql-cli/cli";
import { CancellationTokenSource, Uri } from "vscode";
import { tmpDir } from "../../../src/tmp-dir";
import {
EvaluationResult,
QueryResultType,
} from "../../../src/query-server/legacy-messages";
import { sleep } from "../../../src/common/time";
import { mockedObject } from "../utils/mocking.helpers";
import { formatLegacyMessage } from "../../../src/query-server/format-legacy-message";
describe("query-results", () => {
let queryPath: string;
@ -106,33 +101,6 @@ describe("query-results", () => {
expect(completedQuery.getResultsPath("zxa")).toBe("bxa");
});
it("should format the statusString", () => {
const evalResult: EvaluationResult = {
resultType: QueryResultType.OTHER_ERROR,
evaluationTime: 12340,
queryId: 3,
runId: 1,
};
evalResult.message = "Tremendously";
expect(formatLegacyMessage(evalResult)).toBe("failed: Tremendously");
evalResult.resultType = QueryResultType.OTHER_ERROR;
expect(formatLegacyMessage(evalResult)).toBe("failed: Tremendously");
evalResult.resultType = QueryResultType.CANCELLATION;
evalResult.evaluationTime = 2345;
expect(formatLegacyMessage(evalResult)).toBe("cancelled after 2 seconds");
evalResult.resultType = QueryResultType.OOM;
expect(formatLegacyMessage(evalResult)).toBe("out of memory");
evalResult.resultType = QueryResultType.SUCCESS;
expect(formatLegacyMessage(evalResult)).toBe("finished in 2 seconds");
evalResult.resultType = QueryResultType.TIMEOUT;
expect(formatLegacyMessage(evalResult)).toBe("timed out after 2 seconds");
});
it("should updateSortState", async () => {
// setup
const fqi = createMockFullQueryInfo(
@ -471,12 +439,6 @@ describe("query-results", () => {
query: queryEvalInfo,
successful: didRunSuccessfully,
message: "foo",
result: {
evaluationTime: 1,
queryId: 0,
runId: 0,
resultType: QueryResultType.SUCCESS,
},
};
return result;