Skip to content

Commit 4bf89ba

Browse files
Merge branch 'fix-large-sarif-handling' of github.com:marcnjaramillo/vscode-codeql into fix-large-sarif-handling
2 parents 830e918 + 15d2b7b commit 4bf89ba

23 files changed

Lines changed: 741 additions & 126 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ jobs:
7474
strategy:
7575
matrix:
7676
os: [ubuntu-latest, windows-latest]
77-
version: [stable, nightly]
7877
steps:
7978
- name: Checkout
8079
uses: actions/checkout@v2
@@ -104,31 +103,16 @@ jobs:
104103
run: |
105104
npm run lint
106105
107-
- name: Install CodeQL
108-
run: |
109-
mkdir codeql-home
110-
if [ ${{ matrix.version }} = "stable" ]
111-
then
112-
curl -L --silent https://github.com/github/codeql-cli-binaries/releases/latest/download/codeql.zip -o codeql-home/codeql.zip
113-
else
114-
curl -L --silent ${{ needs.find-nightly.outputs.url }}/codeql.zip -o codeql-home/codeql.zip
115-
fi
116-
unzip -q -o codeql-home/codeql.zip -d codeql-home
117-
unzip -q -o codeql-home/codeql.zip codeql/codeql.exe -d codeql-home
118-
rm codeql-home/codeql.zip
119-
shell: bash
120-
121106
- name: Run unit tests (Linux)
122107
working-directory: extensions/ql-vscode
123108
if: matrix.os == 'ubuntu-latest'
124109
run: |
125-
CODEQL_PATH=$GITHUB_WORKSPACE/codeql-home/codeql/codeql npm run test
110+
npm run test
126111
127112
- name: Run unit tests (Windows)
128113
if: matrix.os == 'windows-latest'
129114
working-directory: extensions/ql-vscode
130115
run: |
131-
$env:CODEQL_PATH=$(Join-Path $env:GITHUB_WORKSPACE -ChildPath 'codeql-home/codeql/codeql.exe')
132116
npm run test
133117
134118
- name: Run integration tests (Linux)
@@ -151,7 +135,7 @@ jobs:
151135
strategy:
152136
matrix:
153137
os: [ubuntu-latest, windows-latest]
154-
version: ['v2.3.3', 'v2.4.6', 'v2.5.9', 'v2.6.3', 'nightly']
138+
version: ['v2.3.3', 'v2.4.6', 'v2.5.9', 'v2.6.3', 'v2.7.0', 'nightly']
155139
env:
156140
CLI_VERSION: ${{ matrix.version }}
157141
NIGHTLY_URL: ${{ needs.find-nightly.outputs.url }}

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
44
// List of extensions which should be recommended for users of this workspace.
55
"recommendations": [
6-
"eamodio.tsl-problem-matcher",
6+
"amodio.tsl-problem-matcher",
77
"dbaeumer.vscode-eslint",
88
"eternalphane.tsfmt-vscode"
99
],

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// change to 'true' debug the IDE or Query servers
2222
"IDE_SERVER_JAVA_DEBUG": "false",
2323
"QUERY_SERVER_JAVA_DEBUG": "false",
24+
"CLI_SERVER_JAVA_DEBUG": "false",
25+
// Uncomment to set the JAVA_HOME for the codeql instance to use
26+
// "CODEQL_JAVA_HOME": "/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home"
2427
}
2528
},
2629
{
@@ -93,6 +96,19 @@
9396
// available in the workspace for the tests.
9497
// "${workspaceRoot}/../codeql"
9598
],
99+
"env": {
100+
// Optionally, set the version to use for the integration tests.
101+
// Use "nightly" to use the latest nightly build.
102+
// "CLI_VERSION": "2.7.0",
103+
104+
// If CLI_VERSION is set to nightly, set this to the url of the nightly build.
105+
// "NIGHTLY_URL": "some url to grab the nightly build",
106+
107+
// Optionally, add a path to the codeql executable to be used during these tests.
108+
// If not specified, one will be downloaded automatically.
109+
// This option overrides the CLI_VERSION option.
110+
// "CLI_PATH": "${workspaceRoot}/../semmle-code/target/intree/codeql/codeql",
111+
},
96112
"stopOnEntry": false,
97113
"sourceMaps": true,
98114
"outFiles": [

CONTRIBUTING.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ $ vscode/scripts/code-cli.sh --install-extension dist/vscode-codeql-*.vsix # if
7777

7878
You can use VS Code to debug the extension without explicitly installing it. Just open this directory as a workspace in VS Code, and hit `F5` to start a debugging session.
7979

80-
### Running the unit/integration tests
80+
### Running the unit tests and integration tests that do not require a CLI instance
8181

82-
Ensure the `CODEQL_PATH` environment variable is set to point to the `codeql` cli executable.
82+
Unit tests and many integration tests do not require a copy of the CodeQL CLI.
8383

8484
Outside of vscode, run:
8585

@@ -89,6 +89,16 @@ npm run test && npm run integration
8989

9090
Alternatively, you can run the tests inside of vscode. There are several vscode launch configurations defined that run the unit and integration tests. They can all be found in the debug view.
9191

92+
Only the _With CLI_ tests require a CLI instance to run. See below on how to do that.
93+
94+
Running from a terminal, you _must_ set the `TEST_CODEQL_PATH` variable to point to a checkout of the `github/codeql` repository. The appropriate CLI version will be downloaded as part of the test.
95+
96+
### Running the integration tests
97+
98+
The _Launch Integration Tests - With CLI_ tests require a CLI instance in order to run. There are several environment variables you can use to configure this.
99+
100+
From inside of VSCode, open the `launch.json` file and in the _Launch Integration Tests - With CLI_ uncomment and change the environment variables appropriate for your purpose.
101+
92102
## Releasing (write access required)
93103

94104
1. Double-check the `CHANGELOG.md` contains all desired change comments and has the version to be released with date at the top.

extensions/ql-vscode/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
## [UNRELEASED]
44

55
- Fix a bug that causes VSCode to crash when handling large SARIF files (>4GB) [#1004](https://github.com/github/vscode-codeql/pull/1004)
6+
- Fix the _CodeQL: Open Referenced File_ command for Windows systems. [#979](https://github.com/github/vscode-codeql/pull/979)
67
- Fix a bug that shows 'Set current database' when hovering over the currently selected database in the databases view. [#976](https://github.com/github/vscode-codeql/pull/976)
78
- Fix a bug with importing large databases. Databases over 4GB can now be imported directly from LGTM or from a zip file. This functionality is only available when using CodeQL CLI version 2.6.0 or later. [#971](https://github.com/github/vscode-codeql/pull/971)
89
- Replace certain control codes (`U+0000` - `U+001F`) with their corresponding control labels (`U+2400` - `U+241F`) in the results view. [#963](https://github.com/github/vscode-codeql/pull/963)
10+
- Allow case-insensitive project slugs for GitHub repositories when adding a CodeQL database from LGTM. [#978](https://github.com/github/vscode-codeql/pull/961)
11+
- Make "Open Referenced File" command accessible from the active editor menu. [#989](https://github.com/github/vscode-codeql/pull/989)
912

1013
## 1.5.6 - 07 October 2021
1114

extensions/ql-vscode/src/cli.ts

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { assertNever } from './pure/helpers-pure';
2222
import { QueryMetadata, SortDirection } from './pure/interface-types';
2323
import { Logger, ProgressReporter } from './logging';
2424
import { CompilationMessage } from './pure/messages';
25+
import { dbSchemeToLanguage } from './helpers';
2526

2627
/**
2728
* The version of the SARIF format that we are using.
@@ -166,6 +167,11 @@ export class CodeQLCliServer implements Disposable {
166167
/** Version of current cli, lazily computed by the `getVersion()` method */
167168
private _version: SemVer | undefined;
168169

170+
/**
171+
* The languages supported by the current version of the CLI, computed by `getSupportedLanguages()`.
172+
*/
173+
private _supportedLanguages: string[] | undefined;
174+
169175
/** Path to current codeQL executable, or undefined if not running yet. */
170176
codeQlPath: string | undefined;
171177

@@ -188,12 +194,14 @@ export class CodeQLCliServer implements Disposable {
188194
this.distributionProvider.onDidChangeDistribution(() => {
189195
this.restartCliServer();
190196
this._version = undefined;
197+
this._supportedLanguages = undefined;
191198
});
192199
}
193200
if (this.cliConfig.onDidChangeConfiguration) {
194201
this.cliConfig.onDidChangeConfiguration(() => {
195202
this.restartCliServer();
196203
this._version = undefined;
204+
this._supportedLanguages = undefined;
197205
});
198206
}
199207
}
@@ -264,11 +272,16 @@ export class CodeQLCliServer implements Disposable {
264272
*/
265273
private async launchProcess(): Promise<child_process.ChildProcessWithoutNullStreams> {
266274
const codeQlPath = await this.getCodeQlPath();
275+
const args = [];
276+
if (shouldDebugCliServer()) {
277+
args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9012,server=n,suspend=y,quiet=y');
278+
}
279+
267280
return await spawnServer(
268281
codeQlPath,
269282
'CodeQL CLI Server',
270283
['execute', 'cli-server'],
271-
[],
284+
args,
272285
this.logger,
273286
_data => { /**/ }
274287
);
@@ -653,7 +666,7 @@ export class CodeQLCliServer implements Disposable {
653666
if (target) subcommandArgs.push('--target', target);
654667
if (name) subcommandArgs.push('--name', name);
655668
subcommandArgs.push(archivePath);
656-
669+
657670
return await this.runCodeQlCliCommand(['database', 'unbundle'], subcommandArgs, `Extracting ${archivePath} to directory ${target}`);
658671
}
659672

@@ -809,6 +822,23 @@ export class CodeQLCliServer implements Disposable {
809822
return await this.runJsonCodeQlCliCommand<LanguagesInfo>(['resolve', 'languages'], [], 'Resolving languages');
810823
}
811824

825+
/**
826+
* Gets the list of available languages. Refines the result of `resolveLanguages()`, by excluding
827+
* extra things like "xml" and "properties".
828+
*
829+
* @returns An array of languages that are supported by the current version of the CodeQL CLI.
830+
*/
831+
public async getSupportedLanguages(): Promise<string[]> {
832+
if (!this._supportedLanguages) {
833+
// Get the intersection of resolveLanguages with the list of hardcoded languages in dbSchemeToLanguage.
834+
const resolvedLanguages = Object.keys(await this.resolveLanguages());
835+
const hardcodedLanguages = Object.values(dbSchemeToLanguage);
836+
837+
this._supportedLanguages = resolvedLanguages.filter(lang => hardcodedLanguages.includes(lang));
838+
}
839+
return this._supportedLanguages;
840+
}
841+
812842
/**
813843
* Gets information about queries in a query suite.
814844
* @param suite The suite to resolve.
@@ -834,6 +864,39 @@ export class CodeQLCliServer implements Disposable {
834864
);
835865
}
836866

867+
async packInstall(dir: string) {
868+
return this.runJsonCodeQlCliCommand(['pack', 'install'], [dir], 'Installing pack dependencies');
869+
}
870+
871+
async packBundle(dir: string, workspaceFolders: string[], outputPath: string, precompile = true): Promise<void> {
872+
const args = [
873+
'-o',
874+
outputPath,
875+
dir,
876+
'--additional-packs',
877+
workspaceFolders.join(path.delimiter)
878+
];
879+
if (!precompile && await this.cliConstraints.supportsNoPrecompile()) {
880+
args.push('--no-precompile');
881+
}
882+
883+
return this.runJsonCodeQlCliCommand(['pack', 'bundle'], args, 'Bundling pack');
884+
}
885+
886+
async packPacklist(dir: string, includeQueries: boolean): Promise<string[]> {
887+
const args = includeQueries ? [dir] : ['--no-include-queries', dir];
888+
// since 2.7.1, packlist returns an object with a "paths" property that is a list of packs.
889+
// previous versions return a list of packs.
890+
const results: { paths: string[] } | string[] = await this.runJsonCodeQlCliCommand(['pack', 'packlist'], args, 'Generating the pack list');
891+
892+
// Once we no longer need to support 2.7.0 or earlier, we can remove this and assume all versions return an object.
893+
if ('paths' in results) {
894+
return results.paths;
895+
} else {
896+
return results;
897+
}
898+
}
899+
837900
async generateDil(qloFile: string, outFile: string): Promise<void> {
838901
const extraArgs = await this.cliConstraints.supportsDecompileDil()
839902
? ['--kind', 'dil', '-o', outFile, qloFile]
@@ -1082,6 +1145,12 @@ export function shouldDebugQueryServer() {
10821145
&& process.env.QUERY_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
10831146
}
10841147

1148+
export function shouldDebugCliServer() {
1149+
return 'CLI_SERVER_JAVA_DEBUG' in process.env
1150+
&& process.env.CLI_SERVER_JAVA_DEBUG !== '0'
1151+
&& process.env.CLI_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
1152+
}
1153+
10851154
export class CliVersionConstraint {
10861155

10871156
/**
@@ -1121,6 +1190,16 @@ export class CliVersionConstraint {
11211190
*/
11221191
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.0');
11231192

1193+
/**
1194+
* CLI version where the `--no-precompile` option for pack creation was introduced.
1195+
*/
1196+
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer('2.7.1');
1197+
1198+
/**
1199+
* CLI version where remote queries are supported.
1200+
*/
1201+
public static CLI_VERSION_REMOTE_QUERIES = new SemVer('2.6.3');
1202+
11241203
constructor(private readonly cli: CodeQLCliServer) {
11251204
/**/
11261205
}
@@ -1157,4 +1236,12 @@ export class CliVersionConstraint {
11571236
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE);
11581237
}
11591238

1239+
async supportsNoPrecompile() {
1240+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE);
1241+
}
1242+
1243+
async supportsRemoteQueries() {
1244+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES);
1245+
}
1246+
11601247
}

extensions/ql-vscode/src/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ const REMOTE_QUERIES_SETTING = new Setting('remoteQueries', ROOT_SETTING);
304304
/**
305305
* Lists of GitHub repositories that you want to query remotely via the "Run Remote query" command.
306306
* Note: This command is only available for internal users.
307-
*
307+
*
308308
* This setting should be a JSON object where each key is a user-specified name (string),
309309
* and the value is an array of GitHub repositories (of the form `<owner>/<repo>`).
310310
*/
@@ -314,6 +314,10 @@ export function getRemoteRepositoryLists(): Record<string, string[]> | undefined
314314
return REMOTE_REPO_LISTS.getValue<Record<string, string[]>>() || undefined;
315315
}
316316

317+
export async function setRemoteRepositoryLists(lists: Record<string, string[]> | undefined) {
318+
await REMOTE_REPO_LISTS.updateValue(lists, ConfigurationTarget.Global);
319+
}
320+
317321
/**
318322
* The name of the "controller" repository that you want to use with the "Run Remote query" command.
319323
* Note: This command is only available for internal users.

0 commit comments

Comments
 (0)