Skip to content

Commit 52bb30d

Browse files
committed
Update jsdoc type and variable recognition
Fixes #276
1 parent 01b3bf1 commit 52bb30d

7 files changed

+865
-286
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 175 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,42 +1597,6 @@ repository:
15971597
patterns:
15981598
- include: '#expression'
15991599

1600-
comment:
1601-
patterns:
1602-
- name: comment.block.documentation.ts
1603-
begin: /\*\*(?!/)
1604-
end: \*/
1605-
captures:
1606-
'0': {name: punctuation.definition.comment.ts}
1607-
patterns:
1608-
- include: '#docblock'
1609-
- name: comment.block.ts
1610-
begin: /\*
1611-
end: \*/
1612-
captures:
1613-
'0': {name: punctuation.definition.comment.ts}
1614-
- begin: (^[ \t]+)?(?=//)
1615-
beginCaptures:
1616-
'1': {name: punctuation.whitespace.comment.leading.ts}
1617-
end: (?=$)
1618-
patterns:
1619-
- name: comment.line.double-slash.ts
1620-
begin: //
1621-
beginCaptures:
1622-
'0': {name: punctuation.definition.comment.ts}
1623-
end: (?=$)
1624-
1625-
docblock:
1626-
patterns:
1627-
- name: storage.type.class.jsdoc
1628-
match: (?<!\w)@(abstract|access|alias|arg|argument|async|attribute|augments|author|beta|borrows|bubbes|callback|chainable|class|classdesc|code|config|const|constant|constructor|constructs|copyright|default|defaultvalue|define|deprecated|desc|description|dict|emits|enum|event|example|exports?|extends|extension|extension_for|extensionfor|external|file|fileoverview|final|fires|for|function|global|host|ignore|implements|inherit[Dd]oc|inner|instance|interface|kind|lends|license|listens|main|member|memberof|method|mixex|mixins?|module|name|namespace|nocollapse|nosideeffects|override|overview|package|param|preserve|private|prop|property|protected|public|read[Oo]nly|record|require[ds]|returns?|see|since|static|struct|submodule|summary|template|this|throws|todo|tutorial|type|typedef|unrestricted|uses|var|variation|version|virtual|writeOnce)\b
1629-
- match: ({\b(?:[_$[:alpha:]][_$[:alnum:]]*)\b})\s+\b([_$[:alpha:]][_$[:alnum:]]*)\b\s*((?:(?!\*\/).)*)
1630-
captures:
1631-
'0': {name: other.meta.jsdoc}
1632-
'1': {name: entity.name.type.instance.jsdoc}
1633-
'2': {name: variable.other.jsdoc}
1634-
'3': {name: other.description.jsdoc}
1635-
16361600
literal:
16371601
name: literal.ts
16381602
patterns:
@@ -1728,4 +1692,179 @@ repository:
17281692
name: storage.type.property.ts
17291693
match: (?<!\.|\$)\b(get|set)\b(?!\$)
17301694

1695+
comment:
1696+
patterns:
1697+
- name: comment.block.documentation.ts
1698+
begin: /\*\*(?!/)
1699+
end: \*/
1700+
captures:
1701+
'0': {name: punctuation.definition.comment.ts}
1702+
patterns:
1703+
- include: '#docblock'
1704+
- name: comment.block.ts
1705+
begin: /\*
1706+
end: \*/
1707+
captures:
1708+
'0': {name: punctuation.definition.comment.ts}
1709+
- begin: (^[ \t]+)?(?=//)
1710+
beginCaptures:
1711+
'1': {name: punctuation.whitespace.comment.leading.ts}
1712+
end: (?=$)
1713+
patterns:
1714+
- name: comment.line.double-slash.ts
1715+
begin: //
1716+
beginCaptures:
1717+
'0': {name: punctuation.definition.comment.ts}
1718+
end: (?=$)
1719+
1720+
docblock:
1721+
patterns:
1722+
- name: storage.type.class.jsdoc
1723+
match: (?<!\w)@(abstract|access|alias|arg|argument|async|attribute|augments|author|beta|borrows|bubbes|callback|chainable|class|classdesc|code|config|const|constant|constructor|constructs|copyright|default|defaultvalue|define|deprecated|desc|description|dict|emits|enum|event|example|exports?|extends|extension|extension_for|extensionfor|external|file|fileoverview|final|fires|for|function|global|host|ignore|implements|inherit[Dd]oc|inner|instance|interface|kind|lends|license|listens|main|member|memberof|method|mixex|mixins?|module|name|namespace|nocollapse|nosideeffects|override|overview|package|param|preserve|private|prop|property|protected|public|read[Oo]nly|record|require[ds]|returns?|see|since|static|struct|submodule|summary|template|this|throws|todo|tutorial|type|typedef|unrestricted|uses|var|variation|version|virtual|writeOnce)\b
1724+
- match: |-
1725+
(?x)
1726+
(?:(?<=@param)|(?<=@type))
1727+
\s+
1728+
({(?:
1729+
\* | # {*} any type
1730+
\? | # {?} unknown type
1731+
1732+
(?: # Check for a prefix
1733+
\? | # {?string} nullable type
1734+
! | # {!string} non-nullable type
1735+
\.{3} # {...string} variable number of parameters
1736+
)?
1737+
1738+
(?:
1739+
\( # Opening bracket of multiple types with parenthesis {(string|number)}
1740+
[a-zA-Z_$]+
1741+
(?:
1742+
(?:
1743+
[\w$]*
1744+
(?:\[\])? # {(string[]|number)} type application, an array of strings or a number
1745+
) |
1746+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1747+
)
1748+
(?:
1749+
[\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback
1750+
[a-zA-Z_$]+
1751+
(?:
1752+
(?:
1753+
[\w$]*
1754+
(?:\[\])? # {(string|number[])} type application, a string or an array of numbers
1755+
) |
1756+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1757+
)
1758+
)*
1759+
\) |
1760+
[a-zA-Z_$]+
1761+
(?:
1762+
(?:
1763+
[\w$]*
1764+
(?:\[\])? # {string[]|number} type application, an array of strings or a number
1765+
) |
1766+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1767+
)
1768+
(?:
1769+
[\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback
1770+
[a-zA-Z_$]+
1771+
(?:
1772+
[\w$]* |
1773+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1774+
)
1775+
)*
1776+
)
1777+
# Check for suffix
1778+
(?:\[\])? # {string[]} type application, an array of strings
1779+
=? # {string=} optional parameter
1780+
)})
1781+
\s+
1782+
(
1783+
\[ # [foo] optional parameter
1784+
\s*
1785+
(?:
1786+
[a-zA-Z_$][\w$]*
1787+
(?:
1788+
(?:\[\])? # Foo[].bar properties within an array
1789+
\. # Foo.Bar namespaced parameter
1790+
[a-zA-Z_$][\w$]*
1791+
)*
1792+
(?:
1793+
\s*
1794+
= # [foo=bar] Default parameter value
1795+
\s*
1796+
[\w$\s]*
1797+
)?
1798+
)
1799+
\s*
1800+
\] |
1801+
(?:
1802+
[a-zA-Z_$][\w$]*
1803+
(?:
1804+
(?:\[\])? # Foo[].bar properties within an array
1805+
\. # Foo.Bar namespaced parameter
1806+
[a-zA-Z_$][\w$]*
1807+
)*
1808+
)?
1809+
)
1810+
\s+
1811+
((?:(?!\*\/).)*) # The type description
1812+
captures:
1813+
'0': { name: other.meta.jsdoc }
1814+
'1': { name: entity.name.type.instance.jsdoc }
1815+
'2': { name: variable.other.jsdoc }
1816+
'3': { name: other.description.jsdoc }
1817+
- match: |-
1818+
(?x)
1819+
({(?:
1820+
\* | # {*} any type
1821+
\? | # {?} unknown type
1822+
1823+
(?: # Check for a prefix
1824+
\? | # {?string} nullable type
1825+
! | # {!string} non-nullable type
1826+
\.{3} # {...string} variable number of parameters
1827+
)?
1828+
1829+
(?:
1830+
\( # Opening bracket of multiple types with parenthesis {(string|number)}
1831+
[a-zA-Z_$]+
1832+
(?:
1833+
[\w$]* |
1834+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1835+
)
1836+
(?:
1837+
[\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback
1838+
[a-zA-Z_$]+
1839+
(?:
1840+
[\w$]* |
1841+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1842+
)
1843+
)*
1844+
\) |
1845+
[a-zA-Z_$]+
1846+
(?:
1847+
[\w$]* |
1848+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1849+
)
1850+
(?:
1851+
[\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback
1852+
[a-zA-Z_$]+
1853+
(?:
1854+
[\w$]* |
1855+
<[\w$]+(?:,\s+[\w$]+)*> # {Array<string>} or {Object<string, number>} type application
1856+
)
1857+
)*
1858+
)
1859+
# Check for suffix
1860+
(?:\[\])? # {string[]} type application, an array of strings
1861+
=? # {string=} optional parameter
1862+
)})
1863+
\s+
1864+
((?:(?!\*\/).)*) # The type description
1865+
captures:
1866+
'0': { name: other.meta.jsdoc }
1867+
'1': { name: entity.name.type.instance.jsdoc }
1868+
'2': { name: other.description.jsdoc }
1869+
17311870
...

0 commit comments

Comments
 (0)