Skip to content

Commit b1dbc3c

Browse files
committed
Sync latest syntax
1 parent ae2c1d9 commit b1dbc3c

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Completable: Cpath Value[y2].content.""
159159
}]
160160

161161
Hover src/Hover.res 197:4
162-
{"contents": "```rescript\nCompV4.props<int, string> => React.element\n```\n\n\n```\n \n```\n```rescript\ntype CompV4.props<'n, 's> = {?n: 'n, s: 's}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C190%2C2%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype React.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n\n---\n"}
162+
{"contents": "```rescript\nCompV4.props<int, string> => React.element\n```\n\n\n```\n \n```\n```rescript\ntype CompV4.props<'n, 's> = {n?: 'n, s: 's}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C190%2C2%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype React.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n\n---\n"}
163163

164164
Hover src/Hover.res 202:16
165165
{"contents": "```rescript\nuseR\n```\n\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list<option<r<float>>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n\n---\n"}

analysis/vendor/res_outcome_printer/res_core.ml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,13 +2691,9 @@ and parseBracedOrRecordExpr p =
26912691
Parser.expect Lbrace p;
26922692
match p.Parser.token with
26932693
| Rbrace ->
2694-
Parser.err p (Diagnostics.unexpected Rbrace p.breadcrumbs);
26952694
Parser.next p;
26962695
let loc = mkLoc startPos p.prevEndPos in
2697-
let braces = makeBracesAttr loc in
2698-
Ast_helper.Exp.construct ~attrs:[braces] ~loc
2699-
(Location.mkloc (Longident.Lident "()") loc)
2700-
None
2696+
Ast_helper.Exp.record ~loc [] None
27012697
| DotDotDot ->
27022698
(* beginning of record spread, parse record *)
27032699
Parser.next p;
@@ -4286,6 +4282,7 @@ and parseFieldDeclaration p =
42864282
match p.token with
42874283
| _ -> parseLident p
42884284
in
4285+
let optional = parseOptionalLabel p in
42894286
let name = Location.mkloc lident loc in
42904287
let typ =
42914288
match p.Parser.token with
@@ -4296,7 +4293,7 @@ and parseFieldDeclaration p =
42964293
Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} []
42974294
in
42984295
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
4299-
Ast_helper.Type.field ~attrs ~loc ~mut name typ
4296+
(optional, Ast_helper.Type.field ~attrs ~loc ~mut name typ)
43004297

43014298
and parseFieldDeclarationRegion p =
43024299
let startPos = p.Parser.startPos in
@@ -4488,7 +4485,10 @@ and parseConstrDeclArgs p =
44884485
~closing:Rbrace ~f:parseFieldDeclarationRegion p
44894486
| attrs ->
44904487
let first =
4491-
let field = parseFieldDeclaration p in
4488+
let optional, field = parseFieldDeclaration p in
4489+
let attrs =
4490+
if optional then optionalAttr :: attrs else attrs
4491+
in
44924492
Parser.expect Comma p;
44934493
{field with Parsetree.pld_attributes = attrs}
44944494
in
@@ -4885,13 +4885,15 @@ and parseRecordOrObjectDecl p =
48854885
| _ ->
48864886
Parser.leaveBreadcrumb p Grammar.RecordDecl;
48874887
let fields =
4888+
(* XXX *)
48884889
match attrs with
48894890
| [] ->
48904891
parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
48914892
~closing:Rbrace ~f:parseFieldDeclarationRegion p
48924893
| attr :: _ as attrs ->
48934894
let first =
4894-
let field = parseFieldDeclaration p in
4895+
let optional, field = parseFieldDeclaration p in
4896+
let attrs = if optional then optionalAttr :: attrs else attrs in
48954897
Parser.optional p Comma |> ignore;
48964898
{
48974899
field with
@@ -4907,13 +4909,6 @@ and parseRecordOrObjectDecl p =
49074909
:: parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
49084910
~closing:Rbrace ~f:parseFieldDeclarationRegion p
49094911
in
4910-
let () =
4911-
match fields with
4912-
| [] ->
4913-
Parser.err ~startPos p
4914-
(Diagnostics.message "A record needs at least one field")
4915-
| _ -> ()
4916-
in
49174912
Parser.expect Rbrace p;
49184913
Parser.eatBreadcrumb p;
49194914
(None, Asttypes.Public, Parsetree.Ptype_record fields))

