Skip to content

Commit 759cfc9

Browse files
committed
Merge branch 'aeisenberg/command-runner-refactor' into aeisenberg/telemetry
2 parents 89a809f + deb471c commit 759cfc9

42 files changed

Lines changed: 671 additions & 339 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,11 @@ jobs:
128128
version: ['v2.2.6', 'v2.3.3', 'v2.4.0']
129129
env:
130130
CLI_VERSION: ${{ matrix.version }}
131+
TEST_CODEQL_PATH: '${{ github.workspace }}/codeql'
131132

132133
steps:
133134
- name: Checkout
134135
uses: actions/checkout@v2
135-
with:
136-
fetch-depth: 1
137136

138137
- uses: actions/setup-node@v1
139138
with:
@@ -151,6 +150,12 @@ jobs:
151150
npm run build
152151
shell: bash
153152

153+
- name: Checkout QL
154+
uses: actions/checkout@v2
155+
with:
156+
repository: github/codeql
157+
path: codeql
158+
154159
- name: Run CLI tests (Linux)
155160
working-directory: extensions/ql-vscode
156161
if: matrix.os == 'ubuntu-latest'

.github/workflows/release.yml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Install dependencies
3232
run: |
3333
cd extensions/ql-vscode
34-
npm install
34+
npm ci
3535
shell: bash
3636

3737
- name: Build
@@ -57,8 +57,6 @@ jobs:
5757
REF_NAME="$(echo ${{ github.ref }} | sed -e 's:^refs/tags/::' | sed -e 's:/:-:g')"
5858
echo "::set-output name=ref_name::$REF_NAME"
5959
60-
# Uploading artifacts is not necessary to create a release.
61-
# This is just in case the release itself fails and we want to access the built artifacts from Actions.
6260
- name: Upload artifacts
6361
uses: actions/upload-artifact@v2
6462
with:
@@ -139,3 +137,40 @@ jobs:
139137
body: This PR was automatically generated by the GitHub Actions release workflow in this repository.
140138
branch: ${{ format('version/bump-to-{0}', steps.bump-patch-version.outputs.next_version) }}
141139
base: main
140+
141+
vscode-publish:
142+
name: Publish to VS Code Marketplace
143+
needs: build
144+
environment: publish-vscode-marketplace
145+
runs-on: ubuntu-latest
146+
env:
147+
VSCE_TOKEN: ${{ secrets.VSCE_TOKEN }}
148+
steps:
149+
- name: Download artifact
150+
uses: actions/download-artifact@v2
151+
with:
152+
name: vscode-codeql-extension
153+
154+
- name: Publish to Registry
155+
run: |
156+
npx vsce publish -p $VSCE_TOKEN --packagePath *.vsix || \
157+
echo "Failed to publish to VS Code Marketplace. \
158+
If this was an authentication problem, please make sure the \
159+
auth token hasn't expired."
160+
161+
open-vsx-publish:
162+
name: Publish to Open VSX Registry
163+
needs: build
164+
environment: publish-open-vsx
165+
runs-on: ubuntu-latest
166+
env:
167+
OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
168+
steps:
169+
- name: Download artifact
170+
uses: actions/download-artifact@v2
171+
with:
172+
name: vscode-codeql-extension
173+
174+
- name: Publish to Registry
175+
run: |
176+
npx ovsx publish -p $OPEN_VSX_TOKEN *.vsix

.vscode/launch.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"request": "launch",
99
"runtimeExecutable": "${execPath}",
1010
"args": [
11-
"--extensionDevelopmentPath=${workspaceRoot}/extensions/ql-vscode"
11+
"--extensionDevelopmentPath=${workspaceRoot}/extensions/ql-vscode",
12+
// Add a reference to a workspace to open. Eg-
13+
// "${workspaceRoot}/../vscode-codeql-starter/vscode-codeql-starter.code-workspace"
1214
],
1315
"stopOnEntry": false,
1416
"sourceMaps": true,
@@ -86,7 +88,7 @@
8688
"args": [
8789
"--extensionDevelopmentPath=${workspaceRoot}/extensions/ql-vscode",
8890
"--extensionTestsPath=${workspaceRoot}/extensions/ql-vscode/out/vscode-tests/cli-integration/index",
89-
"${workspaceRoot}/extensions/ql-vscode/test/data"
91+
"${workspaceRoot}/extensions/ql-vscode/src/vscode-tests/cli-integration/data",
9092
],
9193
"stopOnEntry": false,
9294
"sourceMaps": true,

