Prefix BQRS types with Bqrs

This commit is contained in:
Koen Vlaswinkel
2023-11-27 13:36:35 +01:00
parent 439cfcc023
commit 082c5e4a31
13 changed files with 89 additions and 81 deletions

View File

@@ -11,7 +11,7 @@ import { promisify } from "util";
import { CancellationToken, Disposable, Uri } from "vscode";
import {
BQRSInfo,
BqrsInfo,
DecodedBqrs,
DecodedBqrsChunk,
} from "../common/bqrs-cli-types";
@@ -928,11 +928,11 @@ export class CodeQLCliServer implements Disposable {
* @param bqrsPath The path to the bqrs.
* @param pageSize The page size to precompute offsets into the binary file for.
*/
async bqrsInfo(bqrsPath: string, pageSize?: number): Promise<BQRSInfo> {
async bqrsInfo(bqrsPath: string, pageSize?: number): Promise<BqrsInfo> {
const subcommandArgs = (
pageSize ? ["--paginate-rows", pageSize.toString()] : []
).concat(bqrsPath);
return await this.runJsonCodeQlCliCommand<BQRSInfo>(
return await this.runJsonCodeQlCliCommand<BqrsInfo>(
["bqrs", "info"],
subcommandArgs,
"Reading bqrs header",

View File

@@ -4,7 +4,7 @@
* the "for the sake of extensibility" comment in messages.ts.
*/
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace ColumnKindCode {
export namespace BqrsColumnKindCode {
export const FLOAT = "f";
export const INTEGER = "i";
export const STRING = "s";
@@ -13,44 +13,44 @@ export namespace ColumnKindCode {
export const ENTITY = "e";
}
export type ColumnKind =
| typeof ColumnKindCode.FLOAT
| typeof ColumnKindCode.INTEGER
| typeof ColumnKindCode.STRING
| typeof ColumnKindCode.BOOLEAN
| typeof ColumnKindCode.DATE
| typeof ColumnKindCode.ENTITY;
export type BqrsColumnKind =
| typeof BqrsColumnKindCode.FLOAT
| typeof BqrsColumnKindCode.INTEGER
| typeof BqrsColumnKindCode.STRING
| typeof BqrsColumnKindCode.BOOLEAN
| typeof BqrsColumnKindCode.DATE
| typeof BqrsColumnKindCode.ENTITY;
interface Column {
interface BqrsSchemaColumn {
name?: string;
kind: ColumnKind;
kind: BqrsColumnKind;
}
export interface ResultSetSchema {
export interface BqrsResultSetSchema {
name: string;
rows: number;
columns: Column[];
pagination?: PaginationInfo;
columns: BqrsSchemaColumn[];
pagination?: BqrsPaginationInfo;
}
interface PaginationInfo {
interface BqrsPaginationInfo {
"step-size": number;
offsets: number[];
}
export interface BQRSInfo {
"result-sets": ResultSetSchema[];
export interface BqrsInfo {
"result-sets": BqrsResultSetSchema[];
}
export type BqrsId = number;
export interface EntityValue {
url?: UrlValue;
export interface BqrsEntityValue {
url?: BqrsUrlValue;
label?: string;
id?: BqrsId;
}
export interface LineColumnLocation {
export interface BqrsLineColumnLocation {
uri: string;
startLine: number;
startColumn: number;
@@ -58,7 +58,7 @@ export interface LineColumnLocation {
endColumn: number;
}
export interface WholeFileLocation {
export interface BqrsWholeFileLocation {
uri: string;
startLine: never;
startColumn: never;
@@ -66,17 +66,17 @@ export interface WholeFileLocation {
endColumn: never;
}
type ResolvableLocationValue = WholeFileLocation | LineColumnLocation;
export type BqrsUrlValue =
| BqrsWholeFileLocation
| BqrsLineColumnLocation
| string;
export type UrlValue = ResolvableLocationValue | string;
export type CellValue = EntityValue | number | string | boolean;
export type BqrsCellValue = BqrsEntityValue | number | string | boolean;
export type BqrsKind =
| "String"
| "Float"
| "Integer"
| "String"
| "Boolean"
| "Date"
| "Entity";
@@ -85,8 +85,9 @@ interface BqrsColumn {
name?: string;
kind: BqrsKind;
}
export interface DecodedBqrsChunk {
tuples: CellValue[][];
tuples: BqrsCellValue[][];
next?: number;
columns: BqrsColumn[];
}

View File

@@ -1,13 +1,13 @@
import {
CellValue as BqrsCellValue,
ColumnKind as BqrsColumnKind,
ColumnKindCode,
BqrsCellValue as BqrsCellValue,
BqrsColumnKind as BqrsColumnKind,
BqrsColumnKindCode,
DecodedBqrsChunk,
EntityValue as BqrsEntityValue,
LineColumnLocation,
ResultSetSchema,
UrlValue as BqrsUrlValue,
WholeFileLocation,
BqrsEntityValue as BqrsEntityValue,
BqrsLineColumnLocation,
BqrsResultSetSchema,
BqrsUrlValue as BqrsUrlValue,
BqrsWholeFileLocation,
} from "./bqrs-cli-types";
import {
CellValue,
@@ -23,7 +23,7 @@ import { assertNever } from "./helpers-pure";
import { isEmptyPath } from "./bqrs-utils";
export function bqrsToResultSet(
schema: ResultSetSchema,
schema: BqrsResultSetSchema,
chunk: DecodedBqrsChunk,
): RawResultSet {
const name = schema.name;
@@ -52,17 +52,17 @@ export function bqrsToResultSet(
function mapColumnKind(kind: BqrsColumnKind): ColumnKind {
switch (kind) {
case ColumnKindCode.STRING:
case BqrsColumnKindCode.STRING:
return ColumnKind.String;
case ColumnKindCode.FLOAT:
case BqrsColumnKindCode.FLOAT:
return ColumnKind.Float;
case ColumnKindCode.INTEGER:
case BqrsColumnKindCode.INTEGER:
return ColumnKind.Integer;
case ColumnKindCode.BOOLEAN:
case BqrsColumnKindCode.BOOLEAN:
return ColumnKind.Boolean;
case ColumnKindCode.DATE:
case BqrsColumnKindCode.DATE:
return ColumnKind.Date;
case ColumnKindCode.ENTITY:
case BqrsColumnKindCode.ENTITY:
return ColumnKind.Entity;
default:
assertNever(kind);
@@ -136,7 +136,7 @@ export function mapUrlValue(urlValue: BqrsUrlValue): UrlValue | undefined {
return undefined;
}
function isLineColumnLoc(loc: BqrsUrlValue): loc is LineColumnLocation {
function isLineColumnLoc(loc: BqrsUrlValue): loc is BqrsLineColumnLocation {
return (
typeof loc !== "string" &&
!isEmptyPath(loc.uri) &&
@@ -147,7 +147,7 @@ function isLineColumnLoc(loc: BqrsUrlValue): loc is LineColumnLocation {
);
}
function isWholeFileLoc(loc: BqrsUrlValue): loc is WholeFileLocation {
function isWholeFileLoc(loc: BqrsUrlValue): loc is BqrsWholeFileLocation {
return (
typeof loc !== "string" && !isEmptyPath(loc.uri) && !isLineColumnLoc(loc)
);

View File

@@ -10,7 +10,7 @@ import { extLogger } from "../common/logging/vscode";
import { CodeQLCliServer } from "../codeql-cli/cli";
import { DatabaseManager } from "../databases/local-databases";
import { jumpToLocation } from "../databases/local-databases/locations";
import { BQRSInfo } from "../common/bqrs-cli-types";
import { BqrsInfo } from "../common/bqrs-cli-types";
import resultsDiff from "./resultsDiff";
import { CompletedLocalQueryInfo } from "../query-results";
import { assertNever, getErrorMessage } from "../common/helpers-pure";
@@ -232,7 +232,7 @@ export class CompareView extends AbstractWebview<
}
private async getResultSet(
bqrsInfo: BQRSInfo,
bqrsInfo: BqrsInfo,
resultSetName: string,
resultsPath: string,
): Promise<RawResultSet> {

View File

@@ -2,7 +2,7 @@ import { CodeQLCliServer } from "../../codeql-cli/cli";
import {
DecodedBqrsChunk,
BqrsId,
EntityValue,
BqrsEntityValue,
} from "../../common/bqrs-cli-types";
import { DatabaseItem } from "../../databases/local-databases";
import { ChildAstItem, AstItem } from "./ast-viewer";
@@ -56,8 +56,8 @@ export class AstBuilder {
// Build up the parent-child relationships
edgeTuples.tuples.forEach((tuple) => {
const [source, target, tupleType, value] = tuple as [
EntityValue,
EntityValue,
BqrsEntityValue,
BqrsEntityValue,
string,
string,
];
@@ -91,7 +91,11 @@ export class AstBuilder {
// populate parents and children
nodeTuples.tuples.forEach((tuple) => {
const [entity, tupleType, value] = tuple as [EntityValue, string, string];
const [entity, tupleType, value] = tuple as [
BqrsEntityValue,
string,
string,
];
const id = entity.id!;
switch (tupleType) {

View File

@@ -1,11 +1,14 @@
import * as vscode from "vscode";
import { UrlValue, LineColumnLocation } from "../../common/bqrs-cli-types";
import {
BqrsUrlValue,
BqrsLineColumnLocation,
} from "../../common/bqrs-cli-types";
import { isEmptyPath } from "../../common/bqrs-utils";
import { DatabaseItem } from "../../databases/local-databases";
export function fileRangeFromURI(
uri: UrlValue | undefined,
uri: BqrsUrlValue | undefined,
db: DatabaseItem,
): vscode.Location | undefined {
if (!uri || typeof uri === "string") {
@@ -13,7 +16,7 @@ export function fileRangeFromURI(
} else if ("startOffset" in uri) {
return undefined;
} else {
const loc = uri as LineColumnLocation;
const loc = uri as BqrsLineColumnLocation;
if (isEmptyPath(loc.uri)) {
return undefined;
}

View File

@@ -3,9 +3,9 @@ import {
encodeArchiveBasePath,
} from "../../common/vscode/archive-filesystem-provider";
import {
ColumnKindCode,
EntityValue,
ResultSetSchema,
BqrsColumnKindCode,
BqrsEntityValue,
BqrsResultSetSchema,
} from "../../common/bqrs-cli-types";
import { CodeQLCliServer } from "../../codeql-cli/cli";
import { DatabaseItem, DatabaseManager } from "../../databases/local-databases";
@@ -105,7 +105,7 @@ async function getLinksFromResults(
// TODO: Page this
const allTuples = await cli.bqrsDecode(bqrsPath, SELECT_QUERY_NAME);
for (const tuple of allTuples.tuples) {
const [src, dest] = tuple as [EntityValue, EntityValue];
const [src, dest] = tuple as [BqrsEntityValue, BqrsEntityValue];
const srcFile = src.url && fileRangeFromURI(src.url, db);
const destFile = dest.url && fileRangeFromURI(dest.url, db);
if (
@@ -131,12 +131,12 @@ function createTemplates(path: string): Record<string, string> {
};
}
function isValidSelect(selectInfo: ResultSetSchema | undefined) {
function isValidSelect(selectInfo: BqrsResultSetSchema | undefined) {
return (
selectInfo &&
selectInfo.columns.length === 3 &&
selectInfo.columns[0].kind === ColumnKindCode.ENTITY &&
selectInfo.columns[1].kind === ColumnKindCode.ENTITY &&
selectInfo.columns[2].kind === ColumnKindCode.STRING
selectInfo.columns[0].kind === BqrsColumnKindCode.ENTITY &&
selectInfo.columns[1].kind === BqrsColumnKindCode.ENTITY &&
selectInfo.columns[2].kind === BqrsColumnKindCode.STRING
);
}

View File

@@ -73,7 +73,7 @@ import { ResultsViewCommands } from "../common/commands";
import { App } from "../common/app";
import { Disposable } from "../common/disposable-object";
import { RawResultSet } from "../common/raw-result-types";
import { ResultSetSchema } from "../common/bqrs-cli-types";
import { BqrsResultSetSchema } from "../common/bqrs-cli-types";
/**
* results-view.ts
@@ -599,7 +599,7 @@ export class ResultsView extends AbstractWebview<
private async getResultSetSchemas(
completedQuery: CompletedQueryInfo,
selectedTable = "",
): Promise<ResultSetSchema[]> {
): Promise<BqrsResultSetSchema[]> {
const resultsPath = completedQuery.getResultsPath(selectedTable);
const schemas = await this.cliServer.bqrsInfo(
resultsPath,

View File

@@ -1,4 +1,4 @@
import { DecodedBqrsChunk, EntityValue } from "../common/bqrs-cli-types";
import { DecodedBqrsChunk, BqrsEntityValue } from "../common/bqrs-cli-types";
import { CallClassification, Method, Usage } from "./method";
import { ModeledMethodType } from "./modeled-method";
import { parseLibraryFilename } from "./library";
@@ -19,7 +19,7 @@ export function decodeBqrsToMethods(
const definition = getModelsAsDataLanguage(language);
chunk?.tuples.forEach((tuple) => {
let usageEntityValue: EntityValue;
let usageEntityValue: BqrsEntityValue;
let packageName: string;
let typeName: string;
let methodName: string;

View File

@@ -1,6 +1,6 @@
import { CallClassification } from "../method";
import { ModeledMethodType } from "../modeled-method";
import { EntityValue } from "../../common/bqrs-cli-types";
import { BqrsEntityValue } from "../../common/bqrs-cli-types";
export type Query = {
/**
@@ -40,7 +40,7 @@ export type Query = {
};
export type ApplicationModeTuple = [
EntityValue,
BqrsEntityValue,
string,
string,
string,
@@ -53,7 +53,7 @@ export type ApplicationModeTuple = [
];
export type FrameworkModeTuple = [
EntityValue,
BqrsEntityValue,
string,
string,
string,

View File

@@ -19,7 +19,7 @@ import { nanoid } from "nanoid";
import { CodeQLCliServer } from "./codeql-cli/cli";
import { SELECT_QUERY_NAME } from "./language-support";
import { DatabaseManager } from "./databases/local-databases";
import { DecodedBqrsChunk, EntityValue } from "./common/bqrs-cli-types";
import { DecodedBqrsChunk, BqrsEntityValue } from "./common/bqrs-cli-types";
import { BaseLogger, showAndLogWarningMessage } from "./common/logging";
import { extLogger } from "./common/logging/vscode";
import { generateSummarySymbolsFile } from "./log-insights/summary-parser";
@@ -294,7 +294,7 @@ export class QueryEvaluationInfo extends QueryOutputDir {
typeof v === "string" ? v.replaceAll('"', '""') : v
}"`;
} else if (chunk.columns[i].kind === "Entity") {
return (v as EntityValue).label;
return (v as BqrsEntityValue).label;
} else {
return v;
}

View File

@@ -4,7 +4,7 @@ import { CancellationTokenSource } from "vscode-jsonrpc";
import * as messages from "../../../src/query-server/new-messages";
import * as qsClient from "../../../src/query-server/query-server-client";
import * as cli from "../../../src/codeql-cli/cli";
import { CellValue } from "../../../src/common/bqrs-cli-types";
import { BqrsCellValue } from "../../../src/common/bqrs-cli-types";
import { describeWithCodeQL } from "../cli";
import { QueryServerClient } from "../../../src/query-server/query-server-client";
import {
@@ -60,7 +60,7 @@ class Checkpoint<T> {
}
type ResultSets = {
[name: string]: CellValue[][];
[name: string]: BqrsCellValue[][];
};
type QueryTestCase = {

View File

@@ -2,8 +2,8 @@ import { Uri, Range } from "vscode";
import { DatabaseItem } from "../../../../../src/databases/local-databases";
import {
WholeFileLocation,
LineColumnLocation,
BqrsWholeFileLocation,
BqrsLineColumnLocation,
} from "../../../../../src/common/bqrs-cli-types";
import { mockDatabaseItem } from "../../../utils/mocking.helpers";
import { fileRangeFromURI } from "../../../../../src/language-support";
@@ -24,7 +24,7 @@ describe("fileRangeFromURI", () => {
startColumn: 2,
endLine: 3,
endColumn: 4,
} as LineColumnLocation,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toBeUndefined();
@@ -39,7 +39,7 @@ describe("fileRangeFromURI", () => {
startColumn: 2,
endLine: 3,
endColumn: 4,
} as LineColumnLocation,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toBeUndefined();
@@ -54,7 +54,7 @@ describe("fileRangeFromURI", () => {
startColumn: 2,
endLine: 3,
endColumn: 4,
} as LineColumnLocation,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toBeUndefined();
@@ -65,7 +65,7 @@ describe("fileRangeFromURI", () => {
fileRangeFromURI(
{
uri: "file:///hucairz",
} as WholeFileLocation,
} as BqrsWholeFileLocation,
createMockDatabaseItem(),
),
).toEqual({
@@ -83,7 +83,7 @@ describe("fileRangeFromURI", () => {
startColumn: 2,
endLine: 3,
endColumn: 4,
} as LineColumnLocation,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toEqual({