Skip to content

Commit e07208b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into aeisenberg/run-with-all-data-extensions
2 parents 5843c40 + 22aa77f commit e07208b

249 files changed

Lines changed: 4569 additions & 3581 deletions

File tree

Some content is hidden

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

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CHANGELOG.md merge=union
2222

2323
# Mark some JSON files containing test data as generated so they are not included
2424
# as part of diffs or language statistics.
25-
extensions/ql-vscode/src/stories/remote-queries/data/*.json linguist-generated
25+
extensions/ql-vscode/src/stories/variant-analysis/data/*.json linguist-generated
2626

2727
# Always use LF line endings, also on Windows
2828
* text=auto eol=lf
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/**
2+
* @name A VS Code command should not be used in multiple locations
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id vscode-codeql/unique-command-use
6+
* @description Using each VS Code command from only one location makes
7+
* our telemetry more useful, because we can differentiate more user
8+
* interactions and know which features of the UI our users are using.
9+
* To fix this alert, new commands will need to be made so that each one
10+
* is only used from one location. The commands should share the same
11+
* implementation so we do not introduce duplicate code.
12+
* When fixing this alert, search the codebase for all other references
13+
* to the command name. The location of the alert is an arbitrarily
14+
* chosen usage of the command, and may not necessarily be the location
15+
* that should be changed to fix the alert.
16+
*/
17+
18+
import javascript
19+
20+
/**
21+
* The name of a VS Code command.
22+
*/
23+
class CommandName extends string {
24+
CommandName() { exists(CommandUsage e | e.getCommandName() = this) }
25+
26+
/**
27+
* In how many ways is this command used. Will always be at least 1.
28+
*/
29+
int getNumberOfUsages() { result = count(this.getAUse()) }
30+
31+
/**
32+
* Get a usage of this command.
33+
*/
34+
CommandUsage getAUse() { result.getCommandName() = this }
35+
36+
/**
37+
* Get the canonical first usage of this command, to use for the location
38+
* of the alert. The implementation of this ordering of usages is arbitrary
39+
* and the usage given may not be the one that should be changed when fixing
40+
* the alert.
41+
*/
42+
CommandUsage getFirstUsage() {
43+
result =
44+
max(CommandUsage use |
45+
use = this.getAUse()
46+
|
47+
use
48+
order by
49+
use.getFile().getRelativePath(), use.getLocation().getStartLine(),
50+
use.getLocation().getStartColumn()
51+
)
52+
}
53+
}
54+
55+
/**
56+
* Represents a single usage of a command, either from within code or
57+
* from the command's definition in package.json
58+
*/
59+
abstract class CommandUsage extends Locatable {
60+
abstract string getCommandName();
61+
}
62+
63+
/**
64+
* A usage of a command from the typescript code, by calling `executeCommand`.
65+
*/
66+
class CommandUsageCallExpr extends CommandUsage, CallExpr {
67+
CommandUsageCallExpr() {
68+
this.getCalleeName() = "executeCommand" and
69+
this.getArgument(0).(StringLiteral).getValue().matches("%codeQL%") and
70+
not this.getFile().getRelativePath().matches("extensions/ql-vscode/test/%")
71+
}
72+
73+
override string getCommandName() { result = this.getArgument(0).(StringLiteral).getValue() }
74+
}
75+
76+
/**
77+
* A usage of a command from any menu that isn't the command palette.
78+
* This means a user could invoke the command by clicking on a button in
79+
* something like a menu or a dropdown.
80+
*/
81+
class CommandUsagePackageJsonMenuItem extends CommandUsage, JsonObject {
82+
CommandUsagePackageJsonMenuItem() {
83+
exists(this.getPropValue("command")) and
84+
exists(PackageJson packageJson, string menuName |
85+
packageJson
86+
.getPropValue("contributes")
87+
.getPropValue("menus")
88+
.getPropValue(menuName)
89+
.getElementValue(_) = this and
90+
menuName != "commandPalette"
91+
)
92+
}
93+
94+
override string getCommandName() { result = this.getPropValue("command").getStringValue() }
95+
}
96+
97+
/**
98+
* Is the given command disabled for use in the command palette by
99+
* a block with a `"when": "false"` field.
100+
*/
101+
predicate isDisabledInCommandPalette(string commandName) {
102+
exists(PackageJson packageJson, JsonObject commandPaletteObject |
103+
packageJson
104+
.getPropValue("contributes")
105+
.getPropValue("menus")
106+
.getPropValue("commandPalette")
107+
.getElementValue(_) = commandPaletteObject and
108+
commandPaletteObject.getPropValue("command").getStringValue() = commandName and
109+
commandPaletteObject.getPropValue("when").getStringValue() = "false"
110+
)
111+
}
112+
113+
/**
114+
* Represents a command being usable from the command palette.
115+
* This means that a user could choose to manually invoke the command.
116+
*/
117+
class CommandUsagePackageJsonCommandPalette extends CommandUsage, JsonObject {
118+
CommandUsagePackageJsonCommandPalette() {
119+
this.getFile().getBaseName() = "package.json" and
120+
exists(this.getPropValue("command")) and
121+
exists(PackageJson packageJson |
122+
packageJson.getPropValue("contributes").getPropValue("commands").getElementValue(_) = this
123+
) and
124+
not isDisabledInCommandPalette(this.getPropValue("command").getStringValue())
125+
}
126+
127+
override string getCommandName() { result = this.getPropValue("command").getStringValue() }
128+
}
129+
130+
from CommandName c
131+
where c.getNumberOfUsages() > 1
132+
select c.getFirstUsage(),
133+
"The " + c + " command is used from " + c.getNumberOfUsages() + " locations"
134+

