From 64df792eda9121ed9f9343a1fb45583ba6340b1f Mon Sep 17 00:00:00 2001 From: Philip Ginsbach Date: Mon, 4 Sep 2023 14:27:30 +0100 Subject: [PATCH 1/5] TextMate grammar: imports can have instantiation arguments --- .../ql-vscode/syntaxes/ql.tmLanguage.yml | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml b/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml index d7f8ac071..f0d73d3d9 100644 --- a/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml +++ b/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml @@ -170,6 +170,14 @@ repository: match: '\]' name: punctuation.squarebracket.close.ql + open-angle: + match: '<' + name: punctuation.anglebracket.open.ql + + close-angle: + match: '>' + name: punctuation.anglebracket.close.ql + operator-or-punctuation: patterns: - include: '#relational-operator' @@ -186,6 +194,8 @@ repository: - include: '#close-brace' - include: '#open-bracket' - include: '#close-bracket' + - include: '#open-angle' + - include: '#close-angle' # Keywords dont-care: @@ -651,6 +661,15 @@ repository: - include: '#non-context-sensitive' - include: '#annotation' + instantiation-arguments: + beginPattern: '#open-angle' + end: '#close-angle' + patterns: + - include: '#potential-instantiation' + + potential-instantiation: + matches: '(?#simple-id) (?#instantiation-arguments)?' + # An `import` directive. Note that we parse the optional `as` clause as a separate top-level # directive, because otherwise it's too hard to figure out where the `import` directive ends. import-directive: @@ -664,7 +683,7 @@ repository: name: meta.block.import-directive.ql patterns: - include: '#non-context-sensitive' - - match: '(?#simple-id)' + - match: '(?#potential-instantiation)' name: entity.name.type.namespace.ql # The end pattern for an `as` clause, whether on an `import` directive, in an aggregate, or on a @@ -703,7 +722,6 @@ repository: - match: '(?#simple-id)|(?#at-lower-id)' name: entity.name.type.ql - # A `module` declaration, whether a module definition or an alias declaration. module-declaration: # Starts with the `module` keyword. From 599d31e5ac52b699c4b162fe40af5e60de5d2f22 Mon Sep 17 00:00:00 2001 From: Philip Ginsbach Date: Mon, 4 Sep 2023 13:49:32 +0100 Subject: [PATCH 2/5] add changelog entry for TextMate instantiation argument syntax --- extensions/ql-vscode/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index bdc2e476c..ae3226240 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -7,6 +7,7 @@ - Increase the required version of VS Code to 1.82.0. [#2877](https://github.com/github/vscode-codeql/pull/2877) - Fix a bug where the query server was restarted twice after configuration changes. [#2884](https://github.com/github/vscode-codeql/pull/2884). - Add support for the `telemetry.telemetryLevel` setting. For more information, see the [telemetry documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-telemetry-in-codeql-for-visual-studio-code). [#2824](https://github.com/github/vscode-codeql/pull/2824). +- Fixed syntax highlighting directly after import statements with instantiation arguments. ## 1.9.1 - 29 September 2023 From 353e22d6e8e5400f08b87ad6125f8553eb471ed9 Mon Sep 17 00:00:00 2001 From: Philip Ginsbach Date: Fri, 8 Sep 2023 09:50:28 +0100 Subject: [PATCH 3/5] link to the PR from the changelog entry --- extensions/ql-vscode/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index ae3226240..56c1e2a9c 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -7,7 +7,7 @@ - Increase the required version of VS Code to 1.82.0. [#2877](https://github.com/github/vscode-codeql/pull/2877) - Fix a bug where the query server was restarted twice after configuration changes. [#2884](https://github.com/github/vscode-codeql/pull/2884). - Add support for the `telemetry.telemetryLevel` setting. For more information, see the [telemetry documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-telemetry-in-codeql-for-visual-studio-code). [#2824](https://github.com/github/vscode-codeql/pull/2824). -- Fixed syntax highlighting directly after import statements with instantiation arguments. +- Fix syntax highlighting directly after import statements with instantiation arguments. [#2792](https://github.com/github/vscode-codeql/pull/2792) ## 1.9.1 - 29 September 2023 From c78f01758a635dfebc2b30e537b2778786697d8d Mon Sep 17 00:00:00 2001 From: Dave Bartolomeo Date: Mon, 25 Sep 2023 18:31:59 -0400 Subject: [PATCH 4/5] Alternate fix for import highlighting with instantiations --- .../ql-vscode/syntaxes/ql.tmLanguage.yml | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml b/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml index f0d73d3d9..fe10a86d0 100644 --- a/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml +++ b/extensions/ql-vscode/syntaxes/ql.tmLanguage.yml @@ -661,29 +661,38 @@ repository: - include: '#non-context-sensitive' - include: '#annotation' - instantiation-arguments: + # The argument list of an instantiation, enclosed in angle brackets. + instantiation-args: beginPattern: '#open-angle' - end: '#close-angle' + endPattern: '#close-angle' + name: meta.type.parameters.ql patterns: - - include: '#potential-instantiation' - - potential-instantiation: - matches: '(?#simple-id) (?#instantiation-arguments)?' + # Include `#instantiation-args` first so that `#open-angle` and `#close-angle` take precedence + # over `#relational-operator`. + - include: '#instantiation-args' + - include: '#non-context-sensitive' + - match: '(?#simple-id)' + name: entity.name.type.namespace.ql # An `import` directive. Note that we parse the optional `as` clause as a separate top-level # directive, because otherwise it's too hard to figure out where the `import` directive ends. import-directive: beginPattern: '#import' - # Ends with a simple-id that is not followed by a `.` or a `::`. This does not handle comments or - # line breaks between the simple-id and the `.` or `::`. - end: '(?#simple-id) (?!\s*(\.|\:\:))' - endCaptures: - '0': - name: entity.name.type.namespace.ql + # TextMate makes it tricky to tell whether an identifier that we encounter is part of the + # `import` directive or whether it's the first token of the next module-level declaration. + # To find the end of the import directive, we'll look for a zero-width match where the previous + # token is either an identifier (other than `import`) or a `>`, and the next token is not a `.`, + # `<`, `,`, or `::`. This works for nearly all real-world `import` directives, but it will end the + # `import` directive too early if there is a comment or line break between two components of the + # module expression. + end: '(?)|[A-Za-z0-9_]) (?!\s*(\.|\:\:|\,|(?#open-angle)))' name: meta.block.import-directive.ql patterns: + # Include `#instantiation-args` first so that `#open-angle` and `#close-angle` take precedence + # over `#relational-operator`. + - include: '#instantiation-args' - include: '#non-context-sensitive' - - match: '(?#potential-instantiation)' + - match: '(?#simple-id)' name: entity.name.type.namespace.ql # The end pattern for an `as` clause, whether on an `import` directive, in an aggregate, or on a From 47fa163cb9fffce379458962eb391c9ef9082dcb Mon Sep 17 00:00:00 2001 From: Philip Ginsbach Date: Fri, 8 Sep 2023 09:43:39 +0100 Subject: [PATCH 5/5] Update compiled grammar --- syntaxes/ql.tmLanguage.json | 63 ++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/syntaxes/ql.tmLanguage.json b/syntaxes/ql.tmLanguage.json index 66e1cc8ec..a8b5c3909 100644 --- a/syntaxes/ql.tmLanguage.json +++ b/syntaxes/ql.tmLanguage.json @@ -108,6 +108,14 @@ "match": "(?x)\\]", "name": "punctuation.squarebracket.close.ql" }, + "open-angle": { + "match": "(?x)<", + "name": "punctuation.anglebracket.open.ql" + }, + "close-angle": { + "match": "(?x)>", + "name": "punctuation.anglebracket.close.ql" + }, "operator-or-punctuation": { "patterns": [ { @@ -151,6 +159,12 @@ }, { "include": "#close-bracket" + }, + { + "include": "#open-angle" + }, + { + "include": "#close-angle" } ] }, @@ -661,9 +675,9 @@ "begin": "(?x)(?<=/\\*\\*)([^*]|\\*(?!/))*$", "while": "(?x)(^|\\G)\\s*([^*]|\\*(?!/))(?=([^*]|[*](?!/))*$)", "patterns": [ - - - + + + { "match": "(?x)\\G\\s* (@\\S+)", "name": "keyword.tag.ql" @@ -723,15 +737,48 @@ } ] }, - "import-directive": { - "end": "(?x)(?:\\b [A-Za-z][0-9A-Za-z_]* (?:(?!(?:[0-9A-Za-z_])))) (?!\\s*(\\.|\\:\\:))", - "endCaptures": { - "0": { + "instantiation-args": { + "name": "meta.type.parameters.ql", + "patterns": [ + { + "include": "#instantiation-args" + }, + { + "include": "#non-context-sensitive" + }, + { + "match": "(?x)(?:\\b [A-Za-z][0-9A-Za-z_]* (?:(?!(?:[0-9A-Za-z_]))))", "name": "entity.name.type.namespace.ql" } + ], + "begin": "(?x)((?:<))", + "beginCaptures": { + "1": { + "patterns": [ + { + "include": "#open-angle" + } + ] + } }, + "end": "(?x)((?:>))", + "endCaptures": { + "1": { + "patterns": [ + { + "include": "#close-angle" + } + ] + } + } + }, + "import-directive": { + "end": "(?x)(?)|[A-Za-z0-9_]) (?!\\s*(\\.|\\:\\:|\\,|(?:<)))", "name": "meta.block.import-directive.ql", "patterns": [ + { + "include": "#instantiation-args" + }, { "include": "#non-context-sensitive" }, @@ -1493,4 +1540,4 @@ "name": "constant.character.escape.ql" } } -} \ No newline at end of file +}