Skip to content

Checking if a file is a res file #543

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 4 commits into from
Aug 3, 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
7 changes: 7 additions & 0 deletions analysis/src/Files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,10 @@ let rec collect ?(checkDir = fun _ -> true) path test =
|> List.concat
else []
| _ -> if test path then [path] else []

type classifiedFile = Res | Resi | Other

let classifySourceFile path =
if Filename.check_suffix path ".res" && exists path then Res
else if Filename.check_suffix path ".resi" && exists path then Resi
else Other
4 changes: 2 additions & 2 deletions analysis/src/Hint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ let inlay ~path ~pos ~maxLength ~debug =
Ast_iterator.default_iterator.value_binding iterator vb
in
let iterator = {Ast_iterator.default_iterator with value_binding} in
(if Files.exists path && Filename.check_suffix path ".res" then
(if Files.classifySourceFile path = Res then
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
Expand Down Expand Up @@ -143,7 +143,7 @@ let codeLens ~path ~debug =
let iterator = {Ast_iterator.default_iterator with value_binding} in
(* 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.exists path && Filename.check_suffix path ".res" then
(if Files.classifySourceFile path = Res then
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
Expand Down
8 changes: 5 additions & 3 deletions analysis/src/SemanticTokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,17 @@ let command ~debug ~emitter ~path =
let structure_item (iterator : Ast_iterator.iterator)
(item : Parsetree.structure_item) =
(match item.pstr_desc with
| Pstr_primitive {pval_name = {txt = id; loc}} -> emitter |> emitVariable ~id ~debug ~loc;
| Pstr_primitive {pval_name = {txt = id; loc}} ->
emitter |> emitVariable ~id ~debug ~loc
| _ -> ());
Ast_iterator.default_iterator.structure_item iterator item
in

let signature_item (iterator : Ast_iterator.iterator)
(item : Parsetree.signature_item) =
(match item.psig_desc with
| Psig_value {pval_name = {txt = id; loc}} -> emitter |> emitVariable ~id ~debug ~loc;
| Psig_value {pval_name = {txt = id; loc}} ->
emitter |> emitVariable ~id ~debug ~loc
| _ -> ());
Ast_iterator.default_iterator.signature_item iterator item
in
Expand All @@ -431,7 +433,7 @@ let command ~debug ~emitter ~path =
}
in

if Filename.check_suffix path ".res" then (
if Files.classifySourceFile path = Res then (
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/Xform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ let parse ~filename =

let extractCodeActions ~path ~pos ~currentFile ~debug =
match Cmt.fullFromPath ~path with
| Some full when Filename.check_suffix currentFile ".res" ->
| Some full when Files.classifySourceFile currentFile = Res ->
let structure, printExpr, printStructureItem =
parse ~filename:currentFile
in
Expand Down