Skip to content

Commit bd74145

Browse files
committed
Fix template concat, stil need to fix template parts.
So far this works only if the cursor is *after* the first character. This will later need to be moved to the syntax repo and synched back.
1 parent a57d0ef commit bd74145

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

analysis/tests/src/expected/Completion.res.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1536,10 +1536,10 @@ Completable: Cpath Value[red]
15361536

15371537
Complete src/Completion.res 402:24
15381538
posCursor:[402:24] posNoWhite:[402:23] Found expr:[400:14->402:31]
1539-
Pexp_apply ...__ghost__[0:-1->0:-1] (...[401:16->402:27], ...[402:27->402:31])
1540-
posCursor:[402:24] posNoWhite:[402:23] Found expr:[401:16->402:27]
1541-
Pexp_apply ...__ghost__[0:-1->0:-1] (...[401:16->402:27], ...[402:24->402:27])
1542-
posCursor:[402:24] posNoWhite:[402:23] Found expr:[401:16->402:27]
1539+
Pexp_apply ...__ghost__[0:-1->0:-1] (...[400:14->402:27], ...[402:27->402:31])
1540+
posCursor:[402:24] posNoWhite:[402:23] Found expr:[400:14->402:27]
1541+
Pexp_apply ...__ghost__[0:-1->0:-1] (...[400:14->402:24], ...[402:24->402:27])
1542+
posCursor:[402:24] posNoWhite:[402:23] Found expr:[400:14->402:24]
15431543
Pexp_apply ...__ghost__[0:-1->0:-1] (...[400:14->401:16], ...[401:16->402:24])
15441544
posCursor:[402:24] posNoWhite:[402:23] Found expr:[401:16->402:24]
15451545
Completable: Cnone

analysis/vendor/res_outcome_printer/res_core.ml

+9-16
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,11 @@ and parseTemplateExpr ?(prefix = "js") p =
21552155
let op = Location.mknoloc (Longident.Lident "^") in
21562156
Ast_helper.Exp.ident op
21572157
in
2158-
let rec parseParts acc =
2158+
let concat (e1: Parsetree.expression) (e2: Parsetree.expression) =
2159+
let loc = mkLoc e1.pexp_loc.loc_start e2.pexp_loc.loc_end in
2160+
Ast_helper.Exp.apply ~attrs:[templateLiteralAttr] ~loc hiddenOperator
2161+
[(Nolabel, e1); (Nolabel, e2)] in
2162+
let rec parseParts (acc: Parsetree.expression) =
21592163
let startPos = p.Parser.startPos in
21602164
Parser.nextTemplateLiteralToken p;
21612165
match p.token with
@@ -2166,25 +2170,18 @@ and parseTemplateExpr ?(prefix = "js") p =
21662170
Ast_helper.Exp.constant ~attrs:[templateLiteralAttr] ~loc
21672171
(Pconst_string (txt, Some prefix))
21682172
in
2169-
Ast_helper.Exp.apply ~attrs:[templateLiteralAttr] ~loc hiddenOperator
2170-
[(Nolabel, acc); (Nolabel, str)]
2173+
concat acc str
21712174
| TemplatePart txt ->
21722175
Parser.next p;
21732176
let loc = mkLoc startPos p.prevEndPos in
21742177
let expr = parseExprBlock p in
2175-
let fullLoc = mkLoc startPos p.prevEndPos in
21762178
let str =
21772179
Ast_helper.Exp.constant ~attrs:[templateLiteralAttr] ~loc
21782180
(Pconst_string (txt, Some prefix))
21792181
in
21802182
let next =
2181-
let a =
2182-
Ast_helper.Exp.apply ~attrs:[templateLiteralAttr] ~loc:fullLoc
2183-
hiddenOperator
2184-
[(Nolabel, acc); (Nolabel, str)]
2185-
in
2186-
Ast_helper.Exp.apply ~loc:fullLoc hiddenOperator
2187-
[(Nolabel, a); (Nolabel, expr)]
2183+
let a = concat acc str in
2184+
concat a expr
21882185
in
21892186
parseParts next
21902187
| token ->
@@ -2203,15 +2200,11 @@ and parseTemplateExpr ?(prefix = "js") p =
22032200
Parser.next p;
22042201
let constantLoc = mkLoc startPos p.prevEndPos in
22052202
let expr = parseExprBlock p in
2206-
let fullLoc = mkLoc startPos p.prevEndPos in
22072203
let str =
22082204
Ast_helper.Exp.constant ~attrs:[templateLiteralAttr] ~loc:constantLoc
22092205
(Pconst_string (txt, Some prefix))
22102206
in
2211-
let next =
2212-
Ast_helper.Exp.apply ~attrs:[templateLiteralAttr] ~loc:fullLoc
2213-
hiddenOperator
2214-
[(Nolabel, str); (Nolabel, expr)]
2207+
let next = concat str expr
22152208
in
22162209
parseParts next
22172210
| token ->

0 commit comments

Comments
 (0)