Skip to content

Commit 305f7e2

Browse files
mrochmichaelgmcd
authored andcommitted
Fix highlighting of function calls with Flow type args
Fixes #43 Similar to gandm/language-babel#527
1 parent 290d168 commit 305f7e2

File tree

6 files changed

+548
-16
lines changed

6 files changed

+548
-16
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
.vscode
1+
.vscode/*
2+
!.vscode/tasks.json
3+
!.vscode/launch.json
24
.DS_Store
35
.vimrc
46
tags
57
node_modules
6-
dist
8+
dist

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// A launch configuration that launches the extension inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"runtimeExecutable": "${execPath}",
13+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
14+
}
15+
]
16+
}

grammars/Babel-Language.json

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,30 @@
741741
}
742742
]
743743
},
744+
"type-argument-brackets": {
745+
"patterns": [
746+
{
747+
"comment": "Type arguments. This is complicated since we don't want to match things like foo < 123 || bar > baz",
748+
"name": "meta.type-arguments.flowtype",
749+
"begin": "\\s*+(<)(?=((?:(?>[^<>]+)|<\\g<-1>>)*)>)",
750+
"end": "\\s*(>)",
751+
"endCaptures": {
752+
"1": { "name": "punctuation.flowtype" }
753+
},
754+
"beginCaptures": {
755+
"1": { "name": "punctuation.flowtype" }
756+
},
757+
"patterns": [
758+
{
759+
"include": "#flowtype-parse-types"
760+
},
761+
{
762+
"include": "#literal-comma"
763+
}
764+
]
765+
}
766+
]
767+
},
744768
"square-brackets": {
745769
"patterns": [
746770
{
@@ -2146,6 +2170,8 @@
21462170
"include": "#literal-keywords"
21472171
},
21482172
{
2173+
"comment": "A new expression with no type params or arguments, like new Foo()",
2174+
"name": "meta.new-class.without-arguments.js",
21492175
"match": "(?<!\\.)\\s*+(\\bnew\\b)\\s*+((\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?(\\()\\s*+(\\)))",
21502176
"captures": {
21512177
"1": {
@@ -2172,7 +2198,24 @@
21722198
}
21732199
},
21742200
{
2175-
"begin": "(?<!\\.)\\s*+(\\bnew\\b)\\s*+((\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?(?=\\())",
2201+
"comment": "A new expression with type params and no arguments, like new Foo<string>()",
2202+
"name": "meta.new-class.without-arguments.js",
2203+
"begin": "(?<!\\.)\\s*+(\\bnew\\b)\\s*+((\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?\\s*+(?=(<(?:(?>[^<>]+)|\\g<-1>)*>)\\s*+(\\()\\s*+(\\))))",
2204+
"end": "(?=.)",
2205+
"applyEndPatternLast": 1,
2206+
"beginCaptures": {
2207+
"1": { "name": "keyword.operator.new.js" },
2208+
"2": { "name": "meta.function-call.without-arguments.js" },
2209+
"3": { "name": "keyword.operator.private.js" },
2210+
"4": { "name": "entity.name.type.instance.js" },
2211+
"5": { "name": "keyword.operator.existential.js" }
2212+
},
2213+
"patterns": [{ "include": "#type-argument-brackets" }, { "include": "#round-brackets" }]
2214+
},
2215+
{
2216+
"comment": "A new expression with arguments and maybe type params, like new Foo<string>(123)",
2217+
"name": "meta.new-class.with-arguments.js",
2218+
"begin": "(?<!\\.)\\s*+(\\bnew\\b)\\s*+((\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?\\s*+(?=(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+\\())",
21762219
"end": "(?=.)",
21772220
"applyEndPatternLast": 1,
21782221
"beginCaptures": {
@@ -2193,6 +2236,9 @@
21932236
}
21942237
},
21952238
"patterns": [
2239+
{
2240+
"include": "#type-argument-brackets"
2241+
},
21962242
{
21972243
"include": "#round-brackets"
21982244
}
@@ -2202,6 +2248,7 @@
22022248
"include": "#literal-operators"
22032249
},
22042250
{
2251+
"comment": "A call expression with no type params or arguments, like foo()",
22052252
"name": "meta.function-call.without-arguments.js",
22062253
"match": "(?<!\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?(\\()\\s*+(\\))",
22072254
"captures": {
@@ -2223,9 +2270,22 @@
22232270
}
22242271
},
22252272
{
2226-
"comment": "maybe in array form e.g. foo[bar]()",
2273+
"comment": "A call expression with type params and no arguments, like foo<string>()",
22272274
"name": "meta.function-call.without-arguments.js",
2228-
"begin": "(?<!\\.)\\s*+((\\bnew\\b)*)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)(?=\\s*(\\[(?:(?>[^\\[\\]]+)|\\g<-1>)*\\])\\s*+\\(\\s*+\\))",
2275+
"begin": "(?<!\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?\\s*+(?=(<(?:(?>[^<>]+)|\\g<-1>)*>)\\s*+(\\()\\s*+(\\)))",
2276+
"end": "(?=.)",
2277+
"applyEndPatternLast": 1,
2278+
"beginCaptures": {
2279+
"1": { "name": "keyword.operator.private.js" },
2280+
"2": { "name": "entity.name.function.js" },
2281+
"3": { "name": "keyword.operator.existential.js" }
2282+
},
2283+
"patterns": [{ "include": "#type-argument-brackets" }, { "include": "#round-brackets" }]
2284+
},
2285+
{
2286+
"comment": "maybe in array form e.g. foo[bar]() or foo[bar]<string>()",
2287+
"name": "meta.function-call.without-arguments.js",
2288+
"begin": "(?<!\\.)\\s*+((\\bnew\\b)*)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)(?=\\s*(\\[(?:(?>[^\\[\\]]+)|\\g<-1>)*\\])\\s*+(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+\\(\\s*+\\))",
22292289
"end": "(?=.)",
22302290
"applyEndPatternLast": 1,
22312291
"beginCaptures": {
@@ -2243,14 +2303,18 @@
22432303
{
22442304
"include": "#square-brackets"
22452305
},
2306+
{
2307+
"include": "#type-argument-brackets"
2308+
},
22462309
{
22472310
"include": "#round-brackets"
22482311
}
22492312
]
22502313
},
22512314
{
2315+
"comment": "A call expression with arguments and maybe type params, like foo(123) or foo<string>(123)",
22522316
"name": "meta.function-call.with-arguments.js",
2253-
"begin": "(?<!\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?(?=\\()",
2317+
"begin": "(?<!\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(\\?\\.)?\\s*+(?=(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+\\()",
22542318
"end": "(?=.)",
22552319
"applyEndPatternLast": 1,
22562320
"beginCaptures": {
@@ -2265,15 +2329,18 @@
22652329
}
22662330
},
22672331
"patterns": [
2332+
{
2333+
"include": "#type-argument-brackets"
2334+
},
22682335
{
22692336
"include": "#round-brackets"
22702337
}
22712338
]
22722339
},
22732340
{
2274-
"comment": "maybe in array form e.g. foo[bar]()",
2275-
"name": "meta.function-call.without-arguments.js",
2276-
"begin": "(?<!\\.)\\s*+((\\bnew\\b)*)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\g<-1>)*\\])\\s*+\\()",
2341+
"comment": "maybe in array form e.g. foo[bar](123)",
2342+
"name": "meta.function-call.with-arguments.js",
2343+
"begin": "(?<!\\.)\\s*+((\\bnew\\b)*)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\g<-1>)*\\])\\s*+(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+\\()",
22772344
"end": "(?=.)",
22782345
"applyEndPatternLast": 1,
22792346
"beginCaptures": {
@@ -2291,6 +2358,9 @@
22912358
{
22922359
"include": "#square-brackets"
22932360
},
2361+
{
2362+
"include": "#type-argument-brackets"
2363+
},
22942364
{
22952365
"include": "#round-brackets"
22962366
}
@@ -2704,7 +2774,7 @@
27042774
{
27052775
"name": "meta.method-call.without-arguments.js",
27062776
"comment": "e.g CONSTNAME.method() or CONST.method[p]()",
2707-
"begin": "\\s*+(\\#?)((?:[\\p{Lu}])(?:[$_\\p{Lu}\\p{Nd}])*+)\\s*+(?:(\\?\\.)|(\\.))\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+(\\(\\s*+\\)))",
2777+
"begin": "\\s*+(\\#?)((?:[\\p{Lu}])(?:[$_\\p{Lu}\\p{Nd}])*+)\\s*+(?:(\\?\\.)|(\\.))\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+(\\(\\s*+\\)))",
27082778
"end": "(?=.)",
27092779
"applyEndPatternLast": 1,
27102780
"beginCaptures": {
@@ -2731,6 +2801,9 @@
27312801
{
27322802
"include": "#square-brackets"
27332803
},
2804+
{
2805+
"include": "#type-argument-brackets"
2806+
},
27342807
{
27352808
"include": "#round-brackets"
27362809
}
@@ -2774,7 +2847,7 @@
27742847
{
27752848
"name": "meta.method-call.with-arguments.js",
27762849
"comment": "e.g CONSTNAME.method()",
2777-
"begin": "\\s*+(\\#?)((?:[\\p{Lu}])(?:[$_\\p{Lu}\\p{Nd}])*+)\\s*+(?:(\\?\\.)|(\\.))\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+\\()",
2850+
"begin": "\\s*+(\\#?)((?:[\\p{Lu}])(?:[$_\\p{Lu}\\p{Nd}])*+)\\s*+(?:(\\?\\.)|(\\.))\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+\\()",
27782851
"end": "(?=.)",
27792852
"applyEndPatternLast": 1,
27802853
"beginCaptures": {
@@ -2801,6 +2874,9 @@
28012874
{
28022875
"include": "#square-brackets"
28032876
},
2877+
{
2878+
"include": "#type-argument-brackets"
2879+
},
28042880
{
28052881
"include": "#round-brackets"
28062882
}
@@ -2809,7 +2885,7 @@
28092885
{
28102886
"name": "meta.method-call.with-arguments.js",
28112887
"comment": "e.g Abc.aaa()",
2812-
"begin": "\\s*+(\\#?)((?:[\\p{Lu}])(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?:(\\?\\.)|(\\.))\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+\\()",
2888+
"begin": "\\s*+(\\#?)((?:[\\p{Lu}])(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?:(\\?\\.)|(\\.))\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+\\()",
28132889
"end": "(?=.)",
28142890
"applyEndPatternLast": 1,
28152891
"beginCaptures": {
@@ -2835,13 +2911,16 @@
28352911
"patterns": [
28362912
{
28372913
"include": "#round-brackets"
2914+
},
2915+
{
2916+
"include": "#type-argument-brackets"
28382917
}
28392918
]
28402919
},
28412920
{
28422921
"name": "meta.method-call.without-arguments.js",
28432922
"comment": "e.g .aaa()",
2844-
"begin": "(?<=\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+(\\(\\s*+\\)))",
2923+
"begin": "(?<=\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+(\\(\\s*+\\)))",
28452924
"end": "(?=.)",
28462925
"applyEndPatternLast": 1,
28472926
"beginCaptures": {
@@ -2859,6 +2938,9 @@
28592938
{
28602939
"include": "#square-brackets"
28612940
},
2941+
{
2942+
"include": "#type-argument-brackets"
2943+
},
28622944
{
28632945
"include": "#round-brackets"
28642946
}
@@ -2867,7 +2949,7 @@
28672949
{
28682950
"name": "meta.method-call.with-arguments.js",
28692951
"comment": "e.g .aaa()",
2870-
"begin": "(?<=\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+\\()",
2952+
"begin": "(?<=\\.)\\s*+(\\#?)((?:[$_\\p{L}\\p{Nl}]|\\\\u\\h{4}|\\\\u{\\h+})(?:[$_\\p{L}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Nl}\\p{Pc}\\x{200C}\\x{200D}]|\\\\u\\h{4}|\\\\u{\\h+})*+)\\s*+(?=(\\[(?:(?>[^\\[\\]]+)|\\\\g<-1>)*\\])?+\\s*+(<(?:(?>[^<>]+)|\\g<-1>)*>)?\\s*+\\()",
28712953
"end": "(?=.)",
28722954
"applyEndPatternLast": 1,
28732955
"beginCaptures": {
@@ -2882,6 +2964,9 @@
28822964
{
28832965
"include": "#square-brackets"
28842966
},
2967+
{
2968+
"include": "#type-argument-brackets"
2969+
},
28852970
{
28862971
"include": "#round-brackets"
28872972
}

package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"postinstall": "node ./node_modules/vscode/bin/install",
2626
"prettier:stdin": "prettier --single-quote --print-width 100 --trailing-comma all --write",
2727
"prettier": "npm run prettier:stdin -- '**/*.ts' '**/*.json'",
28-
"test": "jest"
28+
"test": "vscode-tmgrammar-test -s source.js -g grammars/Babel-Language.json -t 'tests/*.js'"
2929
},
3030
"repository": {
3131
"type": "git",
@@ -174,7 +174,8 @@
174174
"lint-staged": "^8.1.4",
175175
"prettier": "^1.16.4",
176176
"typescript": "^3.3.3",
177-
"vscode": "^1.1.35"
177+
"vscode": "^1.1.35",
178+
"vscode-tmgrammar-test": "0.0.5"
178179
},
179180
"husky": {
180181
"hooks": {

0 commit comments

Comments
 (0)