Skip to content

Commit 1e72149

Browse files
edoardopirovanoaeisenberg
authored andcommitted
Add some commonly used QL snippets
1 parent dbaed3a commit 1e72149

3 files changed

Lines changed: 141 additions & 0 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Implement sorting of the query history view by name, date, and results count. [#777](https://github.com/github/vscode-codeql/pull/777)
1010
- Add a configuration option to pass additional arguments to the CLI when running tests. [#785](https://github.com/github/vscode-codeql/pull/785)
1111
- Introduce option to view query results as CSV. [#784](https://github.com/github/vscode-codeql/pull/784)
12+
- Add some snippets for commonly used QL statements. [#780](https://github.com/github/vscode-codeql/pull/780)
1213

1314
## 1.4.3 - 22 February 2021
1415

extensions/ql-vscode/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
"path": "./out/syntaxes/dbscheme.tmLanguage.json"
107107
}
108108
],
109+
"snippets": [
110+
{
111+
"language": "ql",
112+
"path": "./snippets.json"
113+
}
114+
],
109115
"configuration": {
110116
"type": "object",
111117
"title": "CodeQL",

extensions/ql-vscode/snippets.json

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"Query Metadata": {
3+
"prefix": "querymetadata",
4+
"body": [
5+
"/**",
6+
" * @name $1",
7+
" * @description $2",
8+
" * @kind $3",
9+
" * @id $4",
10+
" * @tags $5",
11+
" */"
12+
],
13+
"description": "Metadata for a query"
14+
},
15+
"Class": {
16+
"prefix": "class",
17+
"body": ["class $1 extends $2 {", "\t$0", "}"],
18+
"description": "A class"
19+
},
20+
"From/Where/Select": {
21+
"prefix": "from",
22+
"body": ["from $1", "where $2", "select $3"],
23+
"description": "A from/where/select statement"
24+
},
25+
"Predicate": {
26+
"prefix": "predicate",
27+
"body": ["predicate $1($2) {", "\t$0", "}"],
28+
"description": "A predicate"
29+
},
30+
"Dataflow Tracking Class": {
31+
"prefix": "dataflowtracking",
32+
"body": [
33+
"class $1 extends DataFlow::Configuration {",
34+
"\t$1() { this = \"$1\" }",
35+
"\t",
36+
"\toverride predicate isSource(DataFlow::Node node) {",
37+
"\t\t${2:none()}",
38+
"\t}",
39+
"\t",
40+
"\toverride predicate isSink(DataFlow::Node node) {",
41+
"\t\t${3:none()}",
42+
"\t}",
43+
"}"
44+
],
45+
"description": "Boilerplate for a dataflow tracking class"
46+
},
47+
"Taint Tracking Class": {
48+
"prefix": "tainttracking",
49+
"body": [
50+
"class $1 extends TaintTracking::Configuration {",
51+
"\t$1() { this = \"$1\" }",
52+
"\t",
53+
"\toverride predicate isSource(DataFlow::Node node) {",
54+
"\t\t${2:none()}",
55+
"\t}",
56+
"\t",
57+
"\toverride predicate isSink(DataFlow::Node node) {",
58+
"\t\t${3:none()}",
59+
"\t}",
60+
"}"
61+
],
62+
"description": "Boilerplate for a taint tracking class"
63+
},
64+
"Count": {
65+
"prefix": "count",
66+
"body": ["count($1 | $2 | $3)"],
67+
"description": "A count aggregate"
68+
},
69+
"Max": {
70+
"prefix": "max",
71+
"body": ["max($1 | $2 | $3)"],
72+
"description": "A max aggregate"
73+
},
74+
"Min": {
75+
"prefix": "min",
76+
"body": ["min($1 | $2 | $3)"],
77+
"description": "A min aggregate"
78+
},
79+
"Average": {
80+
"prefix": "avg",
81+
"body": ["avg($1 | $2 | $3)"],
82+
"description": "An average aggregate"
83+
},
84+
"Sum": {
85+
"prefix": "sum",
86+
"body": ["sum($1 | $2 | $3)"],
87+
"description": "A sum aggregate"
88+
},
89+
"Concatenation": {
90+
"prefix": "concat",
91+
"body": ["concat($1 | $2 | $3)"],
92+
"description": "A concatenation aggregate"
93+
},
94+
"Rank": {
95+
"prefix": "rank",
96+
"body": ["rank[$1]($2 | $3 | $4)"],
97+
"description": "A rank aggregate"
98+
},
99+
"Strict Sum": {
100+
"prefix": "strictsum",
101+
"body": ["strictsum($1 | $2 | $3)"],
102+
"description": "A strict sum aggregate"
103+
},
104+
"Strict Concatenation": {
105+
"prefix": "strictconcat",
106+
"body": ["strictconcat($1 | $2 | $3)"],
107+
"description": "A strict concatenation aggregate"
108+
},
109+
"Strict Count": {
110+
"prefix": "strictcount",
111+
"body": ["strictcount($1 | $2 | $3)"],
112+
"description": "A strict count aggregate"
113+
},
114+
"Unique": {
115+
"prefix": "unique",
116+
"body": ["unique($1 | $2 | $3)"],
117+
"description": "A unique aggregate"
118+
},
119+
"Exists": {
120+
"prefix": "exists",
121+
"body": ["exists($1 | $2 | $3)"],
122+
"description": "An exists quantifier"
123+
},
124+
"For All": {
125+
"prefix": "forall",
126+
"body": ["forall($1 | $2 | $3)"],
127+
"description": "A for all quantifier"
128+
},
129+
"For All and Exists": {
130+
"prefix": "forex",
131+
"body": ["forex($1 | $2 | $3)"],
132+
"description": "A for all and exists quantifier"
133+
}
134+
}

0 commit comments

Comments
 (0)