Skip to content

Commit c78f017

Browse files
Dave Bartolomeoginsbach
authored andcommitted
Alternate fix for import highlighting with instantiations
1 parent 353e22d commit c78f017

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -661,29 +661,38 @@ repository:
661661
- include: '#non-context-sensitive'
662662
- include: '#annotation'
663663

664-
instantiation-arguments:
664+
# The argument list of an instantiation, enclosed in angle brackets.
665+
instantiation-args:
665666
beginPattern: '#open-angle'
666-
end: '#close-angle'
667+
endPattern: '#close-angle'
668+
name: meta.type.parameters.ql
667669
patterns:
668-
- include: '#potential-instantiation'
669-
670-
potential-instantiation:
671-
matches: '(?#simple-id) (?#instantiation-arguments)?'
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
672676

673677
# An `import` directive. Note that we parse the optional `as` clause as a separate top-level
674678
# directive, because otherwise it's too hard to figure out where the `import` directive ends.
675679
import-directive:
676680
beginPattern: '#import'
677-
# Ends with a simple-id that is not followed by a `.` or a `::`. This does not handle comments or
678-
# line breaks between the simple-id and the `.` or `::`.
679-
end: '(?#simple-id) (?!\s*(\.|\:\:))'
680-
endCaptures:
681-
'0':
682-
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)))'
683689
name: meta.block.import-directive.ql
684690
patterns:
691+
# Include `#instantiation-args` first so that `#open-angle` and `#close-angle` take precedence
692+
# over `#relational-operator`.
693+
- include: '#instantiation-args'
685694
- include: '#non-context-sensitive'
686-
- match: '(?#potential-instantiation)'
695+
- match: '(?#simple-id)'
687696
name: entity.name.type.namespace.ql
688697

689698
# The end pattern for an `as` clause, whether on an `import` directive, in an aggregate, or on a

0 commit comments

Comments
 (0)