Skip to content

Commit 26d83b5

Browse files
committed
Reduce dependencies on semmle-bqrs.
Eliminate references to types in library semmle-bqrs in favor of a local copy of those same types in bqrs-types.ts.
1 parent 2243c21 commit 26d83b5

11 files changed

Lines changed: 119 additions & 13 deletions

File tree

extensions/ql-vscode/src/adapt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DecodedBqrsChunk, ResultSetSchema, ColumnKind, Column, ColumnValue } from './bqrs-cli-types';
2-
import { LocationValue, ResultSetSchema as AdaptedSchema, ColumnSchema, ColumnType, LocationStyle } from 'semmle-bqrs';
2+
import { LocationValue, ResultSetSchema as AdaptedSchema, ColumnSchema, ColumnType, LocationStyle } from './bqrs-types';
33
import { ResultSet } from './interface-types';
44

55
// FIXME: This is a temporary bit of impedance matching to convert
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Types in this file are deprecated, and uses of them should be
3+
* migrated to the corresponding types in bqrs-cli-types.
4+
*/
5+
6+
export enum LocationStyle {
7+
None = 0,
8+
String,
9+
FivePart,
10+
/** Does not occur in BQRS files. Used only to distinguish whole-file locations in client code. */
11+
WholeFile
12+
}
13+
14+
/**
15+
* A primitive type (any type other than an element).
16+
*/
17+
export type PrimitiveTypeKind = 's' | 'b' | 'i' | 'f' | 'd' | 'u';
18+
19+
/**
20+
* A kind of type that a column may have.
21+
*/
22+
export type ColumnTypeKind = PrimitiveTypeKind | 'e';
23+
24+
/**
25+
* A column type that is a primitive type.
26+
*/
27+
export interface PrimitiveColumnType {
28+
type: PrimitiveTypeKind;
29+
}
30+
31+
/**
32+
* A column type that is an element type.
33+
*/
34+
export interface ElementColumnType {
35+
type: 'e';
36+
primitiveType: PrimitiveTypeKind;
37+
locationStyle: LocationStyle;
38+
hasLabel: boolean;
39+
}
40+
41+
/**
42+
* The type of a column.
43+
*/
44+
export type ColumnType = PrimitiveColumnType | ElementColumnType;
45+
46+
/**
47+
* The schema describing a single column in a `ResultSet`.
48+
*/
49+
export interface ColumnSchema {
50+
readonly name: string;
51+
readonly type: ColumnType;
52+
}
53+
54+
/**
55+
* The schema of a single `ResultSet` in a BQRS file.
56+
*/
57+
export interface ResultSetSchema {
58+
readonly version: number;
59+
readonly name: string;
60+
readonly tupleCount: number;
61+
readonly columns: readonly ColumnSchema[];
62+
}
63+
64+
/**
65+
* The schema describing the contents of a BQRS file.
66+
*/
67+
export interface ResultSetsSchema {
68+
readonly version: number,
69+
readonly stringPoolSize: number,
70+
readonly resultSets: readonly ResultSetSchema[]
71+
}
72+
73+
// See https://help.semmle.com/QL/learn-ql/ql/locations.html for how these are used.
74+
export interface FivePartLocation {
75+
t: LocationStyle.FivePart;
76+
file: string;
77+
lineStart: number;
78+
colStart: number;
79+
lineEnd: number;
80+
colEnd: number;
81+
}
82+
83+
export interface StringLocation {
84+
t: LocationStyle.String;
85+
loc: string;
86+
}
87+
88+
/**
89+
* A location representing an entire filesystem resource.
90+
* This is usually derived from a `StringLocation` with the entire filesystem URL.
91+
*/
92+
export interface WholeFileLocation {
93+
t: LocationStyle.WholeFile;
94+
file: string;
95+
}
96+
97+
export type RawLocationValue = FivePartLocation | StringLocation;
98+
99+
export type LocationValue = RawLocationValue | WholeFileLocation;
100+
101+
/** A location that may be resolved to a source code element. */
102+
export type ResolvableLocationValue = FivePartLocation | WholeFileLocation;

extensions/ql-vscode/src/interface-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ResolvableLocationValue,
44
ColumnSchema,
55
ResultSetSchema,
6-
} from 'semmle-bqrs';
6+
} from './bqrs-types';
77
import { ResultRow, ParsedResultSets, RawResultSet } from './adapt';
88

99
/**

extensions/ql-vscode/src/interface-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import {
1616
FivePartLocation,
1717
LocationStyle,
1818
LocationValue,
19-
tryGetResolvableLocation,
2019
WholeFileLocation,
2120
ResolvableLocationValue,
21+
} from './bqrs-types';
22+
import {
23+
tryGetResolvableLocation,
2224
} from 'semmle-bqrs';
2325
import { DatabaseItem, DatabaseManager } from './databases';
2426
import { ViewSourceFileMsg } from './interface-types';

extensions/ql-vscode/src/sarif-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Sarif from 'sarif';
22
import * as path from 'path';
3-
import { LocationStyle, ResolvableLocationValue } from 'semmle-bqrs';
3+
import { LocationStyle, ResolvableLocationValue } from './bqrs-types';
44

55
export interface SarifLink {
66
dest: number;

extensions/ql-vscode/src/view/RawTableHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import { vscode } from './vscode-api';
44
import { RawResultsSortState, SortDirection } from '../interface-types';
55
import { nextSortDirection } from './result-table-utils';
6-
import { ColumnSchema } from 'semmle-bqrs';
6+
import { ColumnSchema } from '../bqrs-types';
77

88
interface Props {
99
readonly columns: readonly ColumnSchema[];

extensions/ql-vscode/src/view/alert-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path';
22
import * as React from 'react';
33
import * as Sarif from 'sarif';
44
import * as Keys from '../result-keys';
5-
import { LocationStyle } from 'semmle-bqrs';
5+
import { LocationStyle } from '../bqrs-types';
66
import * as octicons from './octicons';
77
import { className, renderLocation, ResultTableProps, zebraStripe, selectableZebraStripe, jumpToLocation, nextSortDirection } from './result-table-utils';
88
import { onNavigation, NavigationEvent } from './results';

extensions/ql-vscode/src/view/result-table-utils.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
2-
import { LocationValue, ResolvableLocationValue, tryGetResolvableLocation } from 'semmle-bqrs';
2+
import { LocationValue, ResolvableLocationValue } from '../bqrs-types';
3+
import { tryGetResolvableLocation } from 'semmle-bqrs';
34
import { RawResultsSortState, QueryMetadata, SortDirection } from '../interface-types';
45
import { assertNever } from '../helpers-pure';
56
import { ResultSet } from '../interface-types';

extensions/ql-vscode/src/vscode-tests/no-workspace/interface-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
tryResolveLocation,
1010
} from '../../interface-utils';
1111
import { getDefaultResultSetName } from '../../interface-types';
12-
import { LocationStyle } from 'semmle-bqrs';
12+
import { LocationStyle } from '../../bqrs-types';
1313
import { DatabaseItem } from '../../databases';
1414

1515
describe('interface-utils', () => {

extensions/ql-vscode/test/pure-tests/location.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from 'chai';
22
import 'mocha';
3-
import { LocationStyle, StringLocation, tryGetResolvableLocation } from 'semmle-bqrs';
3+
import { LocationStyle, StringLocation } from '../../src/bqrs-types';
4+
import { tryGetResolvableLocation } from 'semmle-bqrs';
45

56
describe('processing string locations', function () {
67
it('should detect Windows whole-file locations', function () {

0 commit comments

Comments
 (0)