analysis/vendor/res_outcome_printer/res_outcome_printer.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,9 @@ and printRecordDeclRowDoc (name, mut, opt, arg) =
526526
Doc.group
527527
(Doc.concat
528528
[
529-
(if opt then Doc.text "?" else Doc.nil);
530529
(if mut then Doc.text "mutable " else Doc.nil);
531530
printIdentLike ~allowUident:false name;
531+
(if opt then Doc.text "?" else Doc.nil);
532532
Doc.text ": ";
533533
printOutTypeDoc arg;
534534
])
@@ -563,7 +563,8 @@ let printTypeParameterDoc (typ, (co, cn)) =
563563
(if typ = "_" then Doc.text "_" else Doc.text ("'" ^ typ));
564564
]
565565

566-
let rec printOutSigItemDoc ?(printNameAsIs=false) (outSigItem : Outcometree.out_sig_item) =
566+
let rec printOutSigItemDoc ?(printNameAsIs = false)
567+
(outSigItem : Outcometree.out_sig_item) =
567568
match outSigItem with
568569
| Osig_class _ | Osig_class_type _ -> Doc.nil
569570
| Osig_ellipsis -> Doc.dotdotdot
@@ -728,7 +729,8 @@ let rec printOutSigItemDoc ?(printNameAsIs=false) (outSigItem : Outcometree.out_
728729
[
729730
attrs;
730731
kw;
731-
if printNameAsIs then Doc.text outTypeDecl.otype_name else printIdentLike ~allowUident:false outTypeDecl.otype_name;
732+
(if printNameAsIs then Doc.text outTypeDecl.otype_name
733+
else printIdentLike ~allowUident:false outTypeDecl.otype_name);
732734
typeParams;
733735
kind;
734736
]);
@@ -823,7 +825,7 @@ and printOutSignatureDoc (signature : Outcometree.out_sig_item list) =
823825
let doc = printOutTypeExtensionDoc te in
824826
loop items (doc :: acc)
825827
| item :: items ->
826-
let doc = printOutSigItemDoc item in
828+
let doc = printOutSigItemDoc ~printNameAsIs:false item in
827829
loop items (doc :: acc)
828830
in
829831
match loop signature [] with

analysis/vendor/res_outcome_printer/res_outcome_printer.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ val setup : unit lazy_t [@@live]
1313

1414
(* Needed for e.g. the playground to print typedtree data *)
1515
val printOutTypeDoc : Outcometree.out_type -> Res_doc.t [@@live]
16-
val printOutSigItemDoc : ?printNameAsIs: bool -> Outcometree.out_sig_item -> Res_doc.t [@@live]
16+
val printOutSigItemDoc :
17+
?printNameAsIs:bool -> Outcometree.out_sig_item -> Res_doc.t
18+
[@@live]

analysis/vendor/res_outcome_printer/res_printer.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3651,13 +3651,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
36513651
[(Nolabel, lhs); (Nolabel, rhs)] )
36523652
when not
36533653
(ParsetreeViewer.isBinaryExpression lhs
3654-
|| ParsetreeViewer.isBinaryExpression rhs) ->
3654+
|| ParsetreeViewer.isBinaryExpression rhs
3655+
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
3656+
<> Doc.nil) ->
36553657
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
36563658
let lhsDoc = printOperand ~isLhs:true lhs op in
36573659
let rhsDoc = printOperand ~isLhs:false rhs op in
36583660
Doc.group
36593661
(Doc.concat
36603662
[
3663+
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
36613664
lhsDoc;
36623665
(match (lhsHasCommentBelow, op) with
36633666
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]

0 commit comments

Comments
 (0)