CONTRIBUTING.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,32 @@ Alternatively, you can run the tests inside of vscode. There are several vscode
114114
1. Download the VSIX from the draft GitHub release at the top of [the releases page](https://github.com/github/vscode-codeql/releases) that is created when the release build finishes.
115115
1. Unzip the `.vsix` and inspect its `package.json` to make sure the version is what you expect,
116116
or look at the source if there's any doubt the right code is being shipped.
117-
1. Log into the [Visual Studio Marketplace](https://marketplace.visualstudio.com/manage/publishers/github).
118-
1. Click the `...` menu in the CodeQL row and click **Update**.
119-
1. Drag the `.vsix` file you downloaded from the GitHub release into the Marketplace and click **Upload**.
120-
1. Go to the draft GitHub release, click 'Edit', add some summary description, and publish it.
117+
1. Go to the actions tab of the vscode-codeql repository and select the [Release workflow](https://github.com/github/vscode-codeql/actions?query=workflow%3ARelease).
118+
- If there is an authentication failure when publishing, be sure to check that the authentication keys haven't expired. See below.
119+
1. Approve the deployments of the correct Release workflow. This will automatically publish to Open VSX and VS Code Marketplace.
120+
1. Go to the draft GitHub release in [the releases tab of the repository](https://github.com/github/vscode-codeql/releases), click 'Edit', add some summary description, and publish it.
121121
1. Confirm the new release is marked as the latest release at <https://github.com/github/vscode-codeql/releases>.
122122
1. If documentation changes need to be published, notify documentation team that release has been made.
123123
1. Review and merge the version bump PR that is automatically created by Actions.
124124

125+
## Secrets and authentication for publishing
126+
127+
Repository administrators, will need to manage the authentication keys for publishing to the VS Code marketplace and Open VSX. Each requires an authentication token. The VS Code marketplace token expires yearly.
128+
129+
To regenerate the Open VSX token:
130+
131+
1. Log in to the [user settings page on Open VSX](https://open-vsx.org/user-settings/namespaces).
132+
1. Make sure you are a member of the GitHub namespace.
133+
1. Go to the [Access Tokens](https://open-vsx.org/user-settings/tokens) page and generate a new token.
134+
1. Update the secret in the `publish-open-vsx` environment in the project settings.
135+
136+
To regenerate the VSCode Marketplace token:
137+
138+
1. Follow the instructions on [getting a PAT for Azure DevOps](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#get-a-personal-access-token).
139+
1. Update the secret in the `publish-vscode-marketplace` environment in the project settings.
140+
141+
Not that Azure DevOps PATs expire yearly and must be regenerated.
142+
125143
## Resources
126144

127145
* [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)

extensions/ql-vscode/CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
## [UNRELEASED]
44

5-
- Ensure databases are unlocked when removing them from the workspace. This will ensure that after a database is removed from VS Code, queries can be run on it from the command line without restarting VS Code. Requires CodeQL CLI 2.4.1 or later. [#681](https://github.com/github/vscode-codeql/pull/681)
6-
- Fix bug when removing databases where sometimes the source folder would not be removed from the workspace or the database files would not be removed from the workspace storage location. [#692](https://github.com/github/vscode-codeql/pull/692)
5+
## 1.3.8 - 17 December 2020
6+
7+
- Ensure databases are unlocked when removing them from the workspace. This will ensure that after a database is removed from VS Code, queries can be run on it from the command line without restarting the IDE. Requires CodeQL CLI 2.4.1 or later. [#681](https://github.com/github/vscode-codeql/pull/681)
8+
- Fix bug when removing databases where sometimes the source folder would not also be removed from the workspace or the database files would not be deleted from the workspace storage location. [#692](https://github.com/github/vscode-codeql/pull/692)
79
- Query results with no string representation will now be displayed with placeholder text in query results. Previously, they were omitted. [#694](https://github.com/github/vscode-codeql/pull/694)
810
- Add a label for the language of a database in the databases view. This will only take effect for new databases created with the CodeQL CLI v2.4.1 or later. [#697](https://github.com/github/vscode-codeql/pull/697)
911
- Add clearer error message when running a query using a missing or invalid qlpack. [#702](https://github.com/github/vscode-codeql/pull/702)
1012
- Add clearer error message when trying to run a command from the query history view if no item in the history is selected. [#702](https://github.com/github/vscode-codeql/pull/702)
1113
- Fix a bug where it is not possible to download some database archives. This fix specifically addresses large archives and archives whose central directories do not align with file headers. [#700](https://github.com/github/vscode-codeql/pull/700)
14+
- Avoid error dialogs when QL test discovery or database cleanup encounters a missing directory. [#706](https://github.com/github/vscode-codeql/pull/706)
15+
- Add descriptive text and a link in the results view. [#711](https://github.com/github/vscode-codeql/pull/711)
16+
- Fix the _Set Label_ command in the query history view. [#710](https://github.com/github/vscode-codeql/pull/710)
17+
- Add the _CodeQL: View AST_ command to the right-click context menu when a source file in a database source archive is open in the editor. [#712](https://github.com/github/vscode-codeql/pull/712)
1218

1319
## 1.3.7 - 24 November 2020
1420

extensions/ql-vscode/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "CodeQL for Visual Studio Code",
55
"author": "GitHub",
66
"private": true,
7-
"version": "1.3.8",
7+
"version": "1.3.9",
88
"publisher": "GitHub",
99
"license": "MIT",
1010
"icon": "media/VS-marketplace-CodeQL-icon.png",
@@ -539,7 +539,8 @@
539539
},
540540
{
541541
"command": "codeQL.runQueries",
542-
"group": "9_qlCommands"
542+
"group": "9_qlCommands",
543+
"when": "resourceScheme != codeql-zip-archive"
543544
}
544545
],
545546
"commandPalette": [
@@ -669,6 +670,10 @@
669670
"command": "codeQL.runQuery",
670671
"when": "editorLangId == ql && resourceExtname == .ql"
671672
},
673+
{
674+
"command": "codeQL.viewAst",
675+
"when": "resourceScheme == codeql-zip-archive"
676+
},
672677
{
673678
"command": "codeQL.quickEval",
674679
"when": "editorLangId == ql"
@@ -755,7 +760,7 @@
755760
"@types/chai-as-promised": "~7.1.2",
756761
"@types/child-process-promise": "^2.2.1",
757762
"@types/classnames": "~2.2.9",
758-
"@types/fs-extra": "^9.0.3",
763+
"@types/fs-extra": "^9.0.6",
759764
"@types/glob": "^7.1.1",
760765
"@types/google-protobuf": "^3.2.7",
761766
"@types/gulp": "^4.0.6",

extensions/ql-vscode/src/cli.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,15 @@ export class CodeQLCliServer implements Disposable {
144144
/** Path to current codeQL executable, or undefined if not running yet. */
145145
codeQlPath: string | undefined;
146146

147+
/**
148+
* When set to true, ignore some modal popups and assume user has clicked "yes".
149+
*/
150+
public quiet = false;
151+
147152
constructor(
148153
private distributionProvider: DistributionProvider,
149154
private cliConfig: CliConfig,
150-
private logger: Logger,
155+
private logger: Logger
151156
) {
152157
this.commandQueue = [];
153158
this.commandInProcess = false;

extensions/ql-vscode/src/commandRunner.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,16 @@ export function commandRunner(
122122
return await task(...args);
123123
} catch (e) {
124124
error = e;
125+
const errorMessage = `${e.message || e} (${commandId})`;
125126
if (e instanceof UserCancellationException) {
126127
// User has cancelled this action manually
127128
if (e.silent) {
128-
logger.log(e.message);
129+
logger.log(errorMessage);
129130
} else {
130-
showAndLogWarningMessage(e.message);
131+
showAndLogWarningMessage(errorMessage);
131132
}
132133
} else {
133-
showAndLogErrorMessage(e.message || e);
134+
showAndLogErrorMessage(errorMessage);
134135
}
135136
return undefined;
136137
} finally {
@@ -166,15 +167,16 @@ export function commandRunnerWithProgress<R>(
166167
return await withProgress(progressOptionsWithDefaults, task, ...args);
167168
} catch (e) {
168169
error = e;
170+
const errorMessage = `${e.message || e} (${commandId})`;
169171
if (e instanceof UserCancellationException) {
170172
// User has cancelled this action manually
171173
if (e.silent) {
172-
logger.log(e.message);
174+
logger.log(errorMessage);
173175
} else {
174-
showAndLogWarningMessage(e.message);
176+
showAndLogWarningMessage(errorMessage);
175177
}
176178
} else {
177-
showAndLogErrorMessage(e.message || e);
179+
showAndLogErrorMessage(errorMessage);
178180
}
179181
return undefined;
180182
} finally {
@@ -183,3 +185,45 @@ export function commandRunnerWithProgress<R>(
183185
}
184186
});
185187
}
188+
189+
/**
190+
* Displays a progress monitor that indicates how much progess has been made
191+
* reading from a stream.
192+
*
193+
* @param readable The stream to read progress from
194+
* @param messagePrefix A prefix for displaying the message
195+
* @param totalNumBytes Total number of bytes in this stream
196+
* @param progress The progress callback used to set messages
197+
*/
198+
export function reportStreamProgress(
199+
readable: NodeJS.ReadableStream,
200+
messagePrefix: string,
201+
totalNumBytes?: number,
202+
progress?: ProgressCallback
203+
) {
204+
if (progress && totalNumBytes) {
205+
let numBytesDownloaded = 0;
206+
const bytesToDisplayMB = (numBytes: number): string => `${(numBytes / (1024 * 1024)).toFixed(1)} MB`;
207+
const updateProgress = () => {
208+
progress({
209+
step: numBytesDownloaded,
210+
maxStep: totalNumBytes,
211+
message: `${messagePrefix} [${bytesToDisplayMB(numBytesDownloaded)} of ${bytesToDisplayMB(totalNumBytes)}]`,
212+
});
213+
};
214+
215+
// Display the progress straight away rather than waiting for the first chunk.
216+
updateProgress();
217+
218+
readable.on('data', data => {
219+
numBytesDownloaded += data.length;
220+
updateProgress();
221+
});
222+
} else if (progress) {
223+
progress({
224+
step: 1,
225+
maxStep: 2,
226+
message: `${messagePrefix} (Size unknown)`,
227+
});
228+
}
229+
}

extensions/ql-vscode/src/contextual/templateProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as vscode from 'vscode';
22

33
import { decodeSourceArchiveUri, encodeArchiveBasePath, zipArchiveScheme } from '../archive-filesystem-provider';
44
import { CodeQLCliServer } from '../cli';
5-
import { ProgressCallback, withProgress } from '../commandRunner';
65
import { DatabaseManager } from '../databases';
76
import { CachedOperation } from '../helpers';
7+
import { ProgressCallback, withProgress } from '../commandRunner';
88
import * as messages from '../pure/messages';
99
import { QueryServerClient } from '../queryserver-client';
1010
import { compileAndRunQueryAgainstDatabase, QueryWithResults } from '../run-queries';

0 commit comments

Comments
 (0)