Skip to content

Commit 9e6100f

Browse files
author
Dave Bartolomeo
committed
Merge remote-tracking branch 'upstream/master' into dbartol/QLTest
2 parents 7d325e3 + 6f4211b commit 9e6100f

6 files changed

Lines changed: 65 additions & 18 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This project is an extension for Visual Studio Code that adds rich language supp
44

55
The extension is released. You can download it from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=github.vscode-codeql).
66

7+
To see what has changed in the last few versions of the extension, see the [Changelog](https://github.com/github/vscode-codeql/blob/master/extensions/ql-vscode/CHANGELOG.md).
8+
79
![CI status badge](https://github.com/github/vscode-codeql/workflows/Build%20Extension/badge.svg)
810

911
## Features

extensions/ql-vscode/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# CodeQL for Visual Studio Code: Changelog
2+
3+
## 1.0.1 - 21 November 2019
4+
5+
- Change `codeQL.cli.executablePath` to a per-machine setting, so it can no longer be set at the user or workspace level. This helps prevent arbitrary code execution when using a VS Code workspace from an untrusted source.
6+
- Improve the highlighting of the selected query result within the source code.
7+
- Improve the performance of switching between result tables in the CodeQL Query Results view.
8+
- Fix the automatic upgrading of CodeQL databases when using upgrade scripts from the workspace.
9+
- Allow removal of items from the CodeQL Query History view.
10+
11+
12+
## 1.0.0 - 14 November 2019
13+
14+
Initial release of CodeQL for Visual Studio Code.

extensions/ql-vscode/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This project is an extension for Visual Studio Code that adds rich language supp
77
* Provides an easy way to run queries from the large, open source repository of [CodeQL security queries](https://github.com/Semmle/ql).
88
* Adds IntelliSense to support you writing and editing your own CodeQL query and library files.
99

10+
To see what has changed in the last few versions of the extension, see the [Changelog](https://github.com/github/vscode-codeql/blob/master/extensions/ql-vscode/CHANGELOG.md).
11+
1012
## Quick start overview
1113

1214
The information in this `README` file describes the quickest way to start using CodeQL.

extensions/ql-vscode/package.json

Lines changed: 2 additions & 2 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.0.1",
7+
"version": "1.0.2",
88
"publisher": "GitHub",
99
"license": "MIT",
1010
"icon": "media/VS-marketplace-CodeQL-icon.png",
@@ -86,7 +86,7 @@
8686
"title": "CodeQL",
8787
"properties": {
8888
"codeQL.cli.executablePath": {
89-
"scope": "window",
89+
"scope": "machine",
9090
"type": "string",
9191
"default": "",
9292
"description": "Path to the CodeQL executable that should be used by the CodeQL extension. The executable is named `codeql` on Linux/Mac and `codeql.cmd` on Windows. This overrides all other CodeQL CLI settings."

extensions/ql-vscode/src/config.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ const DISTRIBUTION_SETTING = new Setting('cli', ROOT_SETTING);
3737
const CUSTOM_CODEQL_PATH_SETTING = new Setting('executablePath', DISTRIBUTION_SETTING);
3838
const INCLUDE_PRERELEASE_SETTING = new Setting('includePrerelease', DISTRIBUTION_SETTING);
3939
const PERSONAL_ACCESS_TOKEN_SETTING = new Setting('personalAccessToken', DISTRIBUTION_SETTING);
40-
const OWNER_NAME_SETTING = new Setting('owner', DISTRIBUTION_SETTING);
41-
const REPOSITORY_NAME_SETTING = new Setting('repository', DISTRIBUTION_SETTING);
4240

4341
/** When these settings change, the distribution should be updated. */
44-
const DISTRIBUTION_CHANGE_SETTINGS = [CUSTOM_CODEQL_PATH_SETTING, INCLUDE_PRERELEASE_SETTING, PERSONAL_ACCESS_TOKEN_SETTING, OWNER_NAME_SETTING, REPOSITORY_NAME_SETTING];
42+
const DISTRIBUTION_CHANGE_SETTINGS = [CUSTOM_CODEQL_PATH_SETTING, INCLUDE_PRERELEASE_SETTING, PERSONAL_ACCESS_TOKEN_SETTING];
4543

4644
export interface DistributionConfig {
4745
customCodeQlPath?: string;
4846
includePrerelease: boolean;
4947
personalAccessToken?: string;
50-
ownerName: string;
51-
repositoryName: string;
48+
ownerName?: string;
49+
repositoryName?: string;
5250
onDidChangeDistributionConfiguration?: Event<void>;
5351
}
5452

@@ -114,14 +112,6 @@ export class DistributionConfigListener extends ConfigListener implements Distri
114112
return PERSONAL_ACCESS_TOKEN_SETTING.getValue() ? PERSONAL_ACCESS_TOKEN_SETTING.getValue() : undefined;
115113
}
116114

117-
public get ownerName(): string {
118-
return OWNER_NAME_SETTING.getValue();
119-
}
120-
121-
public get repositoryName(): string {
122-
return REPOSITORY_NAME_SETTING.getValue();
123-
}
124-
125115
public get onDidChangeDistributionConfiguration(): Event<void> {
126116
return this._onDidChangeConfiguration.event;
127117
}

extensions/ql-vscode/src/interface.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class InterfaceManager extends DisposableObject {
9898

9999
super();
100100
this.push(this._diagnosticCollection);
101+
this.push(vscode.window.onDidChangeTextEditorSelection(this.handleSelectionChange.bind(this)));
101102
}
102103

103104
// Returns the webview panel, creating it if it doesn't already
@@ -398,16 +399,54 @@ export class InterfaceManager extends DisposableObject {
398399
sortState: info.sortState
399400
};
400401
}
402+
403+
private handleSelectionChange(event: vscode.TextEditorSelectionChangeEvent) {
404+
if (event.kind === vscode.TextEditorSelectionChangeKind.Command) {
405+
return; // Ignore selection events we caused ourselves.
406+
}
407+
let editor = vscode.window.activeTextEditor;
408+
if (editor !== undefined) {
409+
editor.setDecorations(shownLocationDecoration, []);
410+
editor.setDecorations(shownLocationLineDecoration, []);
411+
}
412+
}
401413
}
402414

415+
const findMatchBackground = new vscode.ThemeColor('editor.findMatchBackground');
416+
const findRangeHighlightBackground = new vscode.ThemeColor('editor.findRangeHighlightBackground');
417+
418+
const shownLocationDecoration = vscode.window.createTextEditorDecorationType({
419+
backgroundColor: findMatchBackground,
420+
});
421+
422+
const shownLocationLineDecoration = vscode.window.createTextEditorDecorationType({
423+
backgroundColor: findRangeHighlightBackground,
424+
isWholeLine: true
425+
});
426+
403427
async function showLocation(loc: ResolvableLocationValue, databaseItem: DatabaseItem): Promise<void> {
404428
const resolvedLocation = tryResolveLocation(loc, databaseItem);
405429
if (resolvedLocation) {
406430
const doc = await workspace.openTextDocument(resolvedLocation.uri);
407431
const editor = await Window.showTextDocument(doc, vscode.ViewColumn.One);
408-
const sel = new vscode.Selection(resolvedLocation.range.start, resolvedLocation.range.end);
409-
editor.selection = sel;
410-
editor.revealRange(sel, vscode.TextEditorRevealType.InCenter);
432+
let range = resolvedLocation.range;
433+
// When highlighting the range, vscode's occurrence-match and bracket-match highlighting will
434+
// trigger based on where we place the cursor/selection, and will compete for the user's attention.
435+
// For reference:
436+
// - Occurences are highlighted when the cursor is next to or inside a word or a whole word is selected.
437+
// - Brackets are highlighted when the cursor is next to a bracket and there is an empty selection.
438+
// - Multi-line selections explicitly highlight line-break characters, but multi-line decorators do not.
439+
//
440+
// For single-line ranges, select the whole range, mainly to disable bracket highlighting.
441+
// For multi-line ranges, place the cursor at the beginning to avoid visual artifacts from selected line-breaks.
442+
// Multi-line ranges are usually large enough to overshadow the noise from bracket highlighting.
443+
let selectionEnd = (range.start.line === range.end.line)
444+
? range.end
445+
: range.start;
446+
editor.selection = new vscode.Selection(range.start, selectionEnd);
447+
editor.revealRange(range, vscode.TextEditorRevealType.InCenter);
448+
editor.setDecorations(shownLocationDecoration, [range]);
449+
editor.setDecorations(shownLocationLineDecoration, [range]);
411450
}
412451
}
413452

0 commit comments

Comments
 (0)