diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 9c808abe89e..f425efe592b 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -9,6 +9,7 @@ - Implement sorting of the query history view by name, date, and results count. [#777](https://github.com/github/vscode-codeql/pull/777) - Add a configuration option to pass additional arguments to the CLI when running tests. [#785](https://github.com/github/vscode-codeql/pull/785) - Introduce option to view query results as CSV. [#784](https://github.com/github/vscode-codeql/pull/784) +- Add some snippets for commonly used QL statements. [#780](https://github.com/github/vscode-codeql/pull/780) ## 1.4.3 - 22 February 2021 diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index c51b0b5ba66..d9ba7c96c1a 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -106,6 +106,12 @@ "path": "./out/syntaxes/dbscheme.tmLanguage.json" } ], + "snippets": [ + { + "language": "ql", + "path": "./snippets.json" + } + ], "configuration": { "type": "object", "title": "CodeQL", diff --git a/extensions/ql-vscode/snippets.json b/extensions/ql-vscode/snippets.json new file mode 100644 index 00000000000..5ad3f5a67fb --- /dev/null +++ b/extensions/ql-vscode/snippets.json @@ -0,0 +1,134 @@ +{ + "Query Metadata": { + "prefix": "querymetadata", + "body": [ + "/**", + " * @name $1", + " * @description $2", + " * @kind $3", + " * @id $4", + " * @tags $5", + " */" + ], + "description": "Metadata for a query" + }, + "Class": { + "prefix": "class", + "body": ["class $1 extends $2 {", "\t$0", "}"], + "description": "A class" + }, + "From/Where/Select": { + "prefix": "from", + "body": ["from $1", "where $2", "select $3"], + "description": "A from/where/select statement" + }, + "Predicate": { + "prefix": "predicate", + "body": ["predicate $1($2) {", "\t$0", "}"], + "description": "A predicate" + }, + "Dataflow Tracking Class": { + "prefix": "dataflowtracking", + "body": [ + "class $1 extends DataFlow::Configuration {", + "\t$1() { this = \"$1\" }", + "\t", + "\toverride predicate isSource(DataFlow::Node node) {", + "\t\t${2:none()}", + "\t}", + "\t", + "\toverride predicate isSink(DataFlow::Node node) {", + "\t\t${3:none()}", + "\t}", + "}" + ], + "description": "Boilerplate for a dataflow tracking class" + }, + "Taint Tracking Class": { + "prefix": "tainttracking", + "body": [ + "class $1 extends TaintTracking::Configuration {", + "\t$1() { this = \"$1\" }", + "\t", + "\toverride predicate isSource(DataFlow::Node node) {", + "\t\t${2:none()}", + "\t}", + "\t", + "\toverride predicate isSink(DataFlow::Node node) {", + "\t\t${3:none()}", + "\t}", + "}" + ], + "description": "Boilerplate for a taint tracking class" + }, + "Count": { + "prefix": "count", + "body": ["count($1 | $2 | $3)"], + "description": "A count aggregate" + }, + "Max": { + "prefix": "max", + "body": ["max($1 | $2 | $3)"], + "description": "A max aggregate" + }, + "Min": { + "prefix": "min", + "body": ["min($1 | $2 | $3)"], + "description": "A min aggregate" + }, + "Average": { + "prefix": "avg", + "body": ["avg($1 | $2 | $3)"], + "description": "An average aggregate" + }, + "Sum": { + "prefix": "sum", + "body": ["sum($1 | $2 | $3)"], + "description": "A sum aggregate" + }, + "Concatenation": { + "prefix": "concat", + "body": ["concat($1 | $2 | $3)"], + "description": "A concatenation aggregate" + }, + "Rank": { + "prefix": "rank", + "body": ["rank[$1]($2 | $3 | $4)"], + "description": "A rank aggregate" + }, + "Strict Sum": { + "prefix": "strictsum", + "body": ["strictsum($1 | $2 | $3)"], + "description": "A strict sum aggregate" + }, + "Strict Concatenation": { + "prefix": "strictconcat", + "body": ["strictconcat($1 | $2 | $3)"], + "description": "A strict concatenation aggregate" + }, + "Strict Count": { + "prefix": "strictcount", + "body": ["strictcount($1 | $2 | $3)"], + "description": "A strict count aggregate" + }, + "Unique": { + "prefix": "unique", + "body": ["unique($1 | $2 | $3)"], + "description": "A unique aggregate" + }, + "Exists": { + "prefix": "exists", + "body": ["exists($1 | $2 | $3)"], + "description": "An exists quantifier" + }, + "For All": { + "prefix": "forall", + "body": ["forall($1 | $2 | $3)"], + "description": "A for all quantifier" + }, + "For All and Exists": { + "prefix": "forex", + "body": ["forex($1 | $2 | $3)"], + "description": "A for all and exists quantifier" + } +}