Skip to content

Commit ffd6440

Browse files
jbrown215facebook-github-bot
authored andcommitted
[flow][EZ][apply-code-action] Factor out code to type check file
Summary: Next diff has a similar structure to this function so I'll make it re-usable Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D69551137 fbshipit-source-id: 28f49490843cd2f2fd741b477904156c17b98ad5
1 parent 59c1531 commit ffd6440

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/services/code_action/code_action_service.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,9 +1592,7 @@ let autofix_imports ~options ~env ~loc_of_aloc ~module_system_info ~cx ~ast ~src
15921592
let opts = layout_options options in
15931593
Autofix_imports.add_imports ~options:opts ~added_imports ast
15941594

1595-
let autofix_imports_cli
1596-
~options ~profiling ~env ~loc_of_aloc ~module_system_info ~file_key ~file_content =
1597-
let src_dir = File_key.to_string file_key |> Filename.dirname |> Base.Option.return in
1595+
let with_type_checked_file ~options ~profiling ~env ~file_key ~file_content ~f =
15981596
let file_artifacts =
15991597
let ((_, parse_errs) as intermediate_result) =
16001598
Type_contents.parse_contents ~options ~profiling file_content file_key
@@ -1610,10 +1608,17 @@ let autofix_imports_cli
16101608
intermediate_result
16111609
in
16121610
match file_artifacts with
1613-
| Ok (Parse_artifacts { ast; _ }, Typecheck_artifacts { cx; _ }) ->
1611+
| Ok (Parse_artifacts { ast; _ }, Typecheck_artifacts { cx; _ }) -> f ~cx ~ast
1612+
| _ -> Error "Failed to parse or check file"
1613+
1614+
let autofix_imports_cli
1615+
~options ~profiling ~env ~loc_of_aloc ~module_system_info ~file_key ~file_content =
1616+
let src_dir = File_key.to_string file_key |> Filename.dirname |> Base.Option.return in
1617+
let get_edits ~cx ~ast =
16141618
let edits = autofix_imports ~options ~env ~loc_of_aloc ~module_system_info ~cx ~ast ~src_dir in
16151619
Ok (Replacement_printer.loc_patch_to_patch file_content edits)
1616-
| _ -> Error "Failed to parse or check file"
1620+
in
1621+
with_type_checked_file ~options ~profiling ~env ~file_key ~file_content ~f:get_edits
16171622

16181623
let autofix_imports_lsp ~options ~env ~loc_of_aloc ~module_system_info ~cx ~ast ~uri =
16191624
let src_dir = Lsp_helpers.lsp_uri_to_path uri |> Filename.dirname |> Base.Option.return in

0 commit comments

Comments
 (0)