Skip to content
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

Pull latest parser and compiler helper files #998

Merged
merged 3 commits into from
May 31, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
- Add code action for expanding catch-all patterns. https://github.com/rescript-lang/rescript-vscode/pull/987
- Add code actions for removing unused code (per item and for an entire file), driven by `reanalyze`. https://github.com/rescript-lang/rescript-vscode/pull/989

#### :house: Internal

- Update parser and compiler support files to the latest version. https://github.com/rescript-lang/rescript-vscode/pull/998

## 1.50.0

#### :rocket: New Feature
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/Codemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let transform ~path ~pos ~debug ~typ ~hint =
| AddMissingCases -> (
let source = "let " ^ hint ^ " = ()" in
let {Res_driver.parsetree = hintStructure} =
Res_driver.parseImplementationFromSource ~forPrinter:false
~displayFilename:"<none>" ~source
Res_driver.parse_implementation_from_source ~for_printer:false
~display_filename:"<none>" ~source
in
match hintStructure with
| [{pstr_desc = Pstr_value (_, [{pvb_pat = pattern}])}] -> (
Expand Down
10 changes: 5 additions & 5 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,20 @@ let rename ~path ~pos ~newName ~debug =
let format ~path =
if Filename.check_suffix path ".res" then
let {Res_driver.parsetree = structure; comments; diagnostics} =
Res_driver.parsingEngine.parseImplementation ~forPrinter:true
Res_driver.parsing_engine.parse_implementation ~for_printer:true
~filename:path
in
if List.length diagnostics > 0 then ""
else
Res_printer.printImplementation ~width:!Res_cli.ResClflags.width ~comments
structure
Res_printer.print_implementation ~width:!Res_cli.ResClflags.width
~comments structure
else if Filename.check_suffix path ".resi" then
let {Res_driver.parsetree = signature; comments; diagnostics} =
Res_driver.parsingEngine.parseInterface ~forPrinter:true ~filename:path
Res_driver.parsing_engine.parse_interface ~for_printer:true ~filename:path
in
if List.length diagnostics > 0 then ""
else
Res_printer.printInterface ~width:!Res_cli.ResClflags.width ~comments
Res_printer.print_interface ~width:!Res_cli.ResClflags.width ~comments
signature
else ""

Expand Down
12 changes: 6 additions & 6 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let findArgCompletables ~(args : arg list) ~endPos ~posBeforeCursor
if CursorPosition.locIsEmpty exp.pexp_loc ~pos:posBeforeCursor then
someArgHadEmptyExprLoc := true;

if Res_parsetree_viewer.isTemplateLiteral exp then None
if Res_parsetree_viewer.is_template_literal exp then None
else if exp.pexp_loc |> Loc.hasPos ~pos:posBeforeCursor then (
if Debug.verbose () then
print_endline
Expand Down Expand Up @@ -281,7 +281,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =

and exprToContextPath (e : Parsetree.expression) =
match
( Res_parsetree_viewer.hasAwaitAttribute e.pexp_attributes,
( Res_parsetree_viewer.has_await_attribute e.pexp_attributes,
exprToContextPathInner e )
with
| true, Some ctxPath -> Some (CPAwait ctxPath)
Expand Down Expand Up @@ -1072,7 +1072,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
completionContext =
(if
isLikelyModulePath
&& expr |> Res_parsetree_viewer.isBracedExpr
&& expr |> Res_parsetree_viewer.is_braced_expr
then ValueOrField
else Value);
}))
Expand Down Expand Up @@ -1143,7 +1143,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
| Some contextPath -> setResult (Cpath (CPField (contextPath, "")))
| None -> ())
| Pexp_apply ({pexp_desc = Pexp_ident compName}, args)
when Res_parsetree_viewer.isJsxExpression expr ->
when Res_parsetree_viewer.is_jsx_expression expr ->
inJsxContext := true;
let jsxProps = CompletionJsx.extractJsxProps ~compName ~args in
let compNamePath = flattenLidCheckDot ~jsx:true compName in
Expand Down Expand Up @@ -1500,7 +1500,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor

if Filename.check_suffix path ".res" then (
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
Res_driver.parsing_engine.parse_implementation ~for_printer:false
in
let {Res_driver.parsetree = str} = parser ~filename:currentFile in
iterator.structure iterator str |> ignore;
Expand All @@ -1512,7 +1512,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
if !found = false then if debug then Printf.printf "XXX Not found!\n";
!result)
else if Filename.check_suffix path ".resi" then (
let parser = Res_driver.parsingEngine.parseInterface ~forPrinter:false in
let parser = Res_driver.parsing_engine.parse_interface ~for_printer:false in
let {Res_driver.parsetree = signature} = parser ~filename:currentFile in
iterator.signature iterator signature |> ignore;
if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then (
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/CreateInterface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ let printSignature ~extractor ~signature =

Printtyp.reset_names ();
let sigItemToString (item : Outcometree.out_sig_item) =
item |> Res_outcome_printer.printOutSigItemDoc
|> Res_doc.toString ~width:!Res_cli.ResClflags.width
item |> Res_outcome_printer.print_out_sig_item_doc
|> Res_doc.to_string ~width:!Res_cli.ResClflags.width
in

let genSigStrForInlineAttr lines attributes id vd =
Expand Down
9 changes: 5 additions & 4 deletions analysis/src/Diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ let document_syntax ~path =
diagnostics
|> List.map (fun diagnostic ->
let _, startline, startcol =
Location.get_pos_info (Res_diagnostics.getStartPos diagnostic)
Location.get_pos_info (Res_diagnostics.get_start_pos diagnostic)
in
let _, endline, endcol =
Location.get_pos_info (Res_diagnostics.getEndPos diagnostic)
Location.get_pos_info (Res_diagnostics.get_end_pos diagnostic)
in
Protocol.stringifyDiagnostic
{
Expand All @@ -21,13 +21,14 @@ let document_syntax ~path =
in
if FindFiles.isImplementation path then
let parseImplementation =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
Res_driver.parsing_engine.parse_implementation ~for_printer:false
~filename:path
in
get_diagnostics parseImplementation.diagnostics
else if FindFiles.isInterface path then
let parseInterface =
Res_driver.parsingEngine.parseInterface ~forPrinter:false ~filename:path
Res_driver.parsing_engine.parse_interface ~for_printer:false
~filename:path
in
get_diagnostics parseInterface.diagnostics
else []
20 changes: 11 additions & 9 deletions analysis/src/DocumentSymbol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,17 @@ let command ~path =
in

(if Filename.check_suffix path ".res" then
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore
else
let parser = Res_driver.parsingEngine.parseInterface ~forPrinter:false in
let {Res_driver.parsetree = signature} = parser ~filename:path in
iterator.signature iterator signature |> ignore);
let parser =
Res_driver.parsing_engine.parse_implementation ~for_printer:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore
else
let parser =
Res_driver.parsing_engine.parse_interface ~for_printer:false
in
let {Res_driver.parsetree = signature} = parser ~filename:path in
iterator.signature iterator signature |> ignore);
let isInside
({
range =
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/DumpAst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ let printStructItem structItem ~pos ~source =

let dump ~currentFile ~pos =
let {Res_driver.parsetree = structure; source} =
Res_driver.parsingEngine.parseImplementation ~forPrinter:true
Res_driver.parsing_engine.parse_implementation ~for_printer:true
~filename:currentFile
in

Expand Down
22 changes: 11 additions & 11 deletions analysis/src/Hint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let locItemToTypeHint ~full:{file; package} locItem =
| Const_float _ -> "float"
| Const_int32 _ -> "int32"
| Const_int64 _ -> "int64"
| Const_nativeint _ -> "int")
| Const_bigint _ -> "bigint")
| Typed (_, t, locKind) ->
let fromType typ =
typ |> Shared.typeToString
Expand Down Expand Up @@ -71,11 +71,11 @@ let inlay ~path ~pos ~maxLength ~debug =
in
let iterator = {Ast_iterator.default_iterator with value_binding} in
(if Files.classifySourceFile path = Res then
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore);
let parser =
Res_driver.parsing_engine.parse_implementation ~for_printer:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore);
match Cmt.loadFullCmtFromPath ~path with
| None -> None
| Some full ->
Expand Down Expand Up @@ -135,11 +135,11 @@ let codeLens ~path ~debug =
(* We only print code lenses in implementation files. This is because they'd be redundant in interface files,
where the definition itself will be the same thing as what would've been printed in the code lens. *)
(if Files.classifySourceFile path = Res then
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore);
let parser =
Res_driver.parsing_engine.parse_implementation ~for_printer:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore);
match Cmt.loadFullCmtFromPath ~path with
| None -> None
| Some full ->
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/Hover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
| Const_float _ -> "float"
| Const_int32 _ -> "int32"
| Const_int64 _ -> "int64"
| Const_nativeint _ -> "int"))
| Const_bigint _ -> "bigint"))
| Typed (_, t, locKind) ->
let fromType ~docstring typ =
( hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ,
Expand Down
8 changes: 4 additions & 4 deletions analysis/src/PrintType.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let printExpr ?(lineWidth = 60) typ =
Printtyp.reset_names ();
Printtyp.reset_and_mark_loops typ;
Res_doc.toString ~width:lineWidth
(Res_outcome_printer.printOutTypeDoc (Printtyp.tree_of_typexp false typ))
Res_doc.to_string ~width:lineWidth
(Res_outcome_printer.print_out_type_doc (Printtyp.tree_of_typexp false typ))

let printDecl ?printNameAsIs ~recStatus name decl =
Printtyp.reset_names ();
Res_doc.toString ~width:60
(Res_outcome_printer.printOutSigItemDoc ?printNameAsIs
Res_doc.to_string ~width:60
(Res_outcome_printer.print_out_sig_item_doc ?print_name_as_is:printNameAsIs
(Printtyp.tree_of_type_declaration (Ident.create name) decl recStatus))
6 changes: 3 additions & 3 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let mapRecordField {Types.ld_id; ld_type; ld_attributes} =
stamp = astamp;
fname = Location.mknoloc name;
typ = ld_type;
optional = Res_parsetree_viewer.hasOptionalAttribute ld_attributes;
optional = Res_parsetree_viewer.has_optional_attribute ld_attributes;
docstring =
(match ProcessAttributes.findDocAttribute ld_attributes with
| None -> []
Expand Down Expand Up @@ -255,7 +255,7 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
typ = f.ld_type.ctyp_type;
optional =
Res_parsetree_viewer
.hasOptionalAttribute
.has_optional_attribute
f.ld_attributes;
docstring =
(match
Expand Down Expand Up @@ -302,7 +302,7 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
fname;
typ = ctyp_type;
optional =
Res_parsetree_viewer.hasOptionalAttribute
Res_parsetree_viewer.has_optional_attribute
ld_attributes;
docstring = attrsToDocstring ld_attributes;
deprecated =
Expand Down
30 changes: 15 additions & 15 deletions analysis/src/SemanticTokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ let command ~debug ~emitter ~path =
~lid ~debug;
Ast_iterator.default_iterator.expr iterator e
| Pexp_apply ({pexp_desc = Pexp_ident lident; pexp_loc}, args)
when Res_parsetree_viewer.isJsxExpression e ->
when Res_parsetree_viewer.is_jsx_expression e ->
(*
Angled brackets:
- These are handled in the grammar: <> </> </ />
Expand Down Expand Up @@ -283,18 +283,18 @@ let command ~debug ~emitter ~path =
(* there's an off-by one somehow in the AST *)
in
(if not selfClosing then
let lineStart, colStart = Loc.start pexp_loc in
let lineEnd, colEnd = Loc.end_ pexp_loc in
let length = if lineStart = lineEnd then colEnd - colStart else 0 in
let lineEndWhole, colEndWhole = Loc.end_ e.pexp_loc in
if length > 0 && colEndWhole > length then (
emitter
|> emitJsxClose ~debug ~lid:lident.txt
~pos:(lineEndWhole, colEndWhole - 1);
emitter (* <foo ...props > <-- *)
|> emitJsxTag ~debug ~name:">" ~pos:posOfGreatherthanAfterProps;
emitter (* <foo> ... </foo> <-- *)
|> emitJsxTag ~debug ~name:">" ~pos:posOfFinalGreatherthan));
let lineStart, colStart = Loc.start pexp_loc in
let lineEnd, colEnd = Loc.end_ pexp_loc in
let length = if lineStart = lineEnd then colEnd - colStart else 0 in
let lineEndWhole, colEndWhole = Loc.end_ e.pexp_loc in
if length > 0 && colEndWhole > length then (
emitter
|> emitJsxClose ~debug ~lid:lident.txt
~pos:(lineEndWhole, colEndWhole - 1);
emitter (* <foo ...props > <-- *)
|> emitJsxTag ~debug ~name:">" ~pos:posOfGreatherthanAfterProps;
emitter (* <foo> ... </foo> <-- *)
|> emitJsxTag ~debug ~name:">" ~pos:posOfFinalGreatherthan));

args |> List.iter (fun (_lbl, arg) -> iterator.expr iterator arg)
| Pexp_apply
Expand Down Expand Up @@ -440,7 +440,7 @@ let command ~debug ~emitter ~path =

if Files.classifySourceFile path = Res then (
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
Res_driver.parsing_engine.parse_implementation ~for_printer:false
in
let {Res_driver.parsetree = structure; diagnostics} =
parser ~filename:path
Expand All @@ -450,7 +450,7 @@ let command ~debug ~emitter ~path =
(List.length structure) (List.length diagnostics);
iterator.structure iterator structure |> ignore)
else
let parser = Res_driver.parsingEngine.parseInterface ~forPrinter:false in
let parser = Res_driver.parsing_engine.parse_interface ~for_printer:false in
let {Res_driver.parsetree = signature; diagnostics} =
parser ~filename:path
in
Expand Down
6 changes: 3 additions & 3 deletions analysis/src/SignatureHelp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads =
in
let iterator = {Ast_iterator.default_iterator with expr; pat} in
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
Res_driver.parsing_engine.parse_implementation ~for_printer:false
in
let {Res_driver.parsetree = structure} = parser ~filename:currentFile in
iterator.structure iterator structure |> ignore;
Expand Down Expand Up @@ -456,8 +456,8 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads =
let fnTypeStr = Shared.typeToString type_expr in
let typeStrForParser = labelPrefix ^ fnTypeStr in
let {Res_driver.parsetree = signature} =
Res_driver.parseInterfaceFromSource ~forPrinter:false
~displayFilename:"<missing-file>" ~source:typeStrForParser
Res_driver.parse_interface_from_source ~for_printer:false
~display_filename:"<missing-file>" ~source:typeStrForParser
in

let parameters =
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ let printMaybeExoticIdent ?(allowUident = false) txt =
| 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '\'' | '_' -> loop (i + 1)
| _ -> "\"" ^ txt ^ "\""
in
if Res_token.isKeywordTxt txt then "\"" ^ txt ^ "\"" else loop 0
if Res_token.is_keyword_txt txt then "\"" ^ txt ^ "\"" else loop 0

let findPackageJson root =
let path = Uri.toPath root in
Expand Down
Loading
Loading