Skip to content

Commit

Permalink
Syntax highlighting for functions, variables and numbers (#2088)
Browse files Browse the repository at this point in the history
Supports syntax highlighting for:

- function definitions
- function calls
- numbers
- variables

See issue #1950.

The change for function calls also applies to operation definitions and
to attributes (see bigger example below).
The change for variables also applies to attributes and to imports.

I might be nice to make attributes and imports get their own designated
rules. I can do them as part of this PR, but I think it might be best to
do as a followup issue - because I believe this PR is actually already
an improvement for them.

Simple example for the change (from the original issue description):


![image](https://github.com/user-attachments/assets/cab2630b-0e28-4d48-a98e-7e5bc83e5c7c)

And a bigger example:


![image](https://github.com/user-attachments/assets/7d0c059a-8481-4159-ba64-d8539f1540c0)
  • Loading branch information
Morcifer authored Jan 7, 2025
1 parent 5ff51bb commit 1a930f6
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions vscode/syntaxes/qsharp.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
{
"include": "#comments"
},
{
"include": "#functions"
},
{
"include": "#keywords"
},
Expand All @@ -20,6 +23,9 @@
},
{
"include": "#strings"
},
{
"include": "#variables"
}
],
"repository": {
Expand All @@ -35,6 +41,103 @@
}
]
},
"functions": {
"patterns": [
{
"comment": "function definition",
"name": "meta.function.definition.qsharp",
"begin": "\\b(function)\\s+([A-Za-z0-9_]+)(\\()",
"beginCaptures": {
"1": {
"name": "keyword.other.qsharp"
},
"2": {
"name": "entity.name.function.qsharp"
},
"3": {
"name": "punctuation.brackets.round.qsharp"
}
},
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.brackets.round.qsharp"
}
},
"patterns": [
{
"include": "#comments"
},
{
"include": "#functions"
},
{
"include": "#keywords"
},
{
"include": "#operators"
},
{
"include": "#types"
},
{
"include": "#constants"
},
{
"include": "#strings"
},
{
"include": "#variables"
}
]
},
{
"comment": "function calls",
"name": "meta.function.call.qsharp",
"begin": "\\b(?<!@)([A-Za-z0-9_]+)(\\()",
"beginCaptures": {
"1": {
"name": "entity.name.function.qsharp"
},
"2": {
"name": "punctuation.brackets.round.qsharp"
}
},
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.brackets.round.qsharp"
}
},
"patterns": [
{
"include": "#comments"
},
{
"include": "#functions"
},
{
"include": "#keywords"
},
{
"include": "#operators"
},
{
"include": "#types"
},
{
"include": "#constants"
},
{
"include": "#strings"
},
{
"include": "#variables"
}
]
}
]
},
"keywords": {
"patterns": [
{
Expand Down Expand Up @@ -72,6 +175,11 @@
{
"name": "constant.other.result.qsharp",
"match": "\\b(One|Zero)\\b"
},
{
"comment": "integers and decimals",
"name": "constant.numeric.qsharp",
"match": "\\b[\\d_]*\\.?[\\d_]\\b"
}
]
},
Expand All @@ -89,6 +197,14 @@
]
}
]
},
"variables": {
"patterns": [
{
"name": "variable.other.qsharp",
"match": "\\b(?<!@)[A-Za-z0-9_]+\\b"
}
]
}
},
"scopeName": "source.qsharp"
Expand Down

0 comments on commit 1a930f6

Please sign in to comment.