Skip to content

Commit

Permalink
Fix the method declaration detection to handle complete typeparameter…
Browse files Browse the repository at this point in the history
… list on single line

Fixes #720
  • Loading branch information
sheetalkamat committed Mar 20, 2019
1 parent 31b00a7 commit d8c9720
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 12 deletions.
8 changes: 4 additions & 4 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ repository:
- include: '#function-body'
# new or call signature
- name: meta.method.declaration.ts
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\s*\b(new)\b(?!:){{endOfIdentifier}})|(?:(\*)\s*)?)(?=\s*[\(\<])'
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\s*\b(new)\b(?!:){{endOfIdentifier}})|(?:(\*)\s*)?)(?=\s*({{typeParameters}})?[\(])'
beginCaptures:
'1': { name: storage.modifier.ts } # captures keyword (public or private or protected)
'2': { name: storage.modifier.ts } # captures keyword (abstract)
Expand All @@ -726,7 +726,7 @@ repository:
- include: '#function-body'
# method, accessor
- name: meta.method.declaration.ts
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*({{propertyName}}\s*(\??))\s*[\(\<])'
begin: '(?x){{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*({{propertyName}}\s*(\??))\s*({{typeParameters}})?[\(])'
beginCaptures:
'1': { name: storage.modifier.ts } # captures keyword (public or private or protected)
'2': { name: storage.modifier.ts } # captures keyword (abstract)
Expand All @@ -740,7 +740,7 @@ repository:

object-literal-method-declaration:
name: meta.method.declaration.ts
begin: '(?x){{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*({{propertyName}}\s*(\??))\s*[\(\<])'
begin: '(?x){{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*({{propertyName}}\s*(\??))\s*({{typeParameters}})?[\(])'
beginCaptures:
'1': { name: storage.modifier.async.ts } # captures keyword (async)
'2': { name: storage.type.property.ts } # captures keyword (get|set)
Expand All @@ -749,7 +749,7 @@ repository:
patterns:
- include: '#method-declaration-name'
- include: '#function-body'
- begin: '(?x){{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*({{propertyName}}\s*(\??))\s*[\(\<])'
- begin: '(?x){{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*({{propertyName}}\s*(\??))\s*({{typeParameters}})?[\(])'
beginCaptures:
'1': { name: storage.modifier.async.ts } # captures keyword (async)
'2': { name: storage.type.property.ts } # captures keyword (get|set)
Expand Down
8 changes: 4 additions & 4 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,7 @@
<key>name</key>
<string>meta.method.declaration.ts</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\s*\b(new)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?)(?=\s*[\(\&lt;])</string>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\s*\b(new)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?)(?=\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -2309,7 +2309,7 @@
(?:\b[0-9][0-9_]*(\.)(n)?\B)| # 1.
(?:\B(\.)[0-9][0-9_]*(n)?\b)| # .1
(?:\b[0-9][0-9_]*(n)?\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\&lt;])</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -2368,7 +2368,7 @@
(?:\b[0-9][0-9_]*(\.)(n)?\B)| # 1.
(?:\B(\.)[0-9][0-9_]*(n)?\b)| # .1
(?:\b[0-9][0-9_]*(n)?\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\&lt;])</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -2410,7 +2410,7 @@
(?:\b[0-9][0-9_]*(\.)(n)?\B)| # 1.
(?:\B(\.)[0-9][0-9_]*(n)?\b)| # .1
(?:\b[0-9][0-9_]*(n)?\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\&lt;])</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down
8 changes: 4 additions & 4 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@
<key>name</key>
<string>meta.method.declaration.tsx</string>
<key>begin</key>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\s*\b(new)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?)(?=\s*[\(\&lt;])</string>
<string>(?x)(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\s*\b(new)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?)(?=\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -2313,7 +2313,7 @@
(?:\b[0-9][0-9_]*(\.)(n)?\B)| # 1.
(?:\B(\.)[0-9][0-9_]*(n)?\b)| # .1
(?:\b[0-9][0-9_]*(n)?\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\&lt;])</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -2372,7 +2372,7 @@
(?:\b[0-9][0-9_]*(\.)(n)?\B)| # 1.
(?:\B(\.)[0-9][0-9_]*(n)?\b)| # .1
(?:\b[0-9][0-9_]*(n)?\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\&lt;])</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -2414,7 +2414,7 @@
(?:\b[0-9][0-9_]*(\.)(n)?\B)| # 1.
(?:\B(\.)[0-9][0-9_]*(n)?\b)| # .1
(?:\b[0-9][0-9_]*(n)?\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\&lt;])</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\`([^\`\\]|\\\`|\\)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;]|\&lt;\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=&lt;&gt;]|=[^&lt;])*\&gt;)*&gt;\s*))?[\(])</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down
166 changes: 166 additions & 0 deletions tests/baselines/Issue720.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
original file
-----------------------------------
class Bar {
myFunc1 = () =>
1 < 2 &&
2 > 1 &&
FOO < FOOO;
myFunc2 = () =>
1 < 2 &&
2 > 1 &&
FOO < FOOO;
}
-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>class Bar {
^^^^^
source.ts meta.class.ts storage.type.class.ts
^
source.ts meta.class.ts
^^^
source.ts meta.class.ts entity.name.type.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts punctuation.definition.block.ts
> myFunc1 = () =>
^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts storage.type.function.arrow.ts
> 1 < 2 &&
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.relational.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> 2 > 1 &&
^^^^
source.ts meta.class.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
^^
source.ts meta.class.ts keyword.operator.logical.ts
> FOO < FOOO;
^^^^
source.ts meta.class.ts
^^^
source.ts meta.class.ts variable.other.constant.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
> myFunc2 = () =>
^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts storage.type.function.arrow.ts
> 1 < 2 &&
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.relational.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> 2 > 1 &&
^^^^
source.ts meta.class.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
^^
source.ts meta.class.ts keyword.operator.logical.ts
> FOO < FOOO;
^^^^
source.ts meta.class.ts
^^^
source.ts meta.class.ts variable.other.constant.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts
10 changes: 10 additions & 0 deletions tests/cases/Issue720.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Bar {
myFunc1 = () =>
1 < 2 &&
2 > 1 &&
FOO < FOOO;
myFunc2 = () =>
1 < 2 &&
2 > 1 &&
FOO < FOOO;
}

0 comments on commit d8c9720

Please sign in to comment.