Skip to content

Alternate fix for import highlighting with instantiations #2859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [UNRELEASED]

- Fix syntax highlighting directly after import statements with instantiation arguments. [#2792](https://github.com/github/vscode-codeql/pull/2792)

## 1.8.11 - 7 September 2023

- Update how variant analysis results are displayed. For queries with ["path-problem" or "problem" `@kind`](https://codeql.github.com/docs/writing-codeql-queries/metadata-for-codeql-queries/#metadata-properties), you can choose to display the results as rendered alerts or as a table of raw results. For queries with any other `@kind`, the results are displayed as a table. [#2745](https://github.com/github/vscode-codeql/pull/2745) & [#2749](https://github.com/github/vscode-codeql/pull/2749)
Expand Down
41 changes: 34 additions & 7 deletions extensions/ql-vscode/syntaxes/ql.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -186,6 +194,8 @@ repository:
- include: '#close-brace'
- include: '#open-bracket'
- include: '#close-bracket'
- include: '#open-angle'
- include: '#close-angle'

# Keywords
dont-care:
Expand Down Expand Up @@ -651,18 +661,36 @@ repository:
- include: '#non-context-sensitive'
- include: '#annotation'

# The argument list of an instantiation, enclosed in angle brackets.
instantiation-args:
beginPattern: '#open-angle'
endPattern: '#close-angle'
name: meta.type.parameters.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: '(?#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: '(?<!\bimport)(?<=(?:\>)|[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: '(?#simple-id)'
name: entity.name.type.namespace.ql
Expand Down Expand Up @@ -703,7 +731,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.
Expand Down
63 changes: 55 additions & 8 deletions syntaxes/ql.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -151,6 +159,12 @@
},
{
"include": "#close-bracket"
},
{
"include": "#open-angle"
},
{
"include": "#close-angle"
}
]
},
Expand Down Expand Up @@ -661,9 +675,9 @@
"begin": "(?x)(?<=/\\*\\*)([^*]|\\*(?!/))*$",
"while": "(?x)(^|\\G)\\s*([^*]|\\*(?!/))(?=([^*]|[*](?!/))*$)",
"patterns": [



{
"match": "(?x)\\G\\s* (@\\S+)",
"name": "keyword.tag.ql"
Expand Down Expand Up @@ -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)(?<!\\bimport)(?<=(?:\\>)|[A-Za-z0-9_]) (?!\\s*(\\.|\\:\\:|\\,|(?:<)))",
"name": "meta.block.import-directive.ql",
"patterns": [
{
"include": "#instantiation-args"
},
{
"include": "#non-context-sensitive"
},
Expand Down Expand Up @@ -1493,4 +1540,4 @@
"name": "constant.character.escape.ql"
}
}
}
}