Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions syntaxes/go.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1923,12 +1923,12 @@
},
{
"comment": "one line with semicolon(;) without formatting gofmt - single type | property variables and types",
"match": "(?:(?<=\\{)((?:\\s*(?:(?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?(?:(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[^\\s/]+)(?:\\;)?))+)\\s*(?=\\}))",
"match": "(?:(?<=\\{)((?:\\s*(?:(?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?(?:(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[^\\s/\\`\"]+)(?:\\;)?))+)\\s*(?=\\}))",
"captures": {
"1": {
"patterns": [
{
"match": "(?:((?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?((?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[^\\s/]+)(?:\\;)?))",
"match": "(?:((?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?((?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[^\\s/\\`\"]+)(?:\\;)?))",
"captures": {
"1": {
"patterns": [
Expand Down
11 changes: 11 additions & 0 deletions test/semantic_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -4974,3 +4974,14 @@ func weDontKnowIfIsTypeOrVariable(name string, born time.Time) ([]byte, error) {
Age: new(age),
})
}

// Shiki JS engine catastrophic backtracking with long struct tags
// See: https://github.com/shikijs/shiki/issues/1026 (similar issue with comments)
// Time grows exponentially O(4^n) with tag length when using JavaScript regex engine

type BacktrackTest struct {
ShortTag string `json:"short"`
MediumTag string `json:"medium_length_tag"`
LongTag interface{} `json:"this_is_a_very_long_tag_name"`
WithOptions interface{} `json:"field_name,omitempty"`
}
61 changes: 61 additions & 0 deletions test/semantic_tokens.go.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48003,4 +48003,65 @@
# ^ source.go punctuation.definition.end.bracket.round.go
>}
#^ source.go punctuation.definition.end.bracket.curly.go
>
>// Shiki JS engine catastrophic backtracking with long struct tags
#^^ source.go comment.line.double-slash.go punctuation.definition.comment.go
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.go comment.line.double-slash.go
>// See: https://github.com/shikijs/shiki/issues/1026 (similar issue with comments)
#^^ source.go comment.line.double-slash.go punctuation.definition.comment.go
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.go comment.line.double-slash.go
>// Time grows exponentially O(4^n) with tag length when using JavaScript regex engine
#^^ source.go comment.line.double-slash.go punctuation.definition.comment.go
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.go comment.line.double-slash.go
>
>type BacktrackTest struct {
#^^^^ source.go keyword.type.go
# ^ source.go
# ^^^^^^^^^^^^^ source.go entity.name.type.go
# ^ source.go
# ^^^^^^ source.go keyword.struct.go
# ^ source.go
# ^ source.go punctuation.definition.begin.bracket.curly.go
> ShortTag string `json:"short"`
#^ source.go
# ^^^^^^^^ source.go variable.other.property.go
# ^^^^ source.go
# ^^^^^^ source.go storage.type.string.go
# ^^^^^^ source.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.begin.go
# ^^^^^^^^^^^^ source.go string.quoted.raw.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.end.go
> MediumTag string `json:"medium_length_tag"`
#^ source.go
# ^^^^^^^^^ source.go variable.other.property.go
# ^^^ source.go
# ^^^^^^ source.go storage.type.string.go
# ^^^^^^ source.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.begin.go
# ^^^^^^^^^^^^^^^^^^^^^^^^ source.go string.quoted.raw.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.end.go
> LongTag interface{} `json:"this_is_a_very_long_tag_name"`
#^ source.go
# ^^^^^^^ source.go variable.other.property.go
# ^^^^^ source.go
# ^^^^^^^^^ source.go keyword.interface.go
# ^ source.go punctuation.definition.begin.bracket.curly.go
# ^ source.go punctuation.definition.end.bracket.curly.go
# ^ source.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.begin.go
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.go string.quoted.raw.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.end.go
> WithOptions interface{} `json:"field_name,omitempty"`
#^ source.go
# ^^^^^^^^^^^ source.go variable.other.property.go
# ^ source.go
# ^^^^^^^^^ source.go keyword.interface.go
# ^ source.go punctuation.definition.begin.bracket.curly.go
# ^ source.go punctuation.definition.end.bracket.curly.go
# ^ source.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.begin.go
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.go string.quoted.raw.go
# ^ source.go string.quoted.raw.go punctuation.definition.string.end.go
>}
#^ source.go punctuation.definition.end.bracket.curly.go
>
Loading