Skip to content

Commit 86b2157

Browse files
authored
Merge pull request #2792 from github/ginsbach/TextMateInstantiationSyntax
fix syntax highlighting after imports with instantiation arguments
2 parents 27c4bd8 + 47fa163 commit 86b2157

File tree

3 files changed

+90
-15
lines changed

3 files changed

+90
-15
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Increase the required version of VS Code to 1.82.0. [#2877](https://github.com/github/vscode-codeql/pull/2877)
88
- Fix a bug where the query server was restarted twice after configuration changes. [#2884](https://github.com/github/vscode-codeql/pull/2884).
99
- 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).
10+
- Fix syntax highlighting directly after import statements with instantiation arguments. [#2792](https://github.com/github/vscode-codeql/pull/2792)
1011

1112
## 1.9.1 - 29 September 2023
1213

extensions/ql-vscode/syntaxes/ql.tmLanguage.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ repository:
170170
match: '\]'
171171
name: punctuation.squarebracket.close.ql
172172

173+
open-angle:
174+
match: '<'
175+
name: punctuation.anglebracket.open.ql
176+
177+
close-angle:
178+
match: '>'
179+
name: punctuation.anglebracket.close.ql
180+
173181
operator-or-punctuation:
174182
patterns:
175183
- include: '#relational-operator'
@@ -186,6 +194,8 @@ repository:
186194
- include: '#close-brace'
187195
- include: '#open-bracket'
188196
- include: '#close-bracket'
197+
- include: '#open-angle'
198+
- include: '#close-angle'
189199

190200
# Keywords
191201
dont-care:
@@ -651,18 +661,36 @@ repository:
651661
- include: '#non-context-sensitive'
652662
- include: '#annotation'
653663

664+
# The argument list of an instantiation, enclosed in angle brackets.
665+
instantiation-args:
666+
beginPattern: '#open-angle'
667+
endPattern: '#close-angle'
668+
name: meta.type.parameters.ql
669+
patterns:
670+
# Include `#instantiation-args` first so that `#open-angle` and `#close-angle` take precedence
671+
# over `#relational-operator`.
672+
- include: '#instantiation-args'
673+
- include: '#non-context-sensitive'
674+
- match: '(?#simple-id)'
675+
name: entity.name.type.namespace.ql
676+
654677
# An `import` directive. Note that we parse the optional `as` clause as a separate top-level
655678
# directive, because otherwise it's too hard to figure out where the `import` directive ends.
656679
import-directive:
657680
beginPattern: '#import'
658-
# Ends with a simple-id that is not followed by a `.` or a `::`. This does not handle comments or
659-
# line breaks between the simple-id and the `.` or `::`.
660-
end: '(?#simple-id) (?!\s*(\.|\:\:))'
661-
endCaptures:
662-
'0':
663-
name: entity.name.type.namespace.ql
681+
# TextMate makes it tricky to tell whether an identifier that we encounter is part of the
682+
# `import` directive or whether it's the first token of the next module-level declaration.
683+
# To find the end of the import directive, we'll look for a zero-width match where the previous
684+
# token is either an identifier (other than `import`) or a `>`, and the next token is not a `.`,
685+
# `<`, `,`, or `::`. This works for nearly all real-world `import` directives, but it will end the
686+
# `import` directive too early if there is a comment or line break between two components of the
687+
# module expression.
688+
end: '(?<!\bimport)(?<=(?:\>)|[A-Za-z0-9_]) (?!\s*(\.|\:\:|\,|(?#open-angle)))'
664689
name: meta.block.import-directive.ql
665690
patterns:
691+
# Include `#instantiation-args` first so that `#open-angle` and `#close-angle` take precedence
692+
# over `#relational-operator`.
693+
- include: '#instantiation-args'
666694
- include: '#non-context-sensitive'
667695
- match: '(?#simple-id)'
668696
name: entity.name.type.namespace.ql
@@ -703,7 +731,6 @@ repository:
703731
- match: '(?#simple-id)|(?#at-lower-id)'
704732
name: entity.name.type.ql
705733

706-
707734
# A `module` declaration, whether a module definition or an alias declaration.
708735
module-declaration:
709736
# Starts with the `module` keyword.

syntaxes/ql.tmLanguage.json

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@
108108
"match": "(?x)\\]",
109109
"name": "punctuation.squarebracket.close.ql"
110110
},
111+
"open-angle": {
112+
"match": "(?x)<",
113+
"name": "punctuation.anglebracket.open.ql"
114+
},
115+
"close-angle": {
116+
"match": "(?x)>",
117+
"name": "punctuation.anglebracket.close.ql"
118+
},
111119
"operator-or-punctuation": {
112120
"patterns": [
113121
{
@@ -151,6 +159,12 @@
151159
},
152160
{
153161
"include": "#close-bracket"
162+
},
163+
{
164+
"include": "#open-angle"
165+
},
166+
{
167+
"include": "#close-angle"
154168
}
155169
]
156170
},
@@ -661,9 +675,9 @@
661675
"begin": "(?x)(?<=/\\*\\*)([^*]|\\*(?!/))*$",
662676
"while": "(?x)(^|\\G)\\s*([^*]|\\*(?!/))(?=([^*]|[*](?!/))*$)",
663677
"patterns": [
664-
665-
666-
678+
679+
680+
667681
{
668682
"match": "(?x)\\G\\s* (@\\S+)",
669683
"name": "keyword.tag.ql"
@@ -723,15 +737,48 @@
723737
}
724738
]
725739
},
726-
"import-directive": {
727-
"end": "(?x)(?:\\b [A-Za-z][0-9A-Za-z_]* (?:(?!(?:[0-9A-Za-z_])))) (?!\\s*(\\.|\\:\\:))",
728-
"endCaptures": {
729-
"0": {
740+
"instantiation-args": {
741+
"name": "meta.type.parameters.ql",
742+
"patterns": [
743+
{
744+
"include": "#instantiation-args"
745+
},
746+
{
747+
"include": "#non-context-sensitive"
748+
},
749+
{
750+
"match": "(?x)(?:\\b [A-Za-z][0-9A-Za-z_]* (?:(?!(?:[0-9A-Za-z_]))))",
730751
"name": "entity.name.type.namespace.ql"
731752
}
753+
],
754+
"begin": "(?x)((?:<))",
755+
"beginCaptures": {
756+
"1": {
757+
"patterns": [
758+
{
759+
"include": "#open-angle"
760+
}
761+
]
762+
}
732763
},
764+
"end": "(?x)((?:>))",
765+
"endCaptures": {
766+
"1": {
767+
"patterns": [
768+
{
769+
"include": "#close-angle"
770+
}
771+
]
772+
}
773+
}
774+
},
775+
"import-directive": {
776+
"end": "(?x)(?<!\\bimport)(?<=(?:\\>)|[A-Za-z0-9_]) (?!\\s*(\\.|\\:\\:|\\,|(?:<)))",
733777
"name": "meta.block.import-directive.ql",
734778
"patterns": [
779+
{
780+
"include": "#instantiation-args"
781+
},
735782
{
736783
"include": "#non-context-sensitive"
737784
},
@@ -1493,4 +1540,4 @@
14931540
"name": "constant.character.escape.ql"
14941541
}
14951542
}
1496-
}
1543+
}

0 commit comments

Comments
 (0)