diff --git a/analysis/src/Files.ml b/analysis/src/Files.ml index 5da85fd20..9ab016da5 100644 --- a/analysis/src/Files.ml +++ b/analysis/src/Files.ml @@ -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 diff --git a/analysis/src/Hint.ml b/analysis/src/Hint.ml index 1f69cf93a..4a258fe39 100644 --- a/analysis/src/Hint.ml +++ b/analysis/src/Hint.ml @@ -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 @@ -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 diff --git a/analysis/src/SemanticTokens.ml b/analysis/src/SemanticTokens.ml index 80a1badb5..1e7b54160 100644 --- a/analysis/src/SemanticTokens.ml +++ b/analysis/src/SemanticTokens.ml @@ -398,7 +398,8 @@ 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 @@ -406,7 +407,8 @@ let command ~debug ~emitter ~path = 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 @@ -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 diff --git a/analysis/src/Xform.ml b/analysis/src/Xform.ml index a402ca92e..fe9e58f0f 100644 --- a/analysis/src/Xform.ml +++ b/analysis/src/Xform.ml @@ -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