Skip to content

Sync latest syntax #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Completable: Cpath Value[y2].content.""
}]

Hover src/Hover.res 197:4
{"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"}
{"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"}

Hover src/Hover.res 202:16
{"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"}
Expand Down
25 changes: 10 additions & 15 deletions analysis/vendor/res_outcome_printer/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2691,13 +2691,9 @@ and parseBracedOrRecordExpr p =
Parser.expect Lbrace p;
match p.Parser.token with
| Rbrace ->
Parser.err p (Diagnostics.unexpected Rbrace p.breadcrumbs);
Parser.next p;
let loc = mkLoc startPos p.prevEndPos in
let braces = makeBracesAttr loc in
Ast_helper.Exp.construct ~attrs:[braces] ~loc
(Location.mkloc (Longident.Lident "()") loc)
None
Ast_helper.Exp.record ~loc [] None
| DotDotDot ->
(* beginning of record spread, parse record *)
Parser.next p;
Expand Down Expand Up @@ -4286,6 +4282,7 @@ and parseFieldDeclaration p =
match p.token with
| _ -> parseLident p
in
let optional = parseOptionalLabel p in
let name = Location.mkloc lident loc in
let typ =
match p.Parser.token with
Expand All @@ -4296,7 +4293,7 @@ and parseFieldDeclaration p =
Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} []
in
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
Ast_helper.Type.field ~attrs ~loc ~mut name typ
(optional, Ast_helper.Type.field ~attrs ~loc ~mut name typ)

and parseFieldDeclarationRegion p =
let startPos = p.Parser.startPos in
Expand Down Expand Up @@ -4488,7 +4485,10 @@ and parseConstrDeclArgs p =
~closing:Rbrace ~f:parseFieldDeclarationRegion p
| attrs ->
let first =
let field = parseFieldDeclaration p in
let optional, field = parseFieldDeclaration p in
let attrs =
if optional then optionalAttr :: attrs else attrs
in
Parser.expect Comma p;
{field with Parsetree.pld_attributes = attrs}
in
Expand Down Expand Up @@ -4885,13 +4885,15 @@ and parseRecordOrObjectDecl p =
| _ ->
Parser.leaveBreadcrumb p Grammar.RecordDecl;
let fields =
(* XXX *)
match attrs with
| [] ->
parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
~closing:Rbrace ~f:parseFieldDeclarationRegion p
| attr :: _ as attrs ->
let first =
let field = parseFieldDeclaration p in
let optional, field = parseFieldDeclaration p in
let attrs = if optional then optionalAttr :: attrs else attrs in
Parser.optional p Comma |> ignore;
{
field with
Expand All @@ -4907,13 +4909,6 @@ and parseRecordOrObjectDecl p =
:: parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
~closing:Rbrace ~f:parseFieldDeclarationRegion p
in
let () =
match fields with
| [] ->
Parser.err ~startPos p
(Diagnostics.message "A record needs at least one field")
| _ -> ()
in
Parser.expect Rbrace p;
Parser.eatBreadcrumb p;
(None, Asttypes.Public, Parsetree.Ptype_record fields))
Expand Down
10 changes: 6 additions & 4 deletions analysis/vendor/res_outcome_printer/res_outcome_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ and printRecordDeclRowDoc (name, mut, opt, arg) =
Doc.group
(Doc.concat
[
(if opt then Doc.text "?" else Doc.nil);
(if mut then Doc.text "mutable " else Doc.nil);
printIdentLike ~allowUident:false name;
(if opt then Doc.text "?" else Doc.nil);
Doc.text ": ";
printOutTypeDoc arg;
])
Expand Down Expand Up @@ -563,7 +563,8 @@ let printTypeParameterDoc (typ, (co, cn)) =
(if typ = "_" then Doc.text "_" else Doc.text ("'" ^ typ));
]

let rec printOutSigItemDoc ?(printNameAsIs=false) (outSigItem : Outcometree.out_sig_item) =
let rec printOutSigItemDoc ?(printNameAsIs = false)
(outSigItem : Outcometree.out_sig_item) =
match outSigItem with
| Osig_class _ | Osig_class_type _ -> Doc.nil
| Osig_ellipsis -> Doc.dotdotdot
Expand Down Expand Up @@ -728,7 +729,8 @@ let rec printOutSigItemDoc ?(printNameAsIs=false) (outSigItem : Outcometree.out_
[
attrs;
kw;
if printNameAsIs then Doc.text outTypeDecl.otype_name else printIdentLike ~allowUident:false outTypeDecl.otype_name;
(if printNameAsIs then Doc.text outTypeDecl.otype_name
else printIdentLike ~allowUident:false outTypeDecl.otype_name);
typeParams;
kind;
]);
Expand Down Expand Up @@ -823,7 +825,7 @@ and printOutSignatureDoc (signature : Outcometree.out_sig_item list) =
let doc = printOutTypeExtensionDoc te in
loop items (doc :: acc)
| item :: items ->
let doc = printOutSigItemDoc item in
let doc = printOutSigItemDoc ~printNameAsIs:false item in
loop items (doc :: acc)
in
match loop signature [] with
Expand Down
4 changes: 3 additions & 1 deletion analysis/vendor/res_outcome_printer/res_outcome_printer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ val setup : unit lazy_t [@@live]

(* Needed for e.g. the playground to print typedtree data *)
val printOutTypeDoc : Outcometree.out_type -> Res_doc.t [@@live]
val printOutSigItemDoc : ?printNameAsIs: bool -> Outcometree.out_sig_item -> Res_doc.t [@@live]
val printOutSigItemDoc :
?printNameAsIs:bool -> Outcometree.out_sig_item -> Res_doc.t
[@@live]
5 changes: 4 additions & 1 deletion analysis/vendor/res_outcome_printer/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3651,13 +3651,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
[(Nolabel, lhs); (Nolabel, rhs)] )
when not
(ParsetreeViewer.isBinaryExpression lhs
|| ParsetreeViewer.isBinaryExpression rhs) ->
|| ParsetreeViewer.isBinaryExpression rhs
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
<> Doc.nil) ->
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
let lhsDoc = printOperand ~isLhs:true lhs op in
let rhsDoc = printOperand ~isLhs:false rhs op in
Doc.group
(Doc.concat
[
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
lhsDoc;
(match (lhsHasCommentBelow, op) with
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
Expand Down