diff --git a/analysis/vendor/res_outcome_printer/res_core.ml b/analysis/vendor/res_outcome_printer/res_core.ml index 506ceea3d..8547e4f3d 100644 --- a/analysis/vendor/res_outcome_printer/res_core.ml +++ b/analysis/vendor/res_outcome_printer/res_core.ml @@ -161,6 +161,8 @@ let uncurryAttr = (Location.mknoloc "bs", Parsetree.PStr []) let ternaryAttr = (Location.mknoloc "ns.ternary", Parsetree.PStr []) let ifLetAttr = (Location.mknoloc "ns.iflet", Parsetree.PStr []) let optionalAttr = (Location.mknoloc "ns.optional", Parsetree.PStr []) +let makeAwaitAttr loc = (Location.mkloc "res.await" loc, Parsetree.PStr []) +let makeAsyncAttr loc = (Location.mkloc "res.async" loc, Parsetree.PStr []) let makeExpressionOptional ~optional (e : Parsetree.expression) = if optional then {e with pexp_attributes = optionalAttr :: e.pexp_attributes} @@ -237,6 +239,9 @@ let rec goToClosing closingToken state = (* Madness *) let isEs6ArrowExpression ~inTernary p = Parser.lookahead p (fun state -> + (match state.Parser.token with + | Lident "async" -> Parser.next state + | _ -> ()); match state.Parser.token with | Lident _ | Underscore -> ( Parser.next state; @@ -611,19 +616,22 @@ let parseHashIdent ~startPos p = let parseValuePath p = let startPos = p.Parser.startPos in let rec aux p path = - match p.Parser.token with - | Lident ident -> Longident.Ldot (path, ident) - | Uident uident -> - Parser.next p; - if p.Parser.token = Dot then ( - Parser.expect Dot p; - aux p (Ldot (path, uident))) - else ( - Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs); - path) - | token -> - Parser.err p (Diagnostics.unexpected token p.breadcrumbs); - Longident.Ldot (path, "_") + let startPos = p.Parser.startPos in + let token = p.token in + + Parser.next p; + if p.Parser.token = Dot then ( + Parser.expect Dot p; + + match p.Parser.token with + | Lident ident -> Longident.Ldot (path, ident) + | Uident uident -> aux p (Ldot (path, uident)) + | token -> + Parser.err p (Diagnostics.unexpected token p.breadcrumbs); + Longident.Ldot (path, "_")) + else ( + Parser.err p ~startPos ~endPos:p.prevEndPos (Diagnostics.lident token); + path) in let ident = match p.Parser.token with @@ -631,15 +639,7 @@ let parseValuePath p = Parser.next p; Longident.Lident ident | Uident ident -> - Parser.next p; - let res = - if p.Parser.token = Dot then ( - Parser.expect Dot p; - aux p (Lident ident)) - else ( - Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs); - Longident.Lident ident) - in + let res = aux p (Lident ident) in Parser.nextUnsafe p; res | token -> @@ -2031,6 +2031,16 @@ and parseOperandExpr ~context p = let expr = parseUnaryExpr p in let loc = mkLoc startPos p.prevEndPos in Ast_helper.Exp.assert_ ~loc expr + | Lident "async" + (* we need to be careful when we're in a ternary true branch: + `condition ? ternary-true-branch : false-branch` + Arrow expressions could be of the form: `async (): int => stuff()` + But if we're in a ternary, the `:` of the ternary takes precedence + *) + when isEs6ArrowExpression ~inTernary:(context = TernaryTrueBranchExpr) p + -> + parseAsyncArrowExpression p + | Await -> parseAwaitExpression p | Lazy -> Parser.next p; let expr = parseUnaryExpr p in @@ -2744,6 +2754,21 @@ and parseBracedOrRecordExpr p = let expr = parseRecordExpr ~startPos [] p in Parser.expect Rbrace p; expr + (* + The branch below takes care of the "braced" expression {async}. + The big reason that we need all these branches is that {x} isn't a record with a punned field x, but a braced expression… There's lots of "ambiguity" between a record with a single punned field and a braced expression… + What is {x}? + 1) record {x: x} + 2) expression x which happens to wrapped in braces + Due to historical reasons, we always follow 2 + *) + | Lident "async" when isEs6ArrowExpression ~inTernary:false p -> + let expr = parseAsyncArrowExpression p in + let expr = parseExprBlock ~first:expr p in + Parser.expect Rbrace p; + let loc = mkLoc startPos p.prevEndPos in + let braces = makeBracesAttr loc in + {expr with pexp_attributes = braces :: expr.pexp_attributes} | Uident _ | Lident _ -> ( let startToken = p.token in let valueOrConstructor = parseValueOrConstructor p in @@ -3099,6 +3124,28 @@ and parseExprBlock ?first p = Parser.eatBreadcrumb p; overParseConstrainedOrCoercedOrArrowExpression p blockExpr +and parseAsyncArrowExpression p = + let startPos = p.Parser.startPos in + Parser.expect (Lident "async") p; + let asyncAttr = makeAsyncAttr (mkLoc startPos p.prevEndPos) in + let expr = parseEs6ArrowExpression p in + { + expr with + pexp_attributes = asyncAttr :: expr.pexp_attributes; + pexp_loc = {expr.pexp_loc with loc_start = startPos}; + } + +and parseAwaitExpression p = + let awaitLoc = mkLoc p.Parser.startPos p.endPos in + let awaitAttr = makeAwaitAttr awaitLoc in + Parser.expect Await p; + let expr = parseUnaryExpr p in + { + expr with + pexp_attributes = awaitAttr :: expr.pexp_attributes; + pexp_loc = {expr.pexp_loc with loc_start = awaitLoc.loc_start}; + } + and parseTryExpression p = let startPos = p.Parser.startPos in Parser.expect Try p; diff --git a/analysis/vendor/res_outcome_printer/res_grammar.ml b/analysis/vendor/res_outcome_printer/res_grammar.ml index 44f0e4976..cba9b4bde 100644 --- a/analysis/vendor/res_outcome_printer/res_grammar.ml +++ b/analysis/vendor/res_outcome_printer/res_grammar.ml @@ -147,11 +147,11 @@ let isAtomicTypExprStart = function | _ -> false let isExprStart = function - | Token.True | False | Int _ | String _ | Float _ | Codepoint _ | Backtick - | Underscore (* _ => doThings() *) - | Uident _ | Lident _ | Hash | Lparen | List | Module | Lbracket | Lbrace - | LessThan | Minus | MinusDot | Plus | PlusDot | Bang | Percent | At | If - | Switch | While | For | Assert | Lazy | Try -> + | Token.Assert | At | Await | Backtick | Bang | Codepoint _ | False | Float _ + | For | Hash | If | Int _ | Lazy | Lbrace | Lbracket | LessThan | Lident _ + | List | Lparen | Minus | MinusDot | Module | Percent | Plus | PlusDot + | String _ | Switch | True | Try | Uident _ | Underscore (* _ => doThings() *) + | While -> true | _ -> false @@ -255,11 +255,11 @@ let isAttributeStart = function let isJsxChildStart = isAtomicExprStart let isBlockExprStart = function - | Token.At | Hash | Percent | Minus | MinusDot | Plus | PlusDot | Bang | True - | False | Float _ | Int _ | String _ | Codepoint _ | Lident _ | Uident _ - | Lparen | List | Lbracket | Lbrace | Forwardslash | Assert | Lazy | If | For - | While | Switch | Open | Module | Exception | Let | LessThan | Backtick | Try - | Underscore -> + | Token.Assert | At | Await | Backtick | Bang | Codepoint _ | Exception + | False | Float _ | For | Forwardslash | Hash | If | Int _ | Lazy | Lbrace + | Lbracket | LessThan | Let | Lident _ | List | Lparen | Minus | MinusDot + | Module | Open | Percent | Plus | PlusDot | String _ | Switch | True | Try + | Uident _ | Underscore | While -> true | _ -> false diff --git a/analysis/vendor/res_outcome_printer/res_parens.ml b/analysis/vendor/res_outcome_printer/res_parens.ml index 33fb0f3da..c18b7565e 100644 --- a/analysis/vendor/res_outcome_printer/res_parens.ml +++ b/analysis/vendor/res_outcome_printer/res_parens.ml @@ -45,6 +45,8 @@ let callExpr expr = | Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ ); } -> Parenthesized + | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> + Parenthesized | _ -> Nothing) let structureExpr expr = @@ -96,6 +98,8 @@ let unaryExprOperand expr = | Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ ); } -> Parenthesized + | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> + Parenthesized | _ -> Nothing) let binaryExprOperand ~isLhs expr = @@ -120,6 +124,8 @@ let binaryExprOperand ~isLhs expr = | expr when ParsetreeViewer.isBinaryExpression expr -> Parenthesized | expr when ParsetreeViewer.isTernaryExpr expr -> Parenthesized | {pexp_desc = Pexp_lazy _ | Pexp_assert _} when isLhs -> Parenthesized + | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> + Parenthesized | {Parsetree.pexp_attributes = attrs} -> if ParsetreeViewer.hasPrintableAttributes attrs then Parenthesized else Nothing) @@ -169,7 +175,7 @@ let flattenOperandRhs parentOperator rhs = | _ when ParsetreeViewer.isTernaryExpr rhs -> true | _ -> false -let lazyOrAssertExprRhs expr = +let lazyOrAssertOrAwaitExprRhs expr = let optBraces, _ = ParsetreeViewer.processBracesAttr expr in match optBraces with | Some ({Location.loc = bracesLoc}, _) -> Braced bracesLoc @@ -196,6 +202,8 @@ let lazyOrAssertExprRhs expr = | Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ ); } -> Parenthesized + | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> + Parenthesized | _ -> Nothing) let isNegativeConstant constant = @@ -240,6 +248,8 @@ let fieldExpr expr = | Pexp_ifthenelse _ ); } -> Parenthesized + | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> + Parenthesized | _ -> Nothing) let setFieldExprRhs expr = @@ -302,6 +312,8 @@ let jsxPropExpr expr = } when startsWithMinus x -> Parenthesized + | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> + Parenthesized | { Parsetree.pexp_desc = ( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _ @@ -338,6 +350,8 @@ let jsxChildExpr expr = } when startsWithMinus x -> Parenthesized + | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> + Parenthesized | { Parsetree.pexp_desc = ( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _ diff --git a/analysis/vendor/res_outcome_printer/res_parens.mli b/analysis/vendor/res_outcome_printer/res_parens.mli index 04cca4b87..cedf98e13 100644 --- a/analysis/vendor/res_outcome_printer/res_parens.mli +++ b/analysis/vendor/res_outcome_printer/res_parens.mli @@ -10,7 +10,7 @@ val subBinaryExprOperand : string -> string -> bool val rhsBinaryExprOperand : string -> Parsetree.expression -> bool val flattenOperandRhs : string -> Parsetree.expression -> bool -val lazyOrAssertExprRhs : Parsetree.expression -> kind +val lazyOrAssertOrAwaitExprRhs : Parsetree.expression -> kind val fieldExpr : Parsetree.expression -> kind diff --git a/analysis/vendor/res_outcome_printer/res_parsetree_viewer.ml b/analysis/vendor/res_outcome_printer/res_parsetree_viewer.ml index 8049d6a97..c22dfb23c 100644 --- a/analysis/vendor/res_outcome_printer/res_parsetree_viewer.ml +++ b/analysis/vendor/res_outcome_printer/res_parsetree_viewer.ml @@ -11,7 +11,7 @@ let arrowType ct = process attrsBefore (arg :: acc) typ2 | { ptyp_desc = Ptyp_arrow ((Nolabel as lbl), typ1, typ2); - ptyp_attributes = [({txt = "bs"}, _)] as attrs; + ptyp_attributes = [({txt = "bs" | "res.async"}, _)] as attrs; } -> let arg = (attrs, lbl, typ1) in process attrsBefore (arg :: acc) typ2 @@ -55,6 +55,30 @@ let processUncurriedAttribute attrs = in process false [] attrs +type functionAttributesInfo = { + async: bool; + uncurried: bool; + attributes: Parsetree.attributes; +} + +let processFunctionAttributes attrs = + let rec process async uncurried acc attrs = + match attrs with + | [] -> {async; uncurried; attributes = List.rev acc} + | ({Location.txt = "bs"}, _) :: rest -> process async true acc rest + | ({Location.txt = "res.async"}, _) :: rest -> + process true uncurried acc rest + | attr :: rest -> process async uncurried (attr :: acc) rest + in + process false false [] attrs + +let hasAwaitAttribute attrs = + List.exists + (function + | {Location.txt = "res.await"}, _ -> true + | _ -> false) + attrs + let collectListExpressions expr = let rec collect acc expr = match expr.pexp_desc with @@ -168,8 +192,9 @@ let filterParsingAttrs attrs = match attr with | ( { Location.txt = - ( "ns.ternary" | "ns.braces" | "res.template" | "bs" | "ns.iflet" - | "ns.namedArgLoc" | "ns.optional" ); + ( "bs" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc" + | "ns.optional" | "ns.ternary" | "res.async" | "res.await" + | "res.template" ); }, _ ) -> false @@ -316,7 +341,8 @@ let hasAttributes attrs = match attr with | ( { Location.txt = - "bs" | "res.template" | "ns.ternary" | "ns.braces" | "ns.iflet"; + ( "bs" | "ns.braces" | "ns.iflet" | "ns.ternary" | "res.async" + | "res.await" | "res.template" ); }, _ ) -> false @@ -497,8 +523,8 @@ let isPrintableAttribute attr = match attr with | ( { Location.txt = - ( "bs" | "res.template" | "ns.ternary" | "ns.braces" | "ns.iflet" - | "JSX" ); + ( "bs" | "ns.iflet" | "ns.braces" | "JSX" | "res.async" | "res.await" + | "res.template" | "ns.ternary" ); }, _ ) -> false diff --git a/analysis/vendor/res_outcome_printer/res_parsetree_viewer.mli b/analysis/vendor/res_outcome_printer/res_parsetree_viewer.mli index e492010b9..f1f5fa329 100644 --- a/analysis/vendor/res_outcome_printer/res_parsetree_viewer.mli +++ b/analysis/vendor/res_outcome_printer/res_parsetree_viewer.mli @@ -17,6 +17,17 @@ val functorType : val processUncurriedAttribute : Parsetree.attributes -> bool * Parsetree.attributes +type functionAttributesInfo = { + async: bool; + uncurried: bool; + attributes: Parsetree.attributes; +} + +(* determines whether a function is async and/or uncurried based on the given attributes *) +val processFunctionAttributes : Parsetree.attributes -> functionAttributesInfo + +val hasAwaitAttribute : Parsetree.attributes -> bool + type ifConditionKind = | If of Parsetree.expression | IfLet of Parsetree.pattern * Parsetree.expression diff --git a/analysis/vendor/res_outcome_printer/res_printer.ml b/analysis/vendor/res_outcome_printer/res_printer.ml index 19f3ee952..c1d947d4a 100644 --- a/analysis/vendor/res_outcome_printer/res_printer.ml +++ b/analysis/vendor/res_outcome_printer/res_printer.ml @@ -79,6 +79,8 @@ let addBraces doc = Doc.rbrace; ]) +let addAsync doc = Doc.concat [Doc.text "async "; doc] + let getFirstLeadingComment tbl loc = match Hashtbl.find tbl.CommentTable.leading loc with | comment :: _ -> Some comment @@ -3093,7 +3095,7 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl = | Pexp_assert expr -> let rhs = let doc = printExpressionWithComments ~customLayout expr cmtTbl in - match Parens.lazyOrAssertExprRhs expr with + match Parens.lazyOrAssertOrAwaitExprRhs expr with | Parens.Parenthesized -> addParens doc | Braced braces -> printBraces doc expr braces | Nothing -> doc @@ -3102,7 +3104,7 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl = | Pexp_lazy expr -> let rhs = let doc = printExpressionWithComments ~customLayout expr cmtTbl in - match Parens.lazyOrAssertExprRhs expr with + match Parens.lazyOrAssertOrAwaitExprRhs expr with | Parens.Parenthesized -> addParens doc | Braced braces -> printBraces doc expr braces | Nothing -> doc @@ -3135,8 +3137,8 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl = cmtTbl | Pexp_fun _ | Pexp_newtype _ -> let attrsOnArrow, parameters, returnExpr = ParsetreeViewer.funExpr e in - let uncurried, attrs = - ParsetreeViewer.processUncurriedAttribute attrsOnArrow + let ParsetreeViewer.{async; uncurried; attributes = attrs} = + ParsetreeViewer.processFunctionAttributes attrsOnArrow in let returnExpr, typConstraint = match returnExpr.pexp_desc with @@ -3156,7 +3158,7 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl = in let parametersDoc = printExprFunParameters ~customLayout ~inCallback:NoCallback ~uncurried - ~hasConstraint parameters cmtTbl + ~async ~hasConstraint parameters cmtTbl in let returnExprDoc = let optBraces, _ = ParsetreeViewer.processBracesAttr returnExpr in @@ -3278,6 +3280,28 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl = | Pexp_poly _ -> Doc.text "Pexp_poly not impemented in printer" | Pexp_object _ -> Doc.text "Pexp_object not impemented in printer" in + let exprWithAwait = + if ParsetreeViewer.hasAwaitAttribute e.pexp_attributes then + let rhs = + match + Parens.lazyOrAssertOrAwaitExprRhs + { + e with + pexp_attributes = + List.filter + (function + | {Location.txt = "res.await" | "ns.braces"}, _ -> false + | _ -> true) + e.pexp_attributes; + } + with + | Parens.Parenthesized -> addParens printedExpression + | Braced braces -> printBraces printedExpression e braces + | Nothing -> printedExpression + in + Doc.concat [Doc.text "await "; rhs] + else printedExpression + in let shouldPrintItsOwnAttributes = match e.pexp_desc with | Pexp_apply _ | Pexp_fun _ | Pexp_newtype _ | Pexp_setfield _ @@ -3289,17 +3313,16 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl = | _ -> false in match e.pexp_attributes with - | [] -> printedExpression + | [] -> exprWithAwait | attrs when not shouldPrintItsOwnAttributes -> Doc.group - (Doc.concat - [printAttributes ~customLayout attrs cmtTbl; printedExpression]) - | _ -> printedExpression + (Doc.concat [printAttributes ~customLayout attrs cmtTbl; exprWithAwait]) + | _ -> exprWithAwait and printPexpFun ~customLayout ~inCallback e cmtTbl = let attrsOnArrow, parameters, returnExpr = ParsetreeViewer.funExpr e in - let uncurried, attrs = - ParsetreeViewer.processUncurriedAttribute attrsOnArrow + let ParsetreeViewer.{async; uncurried; attributes = attrs} = + ParsetreeViewer.processFunctionAttributes attrsOnArrow in let returnExpr, typConstraint = match returnExpr.pexp_desc with @@ -3313,7 +3336,7 @@ and printPexpFun ~customLayout ~inCallback e cmtTbl = | _ -> (returnExpr, None) in let parametersDoc = - printExprFunParameters ~customLayout ~inCallback ~uncurried + printExprFunParameters ~customLayout ~inCallback ~async ~uncurried ~hasConstraint: (match typConstraint with | Some _ -> true @@ -3513,13 +3536,13 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl = then let leftPrinted = flatten ~isLhs:true left operator in let rightPrinted = - let _, rightAttrs = + let rightPrinteableAttrs, rightInternalAttrs = ParsetreeViewer.partitionPrintableAttributes right.pexp_attributes in let doc = printExpressionWithComments ~customLayout - {right with pexp_attributes = rightAttrs} + {right with pexp_attributes = rightInternalAttrs} cmtTbl in let doc = @@ -3527,14 +3550,14 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl = Doc.concat [Doc.lparen; doc; Doc.rparen] else doc in - let printableAttrs = - ParsetreeViewer.filterPrintableAttributes right.pexp_attributes - in let doc = Doc.concat - [printAttributes ~customLayout printableAttrs cmtTbl; doc] + [ + printAttributes ~customLayout rightPrinteableAttrs cmtTbl; + doc; + ] in - match printableAttrs with + match rightPrinteableAttrs with | [] -> doc | _ -> addParens doc in @@ -3553,22 +3576,25 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl = in printComments doc cmtTbl expr.pexp_loc else + let printeableAttrs, internalAttrs = + ParsetreeViewer.partitionPrintableAttributes expr.pexp_attributes + in let doc = printExpressionWithComments ~customLayout - {expr with pexp_attributes = []} + {expr with pexp_attributes = internalAttrs} cmtTbl in let doc = if Parens.subBinaryExprOperand parentOperator operator - || expr.pexp_attributes <> [] + || printeableAttrs <> [] && (ParsetreeViewer.isBinaryExpression expr || ParsetreeViewer.isTernaryExpr expr) then Doc.concat [Doc.lparen; doc; Doc.rparen] else doc in Doc.concat - [printAttributes ~customLayout expr.pexp_attributes cmtTbl; doc] + [printAttributes ~customLayout printeableAttrs cmtTbl; doc] | _ -> assert false else match expr.pexp_desc with @@ -3671,11 +3697,7 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl = { expr with pexp_attributes = - List.filter - (fun attr -> - match attr with - | {Location.txt = "ns.braces"}, _ -> false - | _ -> true) + ParsetreeViewer.filterPrintableAttributes expr.pexp_attributes; } with @@ -4575,8 +4597,8 @@ and printCase ~customLayout (case : Parsetree.case) cmtTbl = in Doc.group (Doc.concat [Doc.text "| "; content]) -and printExprFunParameters ~customLayout ~inCallback ~uncurried ~hasConstraint - parameters cmtTbl = +and printExprFunParameters ~customLayout ~inCallback ~async ~uncurried + ~hasConstraint parameters cmtTbl = match parameters with (* let f = _ => () *) | [ @@ -4585,11 +4607,15 @@ and printExprFunParameters ~customLayout ~inCallback ~uncurried ~hasConstraint attrs = []; lbl = Asttypes.Nolabel; defaultExpr = None; - pat = {Parsetree.ppat_desc = Ppat_any}; + pat = {Parsetree.ppat_desc = Ppat_any; ppat_loc}; }; ] when not uncurried -> - if hasConstraint then Doc.text "(_)" else Doc.text "_" + let any = + let doc = if hasConstraint then Doc.text "(_)" else Doc.text "_" in + printComments doc cmtTbl ppat_loc + in + if async then addAsync any else any (* let f = a => () *) | [ ParsetreeViewer.Parameter @@ -4603,7 +4629,8 @@ and printExprFunParameters ~customLayout ~inCallback ~uncurried ~hasConstraint when not uncurried -> let txtDoc = let var = printIdentLike stringLoc.txt in - if hasConstraint then addParens var else var + let var = if hasConstraint then addParens var else var in + if async then addAsync (Doc.concat [Doc.lparen; var; Doc.rparen]) else var in printComments txtDoc cmtTbl stringLoc.loc (* let f = () => () *) @@ -4613,11 +4640,16 @@ and printExprFunParameters ~customLayout ~inCallback ~uncurried ~hasConstraint attrs = []; lbl = Asttypes.Nolabel; defaultExpr = None; - pat = {ppat_desc = Ppat_construct ({txt = Longident.Lident "()"}, None)}; + pat = + {ppat_desc = Ppat_construct ({txt = Longident.Lident "()"; loc}, None)}; }; ] when not uncurried -> - Doc.text "()" + let doc = + let lparenRparen = Doc.text "()" in + if async then addAsync lparenRparen else lparenRparen + in + printComments doc cmtTbl loc (* let f = (~greeting, ~from as hometown, ~x=?) => () *) | parameters -> let inCallback = @@ -4625,7 +4657,10 @@ and printExprFunParameters ~customLayout ~inCallback ~uncurried ~hasConstraint | FitsOnOneLine -> true | _ -> false in - let lparen = if uncurried then Doc.text "(. " else Doc.lparen in + let maybeAsyncLparen = + let lparen = if uncurried then Doc.text "(. " else Doc.lparen in + if async then addAsync lparen else lparen + in let shouldHug = ParsetreeViewer.parametersShouldHug parameters in let printedParamaters = Doc.concat @@ -4641,7 +4676,7 @@ and printExprFunParameters ~customLayout ~inCallback ~uncurried ~hasConstraint Doc.group (Doc.concat [ - lparen; + maybeAsyncLparen; (if shouldHug || inCallback then printedParamaters else Doc.concat @@ -5401,6 +5436,7 @@ and printExtensionConstructor ~customLayout let printTypeParams = printTypeParams ~customLayout:0 let printTypExpr = printTypExpr ~customLayout:0 let printExpression = printExpression ~customLayout:0 +let printPattern = printPattern ~customLayout:0 let printImplementation ~width (s : Parsetree.structure) ~comments = let cmtTbl = CommentTable.make () in diff --git a/analysis/vendor/res_outcome_printer/res_printer.mli b/analysis/vendor/res_outcome_printer/res_printer.mli index 267ae091e..2f854ef6b 100644 --- a/analysis/vendor/res_outcome_printer/res_printer.mli +++ b/analysis/vendor/res_outcome_printer/res_printer.mli @@ -14,6 +14,9 @@ val addParens : Res_doc.t -> Res_doc.t val printExpression : Parsetree.expression -> Res_comments_table.t -> Res_doc.t +val printPattern : Parsetree.pattern -> Res_comments_table.t -> Res_doc.t + [@@live] + val printStructure : Parsetree.structure -> Res_comments_table.t -> Res_doc.t [@@live] diff --git a/analysis/vendor/res_outcome_printer/res_token.ml b/analysis/vendor/res_outcome_printer/res_token.ml index 2c4f8f26b..a2dceeca1 100644 --- a/analysis/vendor/res_outcome_printer/res_token.ml +++ b/analysis/vendor/res_outcome_printer/res_token.ml @@ -1,6 +1,7 @@ module Comment = Res_comment type t = + | Await | Open | True | False @@ -111,6 +112,7 @@ let precedence = function | _ -> 0 let toString = function + | Await -> "await" | Open -> "open" | True -> "true" | False -> "false" @@ -210,6 +212,7 @@ let keywordTable = function | "and" -> And | "as" -> As | "assert" -> Assert + | "await" -> Await | "constraint" -> Constraint | "else" -> Else | "exception" -> Exception @@ -238,9 +241,9 @@ let keywordTable = function [@@raises Not_found] let isKeyword = function - | And | As | Assert | Constraint | Else | Exception | External | False | For - | If | In | Include | Land | Lazy | Let | List | Lor | Module | Mutable | Of - | Open | Private | Rec | Switch | True | Try | Typ | When | While -> + | Await | And | As | Assert | Constraint | Else | Exception | External | False + | For | If | In | Include | Land | Lazy | Let | List | Lor | Module | Mutable + | Of | Open | Private | Rec | Switch | True | Try | Typ | When | While -> true | _ -> false