Skip to content

Commit dc1767b

Browse files
committed
Merge branch 'qlhelp-preview' of https://github.com/mgsium/vscode-codeql into qlhelp-preview
2 parents 78d585b + 72e623d commit dc1767b

20 files changed

Lines changed: 622 additions & 88 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 17 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)

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@
9696
// available in the workspace for the tests.
9797
// "${workspaceRoot}/../codeql"
9898
],
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+
},
99112
"stopOnEntry": false,
100113
"sourceMaps": true,
101114
"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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- 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)
99
- Allow case-insensitive project slugs for GitHub repositories when adding a CodeQL database from LGTM. [#978](https://github.com/github/vscode-codeql/pull/961)
1010
- Add a _CodeQL: Preview Query Help_ command to generate Markdown previews of `.qhelp` query help files. See https://codeql.github.com/docs/codeql-cli/testing-query-help-files for more information about query help. [#988](https://github.com/github/vscode-codeql/pull/988)
11+
- Make "Open Referenced File" command accessible from the active editor menu. [#989](https://github.com/github/vscode-codeql/pull/989)
1112

1213
## 1.5.6 - 07 October 2021
1314

extensions/ql-vscode/src/cli.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,39 @@ export class CodeQLCliServer implements Disposable {
820820
);
821821
}
822822

823+
async packInstall(dir: string) {
824+
return this.runJsonCodeQlCliCommand(['pack', 'install'], [dir], 'Installing pack dependencies');
825+
}
826+
827+
async packBundle(dir: string, workspaceFolders: string[], outputPath: string, precompile = true): Promise<void> {
828+
const args = [
829+
'-o',
830+
outputPath,
831+
dir,
832+
'--additional-packs',
833+
workspaceFolders.join(path.delimiter)
834+
];
835+
if (!precompile && await this.cliConstraints.supportsNoPrecompile()) {
836+
args.push('--no-precompile');
837+
}
838+
839+
return this.runJsonCodeQlCliCommand(['pack', 'bundle'], args, 'Bundling pack');
840+
}
841+
842+
async packPacklist(dir: string, includeQueries: boolean): Promise<string[]> {
843+
const args = includeQueries ? [dir] : ['--no-include-queries', dir];
844+
// since 2.7.1, packlist returns an object with a "paths" property that is a list of packs.
845+
// previous versions return a list of packs.
846+
const results: { paths: string[] } | string[] = await this.runJsonCodeQlCliCommand(['pack', 'packlist'], args, 'Generating the pack list');
847+
848+
// Once we no longer need to support 2.7.0 or earlier, we can remove this and assume all versions return an object.
849+
if ('paths' in results) {
850+
return results.paths;
851+
} else {
852+
return results;
853+
}
854+
}
855+
823856
async generateDil(qloFile: string, outFile: string): Promise<void> {
824857
const extraArgs = await this.cliConstraints.supportsDecompileDil()
825858
? ['--kind', 'dil', '-o', outFile, qloFile]
@@ -1113,6 +1146,16 @@ export class CliVersionConstraint {
11131146
*/
11141147
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.0');
11151148

1149+
/**
1150+
* CLI version where the `--no-precompile` option for pack creation was introduced.
1151+
*/
1152+
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer('2.7.1');
1153+
1154+
/**
1155+
* CLI version where remote queries are supported.
1156+
*/
1157+
public static CLI_VERSION_REMOTE_QUERIES = new SemVer('2.6.3');
1158+
11161159
constructor(private readonly cli: CodeQLCliServer) {
11171160
/**/
11181161
}
@@ -1149,4 +1192,12 @@ export class CliVersionConstraint {
11491192
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE);
11501193
}
11511194

1195+
async supportsNoPrecompile() {
1196+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE);
1197+
}
1198+
1199+
async supportsRemoteQueries() {
1200+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES);
1201+
}
1202+
11521203
}

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.

extensions/ql-vscode/src/extension.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,11 @@ async function activateWithInstalledDistribution(
523523
async function openReferencedFile(
524524
selectedQuery: Uri
525525
): Promise<void> {
526-
if (qs !== undefined) {
526+
// If no file is selected, the path of the file in the editor is selected
527+
const path = selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath;
528+
if (qs !== undefined && path) {
527529
if (await cliServer.cliConstraints.supportsResolveQlref()) {
528-
const resolved = await cliServer.resolveQlref(selectedQuery.fsPath);
530+
const resolved = await cliServer.resolveQlref(path);
529531
const uri = Uri.file(resolved.resolvedPath);
530532
await window.showTextDocument(uri, { preview: false });
531533
} else {
@@ -743,13 +745,25 @@ async function activateWithInstalledDistribution(
743745
);
744746
// The "runRemoteQuery" command is internal-only.
745747
ctx.subscriptions.push(
746-
commandRunner('codeQL.runRemoteQuery', async (
748+
commandRunnerWithProgress('codeQL.runRemoteQuery', async (
749+
progress: ProgressCallback,
750+
token: CancellationToken,
747751
uri: Uri | undefined
748752
) => {
749753
if (isCanary()) {
754+
progress({
755+
maxStep: 5,
756+
step: 0,
757+
message: 'Getting credentials'
758+
});
750759
const credentials = await Credentials.initialize(ctx);
751-
await runRemoteQuery(cliServer, credentials, uri || window.activeTextEditor?.document.uri);
760+
await runRemoteQuery(cliServer, credentials, uri || window.activeTextEditor?.document.uri, false, progress, token);
761+
} else {
762+
throw new Error('Remote queries require the CodeQL Canary version to run.');
752763
}
764+
}, {
765+
title: 'Run Remote Query',
766+
cancellable: true
753767
})
754768
);
755769
ctx.subscriptions.push(

extensions/ql-vscode/src/helpers.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
env
1111
} from 'vscode';
1212
import { CodeQLCliServer, QlpacksInfo } from './cli';
13+
import { UserCancellationException } from './commandRunner';
1314
import { logger } from './logging';
1415

1516
/**
@@ -494,14 +495,25 @@ export async function findLanguage(
494495
void logger.log('Could not autodetect query language. Select language manually.');
495496
}
496497
}
497-
const availableLanguages = Object.keys(await cliServer.resolveLanguages());
498+
499+
// will be undefined if user cancels the quick pick.
500+
return await askForLanguage(cliServer, false);
501+
}
502+
503+
504+
export async function askForLanguage(cliServer: CodeQLCliServer, throwOnEmpty = true): Promise<string | undefined> {
505+
const availableLanguages = Object.keys(await cliServer.resolveLanguages()).sort();
498506
const language = await Window.showQuickPick(
499507
availableLanguages,
500508
{ placeHolder: 'Select target language for your query', ignoreFocusOut: true }
501509
);
502510
if (!language) {
503511
// This only happens if the user cancels the quick pick.
504-
void showAndLogErrorMessage('Language not found. Language must be specified manually.');
512+
if (throwOnEmpty) {
513+
throw new UserCancellationException('Cancelled.');
514+
} else {
515+
void showAndLogErrorMessage('Language not found. Language must be specified manually.');
516+
}
505517
}
506518
return language;
507519
}

extensions/ql-vscode/src/quick-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export async function displayQuickQuery(
118118
// Only rewrite the qlpack file if the database has changed
119119
if (shouldRewrite) {
120120
const quickQueryQlpackYaml: any = {
121-
name: 'quick-query',
121+
name: 'vscode/quick-query',
122122
version: '1.0.0',
123123
libraryPathDependencies: [qlpack]
124124
};

0 commit comments

Comments
 (0)