Skip to content

Commit 1a930f6

Browse files
authored
Syntax highlighting for functions, variables and numbers (#2088)
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)
1 parent 5ff51bb commit 1a930f6

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

vscode/syntaxes/qsharp.tmLanguage.json

+116
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
{
77
"include": "#comments"
88
},
9+
{
10+
"include": "#functions"
11+
},
912
{
1013
"include": "#keywords"
1114
},
@@ -20,6 +23,9 @@
2023
},
2124
{
2225
"include": "#strings"
26+
},
27+
{
28+
"include": "#variables"
2329
}
2430
],
2531
"repository": {
@@ -35,6 +41,103 @@
3541
}
3642
]
3743
},
44+
"functions": {
45+
"patterns": [
46+
{
47+
"comment": "function definition",
48+
"name": "meta.function.definition.qsharp",
49+
"begin": "\\b(function)\\s+([A-Za-z0-9_]+)(\\()",
50+
"beginCaptures": {
51+
"1": {
52+
"name": "keyword.other.qsharp"
53+
},
54+
"2": {
55+
"name": "entity.name.function.qsharp"
56+
},
57+
"3": {
58+
"name": "punctuation.brackets.round.qsharp"
59+
}
60+
},
61+
"end": "\\)",
62+
"endCaptures": {
63+
"0": {
64+
"name": "punctuation.brackets.round.qsharp"
65+
}
66+
},
67+
"patterns": [
68+
{
69+
"include": "#comments"
70+
},
71+
{
72+
"include": "#functions"
73+
},
74+
{
75+
"include": "#keywords"
76+
},
77+
{
78+
"include": "#operators"
79+
},
80+
{
81+
"include": "#types"
82+
},
83+
{
84+
"include": "#constants"
85+
},
86+
{
87+
"include": "#strings"
88+
},
89+
{
90+
"include": "#variables"
91+
}
92+
]
93+
},
94+
{
95+
"comment": "function calls",
96+
"name": "meta.function.call.qsharp",
97+
"begin": "\\b(?<!@)([A-Za-z0-9_]+)(\\()",
98+
"beginCaptures": {
99+
"1": {
100+
"name": "entity.name.function.qsharp"
101+
},
102+
"2": {
103+
"name": "punctuation.brackets.round.qsharp"
104+
}
105+
},
106+
"end": "\\)",
107+
"endCaptures": {
108+
"0": {
109+
"name": "punctuation.brackets.round.qsharp"
110+
}
111+
},
112+
"patterns": [
113+
{
114+
"include": "#comments"
115+
},
116+
{
117+
"include": "#functions"
118+
},
119+
{
120+
"include": "#keywords"
121+
},
122+
{
123+
"include": "#operators"
124+
},
125+
{
126+
"include": "#types"
127+
},
128+
{
129+
"include": "#constants"
130+
},
131+
{
132+
"include": "#strings"
133+
},
134+
{
135+
"include": "#variables"
136+
}
137+
]
138+
}
139+
]
140+
},
38141
"keywords": {
39142
"patterns": [
40143
{
@@ -72,6 +175,11 @@
72175
{
73176
"name": "constant.other.result.qsharp",
74177
"match": "\\b(One|Zero)\\b"
178+
},
179+
{
180+
"comment": "integers and decimals",
181+
"name": "constant.numeric.qsharp",
182+
"match": "\\b[\\d_]*\\.?[\\d_]\\b"
75183
}
76184
]
77185
},
@@ -89,6 +197,14 @@
89197
]
90198
}
91199
]
200+
},
201+
"variables": {
202+
"patterns": [
203+
{
204+
"name": "variable.other.qsharp",
205+
"match": "\\b(?<!@)[A-Za-z0-9_]+\\b"
206+
}
207+
]
92208
}
93209
},
94210
"scopeName": "source.qsharp"

0 commit comments

Comments
 (0)