Skip to content

Commit ced9f60

Browse files
Add documentation
1 parent c0a65c9 commit ced9f60

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/codeql/queries/unique-command-use.ql

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,34 @@
66
* @description Using each VS Code command from only one location makes
77
* our telemtry more useful because we can differentiate more user
88
* interactions and know which features of the UI 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 commnad 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.
916
*/
1017

1118
import javascript
1219

20+
/**
21+
* The name of a VS Code command.
22+
*/
1323
class CommandName extends string {
1424
CommandName() { exists(CommandUsage e | e.getCommandName() = this) }
1525

26+
/**
27+
* In how many ways is this command used. Will always be at least 1.
28+
*/
1629
int getNumberOfUsages() { result = count(CommandUsage e | e.getCommandName() = this | e) }
1730

31+
/**
32+
* Get the canonical first usage of this command, to use for the location
33+
* of the alert. The implementation of this ordering of usages is arbitrary
34+
* and the usage given may not be the one that should be changed when fixing
35+
* the alert.
36+
*/
1837
CommandUsage getFirstUsage() {
1938
result.getCommandName() = this and
2039
forall(CommandUsage e | e.getCommandName() = this |
@@ -23,16 +42,27 @@
2342
}
2443
}
2544

45+
/**
46+
* Represents a single usage of a command, either from within code or
47+
* from the command's definition in package.json
48+
*/
2649
abstract class CommandUsage extends Locatable {
2750
abstract string getCommandName();
2851

52+
/**
53+
* Used as a way of ordering locations. The implementation is basically
54+
* arbitrary, so long as the ordering is consistent across analyses.
55+
*/
2956
string getLocationOrdinal() {
3057
result =
3158
this.getFile().getRelativePath() + ":" + this.getLocation().getStartLine() + ":" +
3259
this.getLocation().getStartColumn()
3360
}
3461
}
3562

63+
/**
64+
* A usage of a command from the typescript code, by calling `executeCommand`.
65+
*/
3666
class CommandUsageCallExpr extends CommandUsage, CallExpr {
3767
CommandUsageCallExpr() {
3868
this.getCalleeName() = "executeCommand" and
@@ -43,6 +73,11 @@
4373
override string getCommandName() { result = this.getArgument(0).(StringLiteral).getValue() }
4474
}
4575

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 a
79+
* something like a menu or a dropdown.
80+
*/
4681
class CommandUsagePackageJsonMenuItem extends CommandUsage, JsonObject {
4782
CommandUsagePackageJsonMenuItem() {
4883
exists(this.getPropValue("command")) and
@@ -59,6 +94,10 @@
5994
override string getCommandName() { result = this.getPropValue("command").getStringValue() }
6095
}
6196

97+
/**
98+
* Is the given command disabled for use in the command palette by
99+
* a block with a `"when": "false"` field.
100+
*/
62101
predicate isDisabledInCommandPalette(string commandName) {
63102
exists(PackageJson packageJson, JsonObject commandPaletteObject |
64103
packageJson
@@ -71,6 +110,10 @@
71110
)
72111
}
73112

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+
*/
74117
class CommandUsagePackageJsonCommandPalette extends CommandUsage, JsonObject {
75118
CommandUsagePackageJsonCommandPalette() {
76119
this.getFile().getBaseName() = "package.json" and

0 commit comments

Comments
 (0)