Skip to content

Commit aebab08

Browse files
authored
Merge branch 'main' into aeisenberg/ast-viewer
2 parents 3639dcb + 546ec2e commit aebab08

File tree

17 files changed

+197
-37
lines changed

17 files changed

+197
-37
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- Add the AST Viewer to inspect the QL AST of a source file in a database. Currently, only available for C/C++ sources.
6+
- Fix error with choosing qlpack search path.
67

78
## 1.3.1 - 7 July 2020
89

extensions/ql-vscode/gulpfile.js/webpack.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export const config: webpack.Configuration = {
2020
{
2121
test: /\.(ts|tsx)$/,
2222
loader: 'ts-loader',
23+
options: {
24+
configFile: 'src/view/tsconfig.json',
25+
}
2326
},
2427
{
2528
test: /\.less$/,

extensions/ql-vscode/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,6 @@
654654
"node-fetch": "~2.6.0",
655655
"react": "^16.8.6",
656656
"react-dom": "^16.8.6",
657-
"semmle-bqrs": "^0.0.1",
658-
"semmle-io-node": "^0.0.1",
659657
"@github/codeql-vscode-utils": "^0.0.4",
660658
"tmp": "^0.1.0",
661659
"tree-kill": "~1.2.2",

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+
* TODO: Types in this file are deprecated, and uses of them should be
3+
* migrated to the analogous 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;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { StringLocation, LocationValue, LocationStyle, ResolvableLocationValue } from './bqrs-types';
2+
3+
/**
4+
* The CodeQL filesystem libraries use this pattern in `getURL()` predicates
5+
* to describe the location of an entire filesystem resource.
6+
* Such locations appear as `StringLocation`s instead of `FivePartLocation`s.
7+
*
8+
* Folder resources also get similar URLs, but with the `folder` scheme.
9+
* They are deliberately ignored here, since there is no suitable location to show the user.
10+
*/
11+
const FILE_LOCATION_REGEX = /file:\/\/(.+):([0-9]+):([0-9]+):([0-9]+):([0-9]+)/;
12+
/**
13+
* Gets a resolvable source file location for the specified `LocationValue`, if possible.
14+
* @param loc The location to test.
15+
*/
16+
export function tryGetResolvableLocation(
17+
loc: LocationValue | undefined
18+
): ResolvableLocationValue | undefined {
19+
if (loc === undefined) {
20+
return undefined;
21+
} else if (loc.t === LocationStyle.FivePart && loc.file) {
22+
return loc;
23+
} else if (loc.t === LocationStyle.WholeFile && loc.file) {
24+
return loc;
25+
} else if (loc.t === LocationStyle.String && loc.loc) {
26+
return tryGetLocationFromString(loc);
27+
} else {
28+
return undefined;
29+
}
30+
}
31+
32+
export function tryGetLocationFromString(
33+
loc: StringLocation
34+
): ResolvableLocationValue | undefined {
35+
const matches = FILE_LOCATION_REGEX.exec(loc.loc);
36+
if (matches && matches.length > 1 && matches[1]) {
37+
if (isWholeFileMatch(matches)) {
38+
return {
39+
t: LocationStyle.WholeFile,
40+
file: matches[1],
41+
};
42+
} else {
43+
return {
44+
t: LocationStyle.FivePart,
45+
file: matches[1],
46+
lineStart: Number(matches[2]),
47+
colStart: Number(matches[3]),
48+
lineEnd: Number(matches[4]),
49+
colEnd: Number(matches[5]),
50+
};
51+
}
52+
} else {
53+
return undefined;
54+
}
55+
}
56+
57+
function isWholeFileMatch(matches: RegExpExecArray): boolean {
58+
return (
59+
matches[2] === '0' &&
60+
matches[3] === '0' &&
61+
matches[4] === '0' &&
62+
matches[5] === '0'
63+
);
64+
}

extensions/ql-vscode/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export class CodeQLCliServer implements Disposable {
604604
*/
605605
resolveQlpacks(additionalPacks: string[], searchPath?: string[]): Promise<QlpacksInfo> {
606606
const args = ['--additional-packs', additionalPacks.join(path.delimiter)];
607-
if (searchPath !== undefined) {
607+
if (searchPath?.length) {
608608
args.push('--search-path', path.join(...searchPath));
609609
}
610610

extensions/ql-vscode/src/compare/view/tsconfig.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
],
1111
"jsx": "react",
1212
"sourceMap": true,
13-
"rootDir": "../..",
13+
"rootDir": "..",
1414
"strict": true,
1515
"noUnusedLocals": true,
1616
"noImplicitReturns": true,
1717
"noFallthroughCasesInSwitch": true,
18-
"experimentalDecorators": true,
19-
"typeRoots" : ["./typings"]
18+
"experimentalDecorators": true
2019
},
2120
"exclude": [
2221
"node_modules"
2322
]
24-
}
23+
}

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import {
1616
FivePartLocation,
1717
LocationStyle,
1818
LocationValue,
19-
tryGetResolvableLocation,
2019
WholeFileLocation,
2120
ResolvableLocationValue,
22-
} from 'semmle-bqrs';
21+
} from './bqrs-types';
22+
import {
23+
tryGetResolvableLocation,
24+
} from './bqrs-utils';
2325
import { DatabaseItem, DatabaseManager } from './databases';
2426
import { ViewSourceFileMsg } from './interface-types';
2527
import { Logger } from './logging';

0 commit comments

Comments
 (0)