.github/workflows/main.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ jobs:
132132
- name: Run unit tests
133133
working-directory: extensions/ql-vscode
134134
run: |
135-
npm run test
135+
npm run test:unit
136+
137+
- name: Run view tests
138+
working-directory: extensions/ql-vscode
139+
run: |
140+
npm run test:view
136141
137142
test:
138143
name: Test
@@ -173,15 +178,15 @@ jobs:
173178
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
174179
run: |
175180
unset DBUS_SESSION_BUS_ADDRESS
176-
/usr/bin/xvfb-run npm run integration
181+
/usr/bin/xvfb-run npm run test:vscode-integration
177182
178183
- name: Run integration tests (Windows)
179184
if: matrix.os == 'windows-latest'
180185
working-directory: extensions/ql-vscode
181186
env:
182187
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
183188
run: |
184-
npm run integration
189+
npm run test:vscode-integration
185190
186191
set-matrix:
187192
name: Set Matrix for cli-test
@@ -254,10 +259,10 @@ jobs:
254259
if: matrix.os == 'ubuntu-latest'
255260
run: |
256261
unset DBUS_SESSION_BUS_ADDRESS
257-
/usr/bin/xvfb-run npm run cli-integration
262+
/usr/bin/xvfb-run npm run test:cli-integration
258263
259264
- name: Run CLI tests (Windows)
260265
working-directory: extensions/ql-vscode
261266
if: matrix.os == 'windows-latest'
262267
run: |
263-
npm run cli-integration
268+
npm run test:cli-integration

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
echo "ref_name=$REF_NAME" >> "$GITHUB_OUTPUT"
5555
5656
- name: Upload artifacts
57-
uses: actions/upload-artifact@v2
57+
uses: actions/upload-artifact@v3
5858
with:
5959
name: vscode-codeql-extension
6060
path: artifacts

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"--extensionDevelopmentPath=${workspaceRoot}/extensions/ql-vscode",
1212
// Add a reference to a workspace to open. Eg-
1313
// "${workspaceRoot}/../vscode-codeql-starter/vscode-codeql-starter.code-workspace"
14+
// "${workspaceRoot}/../codespaces-codeql/tutorial.code-workspace"
1415
],
1516
"sourceMaps": true,
1617
"outFiles": [

CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
**/* @github/codeql-vscode-reviewers
2-
**/remote-queries/ @github/code-scanning-secexp-reviewers
32
**/variant-analysis/ @github/code-scanning-secexp-reviewers
43
**/databases/ @github/code-scanning-secexp-reviewers

CONTRIBUTING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ We have several types of tests:
9898
* Unit tests: these live in the `tests/unit-tests/` directory
9999
* View tests: these live in `src/view/variant-analysis/__tests__/`
100100
* VSCode integration tests:
101-
* `test/vscode-tests/no-workspace` tests: These are intended to cover functionality that is meant to work before you even have a workspace open.
101+
* `test/vscode-tests/activated-extension` tests: These are intended to cover functionality that require the full extension to be activated but don't require the CLI. This suite is not run against multiple versions of the CLI in CI.
102+
* `test/vscode-tests/no-workspace` tests: These are intended to cover functionality around not having a workspace. The extension is not activated in these tests.
102103
* `test/vscode-tests/minimal-workspace` tests: These are intended to cover functionality that need a workspace but don't require the full extension to be activated.
103104
* CLI integration tests: these live in `test/vscode-tests/cli-integration`
104-
* These tests are intendended to be cover functionality that is related to the integration between the CodeQL CLI and the extension.
105+
* These tests are intended to cover functionality that is related to the integration between the CodeQL CLI and the extension. These tests are run against each supported versions of the CLI in CI.
105106

106107
The CLI integration tests require an instance of the CodeQL CLI to run so they will require some extra setup steps. When adding new tests to our test suite, please be mindful of whether they need to be in the cli-integration folder. If the tests don't depend on the CLI, they are better suited to being a VSCode integration test.
107108

@@ -119,7 +120,7 @@ Then, from the `extensions/ql-vscode` directory, use the appropriate command to
119120

120121
* Unit tests: `npm run test:unit`
121122
* View Tests: `npm test:view`
122-
* VSCode integration tests: `npm run integration`
123+
* VSCode integration tests: `npm run test:vscode-integration`
123124

124125
###### CLI integration tests
125126

@@ -130,7 +131,7 @@ The CLI integration tests require the CodeQL standard libraries in order to run
130131
2. Run your test command:
131132

132133
```shell
133-
cd extensions/ql-vscode && npm run cli-integration
134+
cd extensions/ql-vscode && npm run test:cli-integration
134135
```
135136

136137
##### 2. From VSCode
@@ -161,13 +162,13 @@ The easiest way to run a single test is to change the `it` of the test to `it.on
161162
to only run tests for this specific file. For example, to run the test `test/vscode-tests/cli-integration/run-queries.test.ts`:
162163

163164
```shell
164-
npm run cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts
165+
npm run test:cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts
165166
```
166167

167168
You can also use the `--testNamePattern` option to run a specific test within a file. For example, to run the test `test/vscode-tests/cli-integration/run-queries.test.ts`:
168169

169170
```shell
170-
npm run cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts --testNamePattern "should create a QueryEvaluationInfo"
171+
npm run test:cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts --testNamePattern "should create a QueryEvaluationInfo"
171172
```
172173

173174
##### 2. From VSCode

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The extension is released. You can download it from the [Visual Studio Marketpla
77
To see what has changed in the last few versions of the extension, see the [Changelog](https://github.com/github/vscode-codeql/blob/main/extensions/ql-vscode/CHANGELOG.md).
88

99
[![CI status badge](https://github.com/github/vscode-codeql/workflows/Build%20Extension/badge.svg)](https://github.com/github/vscode-codeql/actions?query=workflow%3A%22Build+Extension%22+branch%3Amaster)
10-
[![VS Marketplace badge](https://vsmarketplacebadge.apphb.com/version/github.vscode-codeql.svg)](https://marketplace.visualstudio.com/items?itemName=github.vscode-codeql)
10+
[![VS Marketplace badge](https://vsmarketplacebadges.dev/version/github.vscode-codeql.svg)](https://marketplace.visualstudio.com/items?itemName=github.vscode-codeql)
1111

1212
## Features
1313

extensions/ql-vscode/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const baseConfig = {
2929
"plugin:@typescript-eslint/recommended",
3030
],
3131
rules: {
32+
"@typescript-eslint/await-thenable": "error",
3233
"@typescript-eslint/no-use-before-define": 0,
3334
"@typescript-eslint/no-unused-vars": [
3435
"warn",

extensions/ql-vscode/CHANGELOG.md

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

33
## [UNRELEASED]
44

5+
- Send telemetry about unhandled errors happening within the extension. [#2125](https://github.com/github/vscode-codeql/pull/2125)
6+
7+
## 1.7.11 - 1 March 2023
8+
9+
- Enable collection of telemetry concerning interactions with UI elements, including buttons, links, and other inputs. [#2114](https://github.com/github/vscode-codeql/pull/2114)
10+
- Prevent the automatic installation of CodeQL CLI version 2.12.3 to avoid a bug in the language server. CodeQL CLI 2.12.2 will be used instead. [#2126](https://github.com/github/vscode-codeql/pull/2126)
11+
12+
## 1.7.10 - 23 February 2023
13+
14+
- Fix bug that was causing unwanted error notifications.
15+
16+
## 1.7.9 - 20 February 2023
17+
18+
No user facing changes.
19+
520
## 1.7.8 - 2 February 2023
621

722
- Renamed command "CodeQL: Run Query" to "CodeQL: Run Query on Selected Database". [#1962](https://github.com/github/vscode-codeql/pull/1962)

0 commit comments

Comments
 (0)