Skip to content

Commit 4105378

Browse files
Merge #6330
6330: Textmate grammar: raw IDs, underscore fixes (closes #6293, #6340) r=dustypomerleau a=dustypomerleau Fixes rust-lang/rust-analyzer#6293. I've included the possibility of the `r#` prefix in: - function definitions - function/method calls - variables/parameters This way the raw ID will simply get whatever the intended scope was, instead of a unique scope that might be inappropriately themed for its purpose. Will wait a bit for feedback, in case there are other places you might use raw IDs. Co-authored-by: Dusty Pomerleau <dustypomerleau@users.noreply.github.com>
2 parents 2fa942a + f352b98 commit 4105378

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

editors/code/rust.tmGrammar.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
},
159159
{
160160
"comment": "modules",
161-
"match": "(mod)\\s+([a-z][A-Za-z0-9_]*)",
161+
"match": "(mod)\\s+((?:r#(?!crate|[Ss]elf|super))?[a-z][A-Za-z0-9_]*)",
162162
"captures": {
163163
"1": {
164164
"name": "keyword.control.rust"
@@ -295,11 +295,6 @@
295295
"comment": "line comments",
296296
"name": "comment.line.double-slash.rust",
297297
"match": "\\s*//.*"
298-
},
299-
{
300-
"comment": "inferred types, wildcard patterns, ignored params",
301-
"name": "comment.char.underscore.rust",
302-
"match": "\\b_\\w*\\b[^!(]"
303298
}
304299
]
305300
},
@@ -431,10 +426,22 @@
431426
},
432427
"functions": {
433428
"patterns": [
429+
{
430+
"comment": "pub as a function",
431+
"match": "\\b(pub)(\\()",
432+
"captures": {
433+
"1": {
434+
"name": "keyword.other.rust"
435+
},
436+
"2": {
437+
"name": "punctuation.brackets.round.rust"
438+
}
439+
}
440+
},
434441
{
435442
"comment": "function definition",
436443
"name": "meta.function.definition.rust",
437-
"begin": "\\b(fn)\\s+([A-Za-z0-9_]+)((\\()|(<))",
444+
"begin": "\\b(fn)\\s+((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)((\\()|(<))",
438445
"beginCaptures": {
439446
"1": {
440447
"name": "keyword.control.fn.rust"
@@ -503,18 +510,12 @@
503510
{
504511
"comment": "function/method calls, chaining",
505512
"name": "meta.function.call.rust",
506-
"begin": "(?:(pub)|(?:(\\.)?([A-Za-z0-9_]+)))(\\()",
513+
"begin": "((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)(\\()",
507514
"beginCaptures": {
508515
"1": {
509-
"name": "keyword.other.rust"
510-
},
511-
"2": {
512-
"name": "keyword.operator.access.dot.rust"
513-
},
514-
"3": {
515516
"name": "entity.name.function.rust"
516517
},
517-
"4": {
518+
"2": {
518519
"name": "punctuation.brackets.round.rust"
519520
}
520521
},
@@ -1042,7 +1043,7 @@
10421043
{
10431044
"comment": "variables",
10441045
"name": "variable.other.rust",
1045-
"match": "\\b(?<!\\.)[a-z0-9_]+\\b"
1046+
"match": "\\b(?<!\\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\\b"
10461047
}
10471048
]
10481049
}

0 commit comments

Comments
 (0)