Fix the method declaration detection to handle complete typeparameter list on single line

Fixes #720
This commit is contained in:
Sheetal Nandi 2019-03-20 13:00:11 -07:00
Родитель 31b00a7778
Коммит d8c9720c4e
5 изменённых файлов: 188 добавлений и 12 удалений

Просмотреть файл

@ -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)
@ -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)
@ -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)
@ -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)

Просмотреть файл

@ -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>
@ -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>
@ -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>
@ -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>

Просмотреть файл

@ -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>
@ -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>
@ -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>
@ -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>

Просмотреть файл

@ -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
tests/cases/Issue720.ts Normal file
Просмотреть файл

@ -0,0 +1,10 @@
class Bar {
myFunc1 = () =>
1 < 2 &&
2 > 1 &&
FOO < FOOO;
myFunc2 = () =>
1 < 2 &&
2 > 1 &&
FOO < FOOO;
}