Skip to content

Commit f57bfb6

Browse files
committed
Add support for typed commands to CodeQL query
This adds support for detecting the `CommandManager.execute` method in the unique command use query. This may not be the best way to implement this. There's a method `hasUnderlyingType` on `this.getReceiver().getType()`, but I couldn't really figure out how to get it recognize `CommandManager`. It might be possible if we can construct the type of `CommandManager`, but this will probably include the filepath to the `CommandManager` class, which might not neccessarily be something we want: moving the `CommandManager` class should not require updating the query. I'm very happy to hear other suggestions.
1 parent 96c9a4a commit f57bfb6

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@
7272

7373
override string getCommandName() { result = this.getArgument(0).(StringLiteral).getValue() }
7474
}
75+
76+
/**
77+
* A usage of a command from the typescript code, by calling `CommandManager.execute`.
78+
*/
79+
class CommandUsageCommandManagerMethodCallExpr extends CommandUsage, MethodCallExpr {
80+
CommandUsageCommandManagerMethodCallExpr() {
81+
this.getCalleeName() = "execute" and
82+
this.getReceiver().getType().unfold().(TypeReference).getTypeName().getName() = "CommandManager" and
83+
this.getArgument(0).(StringLiteral).getValue().matches("%codeQL%") and
84+
not this.getFile().getRelativePath().matches("extensions/ql-vscode/test/%")
85+
}
86+
87+
override string getCommandName() { result = this.getArgument(0).(StringLiteral).getValue() }
88+
}
7589

7690
/**
7791
* A usage of a command from any menu that isn't the command palette.

0 commit comments

Comments
 (0)