Handle case when function declaration is multiple lines with parameters on new line

This makes it treated like arrow, so allow arrow matching to stop when function block starts
Fixes #405
This commit is contained in:
Sheetal Nandi 2017-01-17 11:50:33 -08:00
Родитель 602d96ad0e
Коммит e47681d06a
5 изменённых файлов: 259 добавлений и 6 удалений

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

@ -1624,7 +1624,7 @@ repository:
)
beginCaptures:
'1': { name: storage.modifier.async.ts }
end: (?==>)
end: (?==>|\{)
patterns:
- include: '#comment'
- include: '#type-parameters'
@ -1646,9 +1646,19 @@ repository:
begin: '(?<=\))\s*(:)'
beginCaptures:
'1': { name: keyword.operator.type.annotation.ts }
end: (?==>)
end: (?==>|\{)
patterns:
# TODO: handle the fn and constructor type specifically.
# Handle returning of object type specifically here so as to not confuse it with the start of function block
- name: meta.object.type.ts
begin: (?<=:)\s*(\{)
beginCaptures:
'1': { name: punctuation.definition.block.ts }
end: \}
endCaptures:
'0': { name: punctuation.definition.block.ts }
patterns:
- include: '#type-object-members'
- include: '#type-predicate-operator'
- include: '#type'

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

@ -4442,7 +4442,7 @@
</dict>
</dict>
<key>end</key>
<string>(?==&gt;)</string>
<string>(?==&gt;|\{)</string>
<key>patterns</key>
<array>
<dict>
@ -4507,9 +4507,40 @@
</dict>
</dict>
<key>end</key>
<string>(?==&gt;)</string>
<string>(?==&gt;|\{)</string>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>meta.object.type.ts</string>
<key>begin</key>
<string>(?&lt;=:)\s*(\{)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.block.ts</string>
</dict>
</dict>
<key>end</key>
<string>\}</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.block.ts</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type-object-members</string>
</dict>
</array>
</dict>
<dict>
<key>include</key>
<string>#type-predicate-operator</string>

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

@ -4424,7 +4424,7 @@
</dict>
</dict>
<key>end</key>
<string>(?==&gt;)</string>
<string>(?==&gt;|\{)</string>
<key>patterns</key>
<array>
<dict>
@ -4489,9 +4489,40 @@
</dict>
</dict>
<key>end</key>
<string>(?==&gt;)</string>
<string>(?==&gt;|\{)</string>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>meta.object.type.tsx</string>
<key>begin</key>
<string>(?&lt;=:)\s*(\{)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.block.tsx</string>
</dict>
</dict>
<key>end</key>
<string>\}</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.block.tsx</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type-object-members</string>
</dict>
</array>
</dict>
<dict>
<key>include</key>
<string>#type-predicate-operator</string>

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

@ -0,0 +1,168 @@
original file
-----------------------------------
function myFunction1
(a: string)
{
var r = true;
return true
}
function myFunction2
(a: string): boolean
{
var r = true;
return true
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>function myFunction1
^^^^^^^^
source.ts meta.function.ts storage.type.function.ts
^^
source.ts meta.function.ts
^^^^^^^^^^^
source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts
^^
source.ts meta.function.ts
> (a: string)
^^
source.ts meta.arrow.ts
^
source.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^
source.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^^
source.ts meta.arrow.ts
>{
^
source.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.block.ts
> var r = true;
^^
source.ts meta.block.ts
^^^
source.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.block.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.block.ts meta.var.expr.ts
^^^^
source.ts meta.block.ts meta.var.expr.ts constant.language.boolean.true.ts
^
source.ts meta.block.ts punctuation.terminator.statement.ts
^^
source.ts meta.block.ts
> return true
^^
source.ts meta.block.ts
^^^^^^
source.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.block.ts
^^^^
source.ts meta.block.ts constant.language.boolean.true.ts
^^
source.ts meta.block.ts
>}
^
source.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts
>
^^
source.ts
>function myFunction2
^^^^^^^^
source.ts meta.function.ts storage.type.function.ts
^
source.ts meta.function.ts
^^^^^^^^^^^
source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts
^^
source.ts meta.function.ts
> (a: string): boolean
^^
source.ts meta.arrow.ts
^
source.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^
source.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.arrow.ts meta.return.type.arrow.ts keyword.operator.type.annotation.ts
^
source.ts meta.arrow.ts meta.return.type.arrow.ts
^^^^^^^
source.ts meta.arrow.ts meta.return.type.arrow.ts support.type.primitive.ts
^^
source.ts meta.arrow.ts meta.return.type.arrow.ts
>{
^
source.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.block.ts
> var r = true;
^^
source.ts meta.block.ts
^^^
source.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.block.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.block.ts meta.var.expr.ts
^^^^
source.ts meta.block.ts meta.var.expr.ts constant.language.boolean.true.ts
^
source.ts meta.block.ts punctuation.terminator.statement.ts
^^
source.ts meta.block.ts
> return true
^^
source.ts meta.block.ts
^^^^^^
source.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.block.ts
^^^^
source.ts meta.block.ts constant.language.boolean.true.ts
^^
source.ts meta.block.ts
>}
^
source.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts
>
^
source.ts

13
tests/cases/Issue405.ts Normal file
Просмотреть файл

@ -0,0 +1,13 @@
function myFunction1
(a: string)
{
var r = true;
return true
}
function myFunction2
(a: string): boolean
{
var r = true;
return true
}