Skip to content

Commit d6d0825

Browse files
committed
Merge branch 'main' into aeisenberg/remote-history-label-editing
2 parents 800c9e0 + a1bc7eb commit d6d0825

22 files changed

Lines changed: 1175 additions & 68 deletions

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,11 @@ jobs:
147147
If this was an authentication problem, please make sure the \
148148
auth token hasn't expired."
149149
150-
# TODO This job is currently broken and is blocked on https://github.com/github/vscode-codeql/issues/1085
151150
open-vsx-publish:
152151
name: Publish to Open VSX Registry
153152
needs: build
154153
environment: publish-open-vsx
155154
runs-on: ubuntu-latest
156-
if: 1 == 0
157155
env:
158156
OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
159157
steps:

extensions/ql-vscode/CHANGELOG.md

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

33
## [UNRELEASED]
44

5+
- Re-enable publishing to open-vsx. [#1285](https://github.com/github/vscode-codeql/pull/1285)
6+
57
## 1.6.4 - 6 April 2022
68

79
No user facing changes.

extensions/ql-vscode/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"Programming Languages"
2222
],
2323
"extensionDependencies": [
24-
"hbenl.vscode-test-explorer",
25-
"ms-vscode.test-adapter-converter"
24+
"hbenl.vscode-test-explorer"
2625
],
2726
"capabilities": {
2827
"untrustedWorkspaces": {
@@ -1222,7 +1221,7 @@
12221221
}
12231222
},
12241223
"lint-staged": {
1225-
"./**/*.{json,css,scss,md}": [
1224+
"./**/*.{json,css,scss}": [
12261225
"prettier --write"
12271226
],
12281227
"./**/*.{ts,tsx}": [

extensions/ql-vscode/src/authentication.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const GITHUB_AUTH_PROVIDER_ID = 'github';
77
// https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps
88
const SCOPES = ['repo'];
99

10-
/**
10+
/**
1111
* Handles authentication to GitHub, using the VS Code [authentication API](https://code.visualstudio.com/api/references/vscode-api#authentication).
1212
*/
1313
export class Credentials {
@@ -18,6 +18,15 @@ export class Credentials {
1818
// eslint-disable-next-line @typescript-eslint/no-empty-function
1919
private constructor() { }
2020

21+
/**
22+
* Initializes an instance of credentials with an octokit instance.
23+
*
24+
* Do not call this method until you know you actually need an instance of credentials.
25+
* since calling this method will require the user to log in.
26+
*
27+
* @param context The extension context.
28+
* @returns An instance of credentials.
29+
*/
2130
static async initialize(context: vscode.ExtensionContext): Promise<Credentials> {
2231
const c = new Credentials();
2332
c.registerListeners(context);

extensions/ql-vscode/src/cli.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,11 @@ export class CodeQLCliServer implements Disposable {
667667

668668
/**
669669
* Generate a summary of an evaluation log.
670-
* @param endSummaryPath The path to write only the end of query part of the human-readable summary to.
670+
* @param endSummaryPath The path to write only the end of query part of the human-readable summary to.
671671
* @param inputPath The path of an evaluation event log.
672672
* @param outputPath The path to write a human-readable summary of it to.
673673
*/
674-
async generateLogSummary(
674+
async generateLogSummary(
675675
inputPath: string,
676676
outputPath: string,
677677
endSummaryPath: string,
@@ -1255,7 +1255,7 @@ export class CliVersionConstraint {
12551255
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer('2.7.1');
12561256

12571257
/**
1258-
* CLI version where remote queries are supported.
1258+
* CLI version where remote queries (variant analysis) are supported.
12591259
*/
12601260
public static CLI_VERSION_REMOTE_QUERIES = new SemVer('2.6.3');
12611261

@@ -1280,16 +1280,16 @@ export class CliVersionConstraint {
12801280
*/
12811281
public static CLI_VERSION_WITH_STRUCTURED_EVAL_LOG = new SemVer('2.8.2');
12821282

1283-
/**
1284-
* CLI version that supports rotating structured logs to produce one per query.
1285-
*
1286-
* Note that 2.8.4 supports generating the evaluation logs and summaries,
1287-
* but 2.9.0 includes a new option to produce the end-of-query summary logs to
1288-
* the query server console. For simplicity we gate all features behind 2.9.0,
1289-
* but if a user is tied to the 2.8 release, we can enable evaluator logs
1290-
* and summaries for them.
1291-
*/
1292-
public static CLI_VERSION_WITH_PER_QUERY_EVAL_LOG = new SemVer('2.9.0');
1283+
/**
1284+
* CLI version that supports rotating structured logs to produce one per query.
1285+
*
1286+
* Note that 2.8.4 supports generating the evaluation logs and summaries,
1287+
* but 2.9.0 includes a new option to produce the end-of-query summary logs to
1288+
* the query server console. For simplicity we gate all features behind 2.9.0,
1289+
* but if a user is tied to the 2.8 release, we can enable evaluator logs
1290+
* and summaries for them.
1291+
*/
1292+
public static CLI_VERSION_WITH_PER_QUERY_EVAL_LOG = new SemVer('2.9.0');
12931293

12941294
constructor(private readonly cli: CodeQLCliServer) {
12951295
/**/

extensions/ql-vscode/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export function isCanary() {
322322
*/
323323
export const NO_CACHE_AST_VIEWER = new Setting('disableCache', AST_VIEWER_SETTING);
324324

325-
// Settings for remote queries
325+
// Settings for variant analysis
326326
const REMOTE_QUERIES_SETTING = new Setting('variantAnalysis', ROOT_SETTING);
327327

328328
/**

extensions/ql-vscode/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ async function activateWithInstalledDistribution(
843843
)
844844
);
845845

846-
void logger.log('Initializing remote queries interface.');
846+
void logger.log('Initializing variant analysis results view.');
847847
const rqm = new RemoteQueriesManager(ctx, cliServer, qhm, queryStorageDir, logger);
848848
ctx.subscriptions.push(rqm);
849849

@@ -873,7 +873,7 @@ async function activateWithInstalledDistribution(
873873
token
874874
);
875875
} else {
876-
throw new Error('Remote queries require the CodeQL Canary version to run.');
876+
throw new Error('Variant analysis requires the CodeQL Canary version to run.');
877877
}
878878
}, {
879879
title: 'Run Variant Analysis',

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Sarif from 'sarif';
2+
import { HighlightedRegion } from '../remote-queries/shared/analysis-result';
23
import { ResolvableLocationValue } from './bqrs-cli-types';
34

45
export interface SarifLink {
@@ -173,3 +174,65 @@ export function parseSarifRegion(
173174
export function isNoLocation(loc: ParsedSarifLocation): loc is NoLocation {
174175
return 'hint' in loc;
175176
}
177+
178+
// Some helpers for highlighting specific regions from a SARIF code snippet
179+
180+
/**
181+
* Checks whether a particular line (determined by its line number in the original file)
182+
* is part of the highlighted region of a SARIF code snippet.
183+
*/
184+
export function shouldHighlightLine(
185+
lineNumber: number,
186+
highlightedRegion: HighlightedRegion
187+
): boolean {
188+
if (lineNumber < highlightedRegion.startLine) {
189+
return false;
190+
}
191+
192+
if (highlightedRegion.endLine == undefined) {
193+
return lineNumber == highlightedRegion.startLine;
194+
}
195+
196+
return lineNumber <= highlightedRegion.endLine;
197+
}
198+
199+
/**
200+
* A line of code split into: plain text before the highlighted section, the highlighted
201+
* text itself, and plain text after the highlighted section.
202+
*/
203+
export interface PartiallyHighlightedLine {
204+
plainSection1: string;
205+
highlightedSection: string;
206+
plainSection2: string;
207+
}
208+
209+
/**
210+
* Splits a line of code into the highlighted and non-highlighted sections.
211+
*/
212+
export function parseHighlightedLine(
213+
line: string,
214+
lineNumber: number,
215+
highlightedRegion: HighlightedRegion
216+
): PartiallyHighlightedLine {
217+
const isSingleLineHighlight = highlightedRegion.endLine === undefined;
218+
const isFirstHighlightedLine = lineNumber === highlightedRegion.startLine;
219+
const isLastHighlightedLine = lineNumber === highlightedRegion.endLine;
220+
221+
const highlightStartColumn = isSingleLineHighlight
222+
? highlightedRegion.startColumn
223+
: isFirstHighlightedLine
224+
? highlightedRegion.startColumn
225+
: 0;
226+
227+
const highlightEndColumn = isSingleLineHighlight
228+
? highlightedRegion.endColumn
229+
: isLastHighlightedLine
230+
? highlightedRegion.endColumn
231+
: line.length + 1;
232+
233+
const plainSection1 = line.substring(0, highlightStartColumn - 1);
234+
const highlightedSection = line.substring(highlightStartColumn - 1, highlightEndColumn - 1);
235+
const plainSection2 = line.substring(highlightEndColumn - 1, line.length);
236+
237+
return { plainSection1, highlightedSection, plainSection2 };
238+
}

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import { slurpQueryHistory, splatQueryHistory } from './query-serialization';
3737
import * as fs from 'fs-extra';
3838
import { CliVersionConstraint } from './cli';
3939
import { HistoryItemLabelProvider } from './history-item-label-provider';
40+
import { Credentials } from './authentication';
41+
import { cancelRemoteQuery } from './remote-queries/gh-actions-api-client';
4042

4143
/**
4244
* query-history.ts
@@ -320,7 +322,7 @@ export class QueryHistoryManager extends DisposableObject {
320322
private readonly qs: QueryServerClient,
321323
private readonly dbm: DatabaseManager,
322324
private readonly queryStorageDir: string,
323-
ctx: ExtensionContext,
325+
private readonly ctx: ExtensionContext,
324326
private readonly queryHistoryConfigListener: QueryHistoryConfig,
325327
private readonly labelProvider: HistoryItemLabelProvider,
326328
private readonly doCompareCallback: (
@@ -518,6 +520,10 @@ export class QueryHistoryManager extends DisposableObject {
518520
this.registerQueryHistoryScrubber(queryHistoryConfigListener, ctx);
519521
}
520522

523+
private getCredentials() {
524+
return Credentials.initialize(this.ctx);
525+
}
526+
521527
/**
522528
* Register and create the history scrubber.
523529
*/
@@ -836,11 +842,20 @@ export class QueryHistoryManager extends DisposableObject {
836842
// In the future, we may support cancelling remote queries, but this is not a short term plan.
837843
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
838844

839-
(finalMultiSelect || [finalSingleItem]).forEach((item) => {
840-
if (item.status === QueryStatus.InProgress && item.t === 'local') {
841-
item.cancel();
845+
const selected = finalMultiSelect || [finalSingleItem];
846+
const results = selected.map(async item => {
847+
if (item.status === QueryStatus.InProgress) {
848+
if (item.t === 'local') {
849+
item.cancel();
850+
} else if (item.t === 'remote') {
851+
void showAndLogInformationMessage('Cancelling variant analysis. This may take a while.');
852+
const credentials = await this.getCredentials();
853+
await cancelRemoteQuery(credentials, item.remoteQuery);
854+
}
842855
}
843856
});
857+
858+
await Promise.all(results);
844859
}
845860

846861
async handleShowQueryText(

extensions/ql-vscode/src/remote-queries/gh-actions-api-client.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ export async function getRemoteQueryIndex(
7474
};
7575
}
7676

77+
export async function cancelRemoteQuery(
78+
credentials: Credentials,
79+
remoteQuery: RemoteQuery
80+
): Promise<void> {
81+
const octokit = await credentials.getOctokit();
82+
const { actionsWorkflowRunId, controllerRepository: { owner, name } } = remoteQuery;
83+
const response = await octokit.request(`POST /repos/${owner}/${name}/actions/runs/${actionsWorkflowRunId}/cancel`);
84+
if (response.status >= 300) {
85+
throw new Error(`Error cancelling variant analysis: ${response.status} ${response?.data?.message || ''}`);
86+
}
87+
}
88+
7789
export async function downloadArtifactFromLink(
7890
credentials: Credentials,
7991
storagePath: string,

0 commit comments

Comments
 (0)