Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"patterns" array does not work with "match" TextMate #542

Closed
RedCMD opened this issue Dec 1, 2023 · 3 comments
Closed

"patterns" array does not work with "match" TextMate #542

RedCMD opened this issue Dec 1, 2023 · 3 comments
Labels

Comments

@RedCMD
Copy link

RedCMD commented Dec 1, 2023

Godot version

NA

VS Code version

1.84.2

Godot Tools VS Code extension version

1.3.1

System information

Windows 11

Issue description

"patterns" does not work with "match"
escape characters will not get tokenized
did you mean to use begin/end instead?

"begin": "\""
"end": "\""

{
"name": "string.quoted.double.basic.line.gdresource",
"match": "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"",
"patterns": [
{
"match": "\\\\([btnfr\"\\\\\\n/ ]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})",
"name": "constant.character.escape.gdresource"
},
{
"match": "\\\\[^btnfr/\"\\\\\\n]",
"name": "invalid.illegal.escape.gdresource"
}
]
},

I don't recommend putting the string contents in a capture group and using "patterns" inside "captures"
as that incurs a medium performance hit in VSCode TextMate
EDIT: "name" inside "captures" is fine

If Godot shouldn't support escape characters inside a string
then the "patterns" array can be safely removed

Steps to reproduce

Create a string with escape characters inside it \\
[ "string\\bar" ]

@RedCMD RedCMD added the bug label Dec 1, 2023
@DaelonSuzuka
Copy link
Collaborator

Good catch, thank you.

I don't recommend putting the string contents in a capture group and using "captures"
as that incurs a medium performance hit in VSCode TextMate

How do you know that? I've been looking for resources on TextMate best practices for a while, but there isn't much content in this area.

@RedCMD
Copy link
Author

RedCMD commented Dec 2, 2023

but there isn't much content in this area.

heres some links I've used:

How do you know that?

Through my own personal testing microsoft/vscode-textmate#167
I was confused as to why some rules were causing more lag than others for seemingly no reason
turned out simply just using a "patterns" array inside "captures" was causing the lag
I suspect its doing an inefficient string copy?
you wont see the performance difference much until you try tokenizing 5000+ character lines or 10,000+ line files
EDIT: Using "name" inside "captures" is fine

@DaelonSuzuka
Copy link
Collaborator

Holy shit, you're the tmLanguage.json syntax extension guy! That's an excellent tool, thank you for building it!

<links>

Fantastic, thank you! Those are going in my list right away.

I was already planning to do some performance testing soon[0], so this is really useful stuff.

[0] I'm building a code formatter for GDScript using the tm grammar and vscode-textmate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants