6330: Textmate grammar: raw IDs, underscore fixes (closes #6293, #6340) r=dustypomerleau a=dustypomerleau

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/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>
This commit is contained in:
bors[bot] 2020-10-24 03:31:17 +00:00 committed by GitHub
commit 4105378dc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -158,7 +158,7 @@
}, },
{ {
"comment": "modules", "comment": "modules",
"match": "(mod)\\s+([a-z][A-Za-z0-9_]*)", "match": "(mod)\\s+((?:r#(?!crate|[Ss]elf|super))?[a-z][A-Za-z0-9_]*)",
"captures": { "captures": {
"1": { "1": {
"name": "keyword.control.rust" "name": "keyword.control.rust"
@ -295,11 +295,6 @@
"comment": "line comments", "comment": "line comments",
"name": "comment.line.double-slash.rust", "name": "comment.line.double-slash.rust",
"match": "\\s*//.*" "match": "\\s*//.*"
},
{
"comment": "inferred types, wildcard patterns, ignored params",
"name": "comment.char.underscore.rust",
"match": "\\b_\\w*\\b[^!(]"
} }
] ]
}, },
@ -431,10 +426,22 @@
}, },
"functions": { "functions": {
"patterns": [ "patterns": [
{
"comment": "pub as a function",
"match": "\\b(pub)(\\()",
"captures": {
"1": {
"name": "keyword.other.rust"
},
"2": {
"name": "punctuation.brackets.round.rust"
}
}
},
{ {
"comment": "function definition", "comment": "function definition",
"name": "meta.function.definition.rust", "name": "meta.function.definition.rust",
"begin": "\\b(fn)\\s+([A-Za-z0-9_]+)((\\()|(<))", "begin": "\\b(fn)\\s+((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)((\\()|(<))",
"beginCaptures": { "beginCaptures": {
"1": { "1": {
"name": "keyword.control.fn.rust" "name": "keyword.control.fn.rust"
@ -503,18 +510,12 @@
{ {
"comment": "function/method calls, chaining", "comment": "function/method calls, chaining",
"name": "meta.function.call.rust", "name": "meta.function.call.rust",
"begin": "(?:(pub)|(?:(\\.)?([A-Za-z0-9_]+)))(\\()", "begin": "((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)(\\()",
"beginCaptures": { "beginCaptures": {
"1": { "1": {
"name": "keyword.other.rust"
},
"2": {
"name": "keyword.operator.access.dot.rust"
},
"3": {
"name": "entity.name.function.rust" "name": "entity.name.function.rust"
}, },
"4": { "2": {
"name": "punctuation.brackets.round.rust" "name": "punctuation.brackets.round.rust"
} }
}, },
@ -1042,7 +1043,7 @@
{ {
"comment": "variables", "comment": "variables",
"name": "variable.other.rust", "name": "variable.other.rust",
"match": "\\b(?<!\\.)[a-z0-9_]+\\b" "match": "\\b(?<!\\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\\b"
} }
] ]
} }