From efe81389bc1c0246b36df5869fcda1dd73aab966 Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Mon, 26 Apr 2021 04:52:53 -0700 Subject: [PATCH 1/2] Small cleanup --- analysis/.depend | 2 +- analysis/src/Files.ml | 16 +-- analysis/src/FindFiles.ml | 183 +++++++++++++++---------------- analysis/src/ModuleResolution.ml | 10 +- analysis/src/NewCompletions.ml | 24 ++-- analysis/src/PartialParser.ml | 58 ++++------ analysis/src/PrepareUtils.ml | 16 +-- analysis/src/ProcessCmt.ml | 24 ++-- analysis/src/References.ml | 5 +- analysis/src/Shared.ml | 6 +- analysis/src/SharedTypes.ml | 4 +- 11 files changed, 166 insertions(+), 182 deletions(-) diff --git a/analysis/.depend b/analysis/.depend index 6324d6d6a..4998b9e43 100644 --- a/analysis/.depend +++ b/analysis/.depend @@ -19,7 +19,7 @@ src/NewCompletions.cmx : src/Utils.cmx src/Uri2.cmx src/TopTypes.cmx \ src/Packages.cmx : src/Uri2.cmx src/TopTypes.cmx src/SharedTypes.cmx \ src/Log.cmx src/vendor/Json.cmx src/Infix.cmx src/FindFiles.cmx \ src/Files.cmx src/BuildSystem.cmx -src/PartialParser.cmx : src/SharedTypes.cmx src/Infix.cmx +src/PartialParser.cmx : src/SharedTypes.cmx src/PrepareUtils.cmx : src/PrintType.cmx : src/vendor/res_outcome_printer/res_outcome_printer.cmx \ src/vendor/res_outcome_printer/res_doc.cmx diff --git a/analysis/src/Files.ml b/analysis/src/Files.ml index 756babe34..5bb17c03f 100644 --- a/analysis/src/Files.ml +++ b/analysis/src/Files.ml @@ -6,9 +6,9 @@ let removeExtraDots path = (* Win32 & MacOS are case-insensitive *) let pathEq = - match Sys.os_type = "Linux" with - | true -> fun a b -> a = b - | false -> fun a b -> String.lowercase_ascii a = String.lowercase_ascii b + if Sys.os_type = "Linux" + then fun a b -> a = b +else fun a b -> String.lowercase_ascii a = String.lowercase_ascii b let pathStartsWith text prefix = String.length prefix <= String.length text @@ -38,9 +38,9 @@ let relpath base path = loop (split Filename.dir_sep base) (split Filename.dir_sep path) in String.concat Filename.dir_sep - ((match base = [] with - | true -> ["."] - | false -> List.map (fun _ -> "..") base) + ((match base with + | [] -> ["."] + | _ -> List.map (fun _ -> "..") base) @ path) |> removeExtraDots @@ -61,7 +61,7 @@ let readFile ~filename = let exists path = match maybeStat path with None -> false | Some _ -> true -let ifExists path = match exists path with true -> Some path | false -> None +let ifExists path = if exists path then Some path else None let readDirectory dir = match Unix.opendir dir with @@ -99,7 +99,7 @@ let rec collect ?(checkDir = fun _ -> true) path test = collect ~checkDir (Filename.concat path name) test) |> List.concat else [] - | _ -> ( match test path with true -> [path] | false -> []) + | _ -> ( if test path then [path] else []) let fileConcat a b = if diff --git a/analysis/src/FindFiles.ml b/analysis/src/FindFiles.ml index ce0021db2..5abe4d49a 100644 --- a/analysis/src/FindFiles.ml +++ b/analysis/src/FindFiles.ml @@ -16,9 +16,9 @@ let getSourceDirectories ~includeDev base config = Json.get "dir" item |?> Json.string |? "Must specify directory" in let typ = - match includeDev with - | true -> "lib" - | false -> item |> Json.get "type" |?> Json.string |? "lib" + if includeDev then + "lib" + else item |> Json.get "type" |?> Json.string |? "lib" in if typ = "dev" then [] else @@ -29,10 +29,12 @@ let getSourceDirectories ~includeDev base config = (* |> ifDebug(true, "Subdirs", String.concat(" - ")) *) |> List.filter (fun name -> name <> Filename.current_dir_name) |> List.map (Files.relpath base) - | Some item -> (current /+ dir) :: handleItem (current /+ dir) item ) + | Some item -> (current /+ dir) :: handleItem (current /+ dir) item) | _ -> failwith "Invalid subdirs entry" in - config |> Json.get "sources" |?>> handleItem "" |? [] + match config |> Json.get "sources" with + | None -> [] + | Some item -> handleItem "" item let isCompiledFile name = Filename.check_suffix name ".cmt" || Filename.check_suffix name ".cmti" @@ -73,10 +75,10 @@ let filterDuplicates cmts = cmts |> List.filter (fun path -> not - ( ( Filename.check_suffix path ".re" - || Filename.check_suffix path ".ml" - || Filename.check_suffix path ".cmt" ) - && Hashtbl.mem intfs (getName path) )) + ((Filename.check_suffix path ".re" + || Filename.check_suffix path ".ml" + || Filename.check_suffix path ".cmt") + && Hashtbl.mem intfs (getName path))) let nameSpaceToName n = n @@ -89,13 +91,12 @@ let getNamespace config = let isNamespaced = ns |?> Json.bool |? (ns |?> Json.string |?> (fun _ -> Some true) |? false) in - match isNamespaced with - | true -> + if isNamespaced then ns |?> Json.string |?? (Json.get "name" config |?> Json.string) |! "name is required if namespace is true" |> nameSpaceToName |> fun s -> Some s - | false -> None + else None let collectFiles directory = let allFiles = Files.readDirectory directory in @@ -108,9 +109,9 @@ let collectFiles directory = let source = Utils.find (fun name -> - match getName name = modName with - | true -> Some (directory /+ name) - | false -> None) + if getName name = modName then + Some (directory /+ name) + else None) sources in (modName, SharedTypes.Impl (compiled, source))) @@ -148,45 +149,44 @@ let findProjectFiles ~debug namespace root sourceDirectories compiledBase = || Filename.check_suffix path ".mli" then ( Log.log ("Adding intf " ^ path); - Hashtbl.replace interfaces (getName path) path )); + Hashtbl.replace interfaces (getName path) path)); let normals = files |> Utils.filterMap (fun path -> - if - Filename.check_suffix path ".re" - || Filename.check_suffix path ".res" - || Filename.check_suffix path ".ml" - then ( - let mname = getName path in - let intf = Hashtbl.find_opt interfaces mname in - Hashtbl.remove interfaces mname; - let base = compiledBaseName ~namespace (Files.relpath root path) in - match intf with - | Some intf -> - let cmti = (compiledBase /+ base) ^ ".cmti" in - let cmt = (compiledBase /+ base) ^ ".cmt" in - if Files.exists cmti then - if Files.exists cmt then - (* Log.log("Intf and impl " ++ cmti ++ " " ++ cmt) *) - Some (mname, SharedTypes.IntfAndImpl (cmti, intf, cmt, path)) - else Some (mname, Intf (cmti, intf)) - else ( - (* Log.log("Just intf " ++ cmti) *) - Log.log ("Bad source file (no cmt/cmti/cmi) " ^ (compiledBase /+ base)); - None - ) - | None -> - let cmt = (compiledBase /+ base) ^ ".cmt" in - if Files.exists cmt then Some (mname, Impl (cmt, Some path)) - else ( - Log.log ("Bad source file (no cmt/cmi) " ^ (compiledBase /+ base)); - None - ) - ) else ( - Log.log ("Bad source file (extension) " ^ path); - None - ) - ) + if + Filename.check_suffix path ".re" + || Filename.check_suffix path ".res" + || Filename.check_suffix path ".ml" + then ( + let mname = getName path in + let intf = Hashtbl.find_opt interfaces mname in + Hashtbl.remove interfaces mname; + let base = compiledBaseName ~namespace (Files.relpath root path) in + match intf with + | Some intf -> + let cmti = (compiledBase /+ base) ^ ".cmti" in + let cmt = (compiledBase /+ base) ^ ".cmt" in + if Files.exists cmti then + if Files.exists cmt then + (* Log.log("Intf and impl " ++ cmti ++ " " ++ cmt) *) + Some (mname, SharedTypes.IntfAndImpl (cmti, intf, cmt, path)) + else Some (mname, Intf (cmti, intf)) + else ( + (* Log.log("Just intf " ++ cmti) *) + Log.log + ("Bad source file (no cmt/cmti/cmi) " ^ (compiledBase /+ base) + ); + None) + | None -> + let cmt = (compiledBase /+ base) ^ ".cmt" in + if Files.exists cmt then Some (mname, Impl (cmt, Some path)) + else ( + Log.log + ("Bad source file (no cmt/cmi) " ^ (compiledBase /+ base)); + None)) + else ( + Log.log ("Bad source file (extension) " ^ path); + None)) in let result = List.append normals @@ -200,9 +200,9 @@ let findProjectFiles ~debug namespace root sourceDirectories compiledBase = else res) interfaces []) |> List.map (fun (name, paths) -> - match namespace with - | None -> (name, paths) - | Some namespace -> (name ^ "-" ^ namespace, paths)) + match namespace with + | None -> (name, paths) + | Some namespace -> (name ^ "-" ^ namespace, paths)) in match namespace with | None -> result @@ -234,35 +234,35 @@ let findDependencyFiles ~debug base config = let depFiles = deps |> List.map (fun name -> - let result = - ModuleResolution.resolveNodeModulePath ~startPath:base name - |?> fun loc -> - let innerPath = loc /+ "bsconfig.json" in - Log.log ("Dep loc " ^ innerPath); - match Files.readFile innerPath with - | Some text -> ( - let inner = Json.parse text in - let namespace = getNamespace inner in - let directories = - getSourceDirectories ~includeDev:false loc inner - in - match BuildSystem.getCompiledBase loc with - | None -> None - | Some compiledBase -> - if debug then Log.log ("Compiled base: " ^ compiledBase); - let compiledDirectories = - directories |> List.map (Files.fileConcat compiledBase) - in - let compiledDirectories = - match namespace = None with - | true -> compiledDirectories - | false -> compiledBase :: compiledDirectories - in - let files = - findProjectFiles ~debug namespace loc directories - compiledBase - in - (* + let result = + ModuleResolution.resolveNodeModulePath ~startPath:base name + |?> fun loc -> + let innerPath = loc /+ "bsconfig.json" in + Log.log ("Dep loc " ^ innerPath); + match Files.readFile innerPath with + | Some text -> ( + let inner = Json.parse text in + let namespace = getNamespace inner in + let directories = + getSourceDirectories ~includeDev:false loc inner + in + match BuildSystem.getCompiledBase loc with + | None -> None + | Some compiledBase -> + if debug then Log.log ("Compiled base: " ^ compiledBase); + let compiledDirectories = + directories |> List.map (Files.fileConcat compiledBase) + in + let compiledDirectories = + match namespace with + | None -> compiledDirectories + | Some _ -> compiledBase :: compiledDirectories + in + let files = + findProjectFiles ~debug namespace loc directories + compiledBase + in + (* let files = switch (namespace) { | None => files @@ -273,15 +273,14 @@ let findDependencyFiles ~debug base config = ) }; *) - Some (compiledDirectories, files) ) - | None -> None - in - match result with - | Some dependency -> dependency - | None -> - Log.log ("Skipping nonexistent dependency: " ^ name); - ([], []) - ) + Some (compiledDirectories, files)) + | None -> None + in + match result with + | Some dependency -> dependency + | None -> + Log.log ("Skipping nonexistent dependency: " ^ name); + ([], [])) in let directories, files = List.split depFiles in let files = List.concat files in diff --git a/analysis/src/ModuleResolution.ml b/analysis/src/ModuleResolution.ml index 1aac4ee7e..f91454eb2 100644 --- a/analysis/src/ModuleResolution.ml +++ b/analysis/src/ModuleResolution.ml @@ -2,10 +2,6 @@ open Infix let rec resolveNodeModulePath ~startPath name = let path = startPath /+ "node_modules" /+ name in - match startPath with - | "/" -> ( match Files.exists path with true -> Some path | false -> None ) - | _ -> ( - match Files.exists path with - | true -> Some path - | false -> - resolveNodeModulePath ~startPath:(Filename.dirname startPath) name ) + if Files.exists path then Some path + else if startPath = "/" then None + else resolveNodeModulePath ~startPath:(Filename.dirname startPath) name diff --git a/analysis/src/NewCompletions.ml b/analysis/src/NewCompletions.ml index e6c75e87f..2f3ba3be6 100644 --- a/analysis/src/NewCompletions.ml +++ b/analysis/src/NewCompletions.ml @@ -1,16 +1,16 @@ open SharedTypes let showConstructor {cname = {txt}; args; res} = - let open Infix in txt - ^ (match args = [] with - | true -> "" - | false -> + ^ (match args with + | [] -> "" + | _ -> "(" - ^ String.concat ", " - (args |> List.map (fun (typ, _) -> typ |> Shared.typeToString)) + ^ (args + |> List.map (fun (typ, _) -> typ |> Shared.typeToString) + |> String.concat ", ") ^ ")") - ^ (res |?>> (fun typ -> "\n" ^ (typ |> Shared.typeToString)) |? "") + ^ match res with None -> "" | Some typ -> "\n" ^ (typ |> Shared.typeToString) (* TODO: local opens *) let resolveOpens ~env ~previous opens ~package = @@ -229,7 +229,7 @@ let valueCompletions ~(env : ProcessCmt.queryEnv) suffix = (* Get rid of lowercase modules (#417) *) env.qExported.modules |> Hashtbl.filter_map_inplace (fun name key -> - match isCapitalized name with true -> Some key | false -> None); + if isCapitalized name then Some key else None); let moduleCompletions = completionForExporteds env.qExported.modules env.qFile.stamps.modules suffix (fun m -> Module m) @@ -416,7 +416,7 @@ let mkItem ~name ~kind ~detail ~deprecated ~docstring = match docstring with [] -> "" | _ :: _ -> docstring |> String.concat "\n" in let tags = - match deprecated = None with true -> [] | false -> [1 (* deprecated *)] + match deprecated with None -> [] | Some _ -> [1 (* deprecated *)] in Protocol. { @@ -553,9 +553,9 @@ let processCompletable ~findItems ~package ~rawOpens |> String.concat "." in let completionName name = - match modulePathMinusOpens = "" with - | true -> name - | false -> modulePathMinusOpens ^ "." ^ name + if modulePathMinusOpens = "" then + name + else modulePathMinusOpens ^ "." ^ name in let parts = modulePath @ [partialName] in let items = parts |> findItems ~exact:false in diff --git a/analysis/src/PartialParser.ml b/analysis/src/PartialParser.ml index 121448009..f660da41f 100644 --- a/analysis/src/PartialParser.ml +++ b/analysis/src/PartialParser.ml @@ -61,18 +61,18 @@ let findJsxContext text offset = let i = skipWhite text i in if i > 0 then match text.[i] with - | '}' -> ( + | '}' -> let i1 = findBackSkippingCommentsAndStrings text '{' '}' (i - 1) 0 in - match i1 > 0 with true -> beforeValue i1 | false -> None) - | ')' -> ( + if i1 > 0 then beforeValue i1 else None + | ')' -> let i1 = findBackSkippingCommentsAndStrings text '(' ')' (i - 1) 0 in - match i1 > 0 with true -> beforeValue i1 | false -> None) - | ']' -> ( + if i1 > 0 then beforeValue i1 else None + | ']' -> let i1 = findBackSkippingCommentsAndStrings text '[' ']' (i - 1) 0 in - match i1 > 0 with true -> beforeValue i1 | false -> None) - | '"' -> ( + if i1 > 0 then beforeValue i1 else None + | '"' -> let i1 = findBack text '"' (i - 1) in - match i1 > 0 with true -> beforeValue i1 | false -> None) + if i1 > 0 then beforeValue i1 else None | _ -> let i1 = startOfLident text i in let ident = String.sub text i1 (i - i1 + 1) in @@ -103,7 +103,7 @@ let findJsxContext text offset = let i = skipWhite text (i - 1) in let i1 = startOfLident text i in let ident = String.sub text i1 (i - i1 + 1) in - match ident = "" with true -> None | false -> loop (i1 - 1)) + match ident with "" -> None | _ -> loop (i1 - 1)) | _ -> None else None in @@ -135,9 +135,7 @@ let findCompletable text offset = let mkPath s = let len = String.length s in let parts = Str.split (Str.regexp_string ".") s in - let parts = - match s.[len - 1] = '.' with true -> parts @ [""] | false -> parts - in + let parts = match s.[len - 1] with '.' -> parts @ [""] | _ -> parts in match parts with | [id] when String.lowercase_ascii id = id -> ( match findJsxContext text (offset - len - 1) with @@ -149,14 +147,13 @@ let findCompletable text offset = let mkPipe off partialName = let off = skipWhite text off in let rec loop i = - match i < 0 with - | true -> Some (PipeId (String.sub text 0 (i - 1))) - | false -> ( + if i < 0 then Some (PipeId (String.sub text 0 (i - 1))) + else match text.[i] with | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '.' | '_' -> loop (i - 1) | '"' when i == off -> Some PipeString | ']' when i == off -> Some PipeArray - | _ -> Some (PipeId (String.sub text (i + 1) (off - i)))) + | _ -> Some (PipeId (String.sub text (i + 1) (off - i))) in match loop off with | None -> None @@ -165,9 +162,8 @@ let findCompletable text offset = let suffix i = String.sub text (i + 1) (offset - (i + 1)) in let rec loop i = - match i < 0 with - | true -> Some (mkPath (suffix i)) - | false -> ( + if i < 0 then Some (mkPath (suffix i)) + else match text.[i] with | '>' when i > 0 && text.[i - 1] = '-' -> let rest = suffix i in @@ -179,10 +175,7 @@ let findCompletable text offset = Some (Clabel (funPath, labelPrefix)) | '@' -> Some (Cdecorator (suffix i)) | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '.' | '_' -> loop (i - 1) - | _ -> ( - match i = offset - 1 with - | true -> None - | false -> Some (mkPath (suffix i)))) + | _ -> if i = offset - 1 then None else Some (mkPath (suffix i)) in if offset > String.length text || offset = 0 then None else loop (offset - 1) @@ -257,18 +250,15 @@ let findOpens text offset = let offsetOfLine text line = let ln = String.length text in let rec loop i lno = - match i >= ln with - | true -> None - | false -> ( + if i >= ln then None + else match text.[i] with - | '\n' -> ( - match lno = line - 1 with - | true -> Some (i + 1) - | false -> loop (i + 1) (lno + 1)) - | _ -> loop (i + 1) lno) + | '\n' -> if lno = line - 1 then Some (i + 1) else loop (i + 1) (lno + 1) + | _ -> loop (i + 1) lno in - match line = 0 with true -> Some 0 | false -> loop 0 0 + match line with 0 -> Some 0 | _ -> loop 0 0 let positionToOffset text (line, character) = - let open Infix in - offsetOfLine text line |?>> fun bol -> bol + character + match offsetOfLine text line with + | None -> None + | Some bol -> Some (bol + character) diff --git a/analysis/src/PrepareUtils.ml b/analysis/src/PrepareUtils.ml index 80da5040e..975b5402d 100644 --- a/analysis/src/PrepareUtils.ml +++ b/analysis/src/PrepareUtils.ml @@ -13,13 +13,13 @@ let combine one two = | None, None -> None | Some a, None -> Some a | None, Some b -> Some b - | Some a, Some b -> ( match a = b with true -> Some a | false -> Some 0 ) + | Some a, Some b -> ( if a = b then Some a else Some 0 ) let trimFirst num string = let length = String.length string in - match length > num with - | true -> String.sub string num (length - num) - | false -> "" + if length > num then +String.sub string num (length - num) + else "" let cleanOffStars doc = let lines = Str.split (Str.regexp_string "\n") doc in @@ -27,11 +27,11 @@ let cleanOffStars doc = match lines with | [] -> None | [one] -> ( - match String.trim one = "" with true -> None | false -> findStars one ) + match String.trim one with "" -> None | _ -> findStars one ) | one :: rest -> ( - match String.trim one = "" with - | true -> loop rest - | false -> combine (findStars one) (loop rest) ) + match String.trim one with + | "" -> loop rest + | _ -> combine (findStars one) (loop rest) ) in let num = loop lines in match num with diff --git a/analysis/src/ProcessCmt.ml b/analysis/src/ProcessCmt.ml index 6cb61490c..3e22874ea 100644 --- a/analysis/src/ProcessCmt.ml +++ b/analysis/src/ProcessCmt.ml @@ -530,9 +530,9 @@ let extraForFile ~(file : SharedTypes.file) = Hashtbl.replace extra.internalReferences stamp (loc :: - (match Hashtbl.mem extra.internalReferences stamp with - | true -> Hashtbl.find extra.internalReferences stamp - | false -> [])) + (if Hashtbl.mem extra.internalReferences stamp then + Hashtbl.find extra.internalReferences stamp + else [])) in file.stamps.modules |> Hashtbl.iter (fun stamp d -> @@ -689,18 +689,18 @@ struct Hashtbl.replace extra.internalReferences stamp (loc :: - (match Hashtbl.mem extra.internalReferences stamp with - | true -> Hashtbl.find extra.internalReferences stamp - | false -> [])) + (if Hashtbl.mem extra.internalReferences stamp then + Hashtbl.find extra.internalReferences stamp + else [])) let addExternalReference moduleName path tip loc = (* TODO need to follow the path, and be able to load the files to follow module references... *) Hashtbl.replace extra.externalReferences moduleName ((path, tip, loc) :: - (match Hashtbl.mem extra.externalReferences moduleName with - | true -> Hashtbl.find extra.externalReferences moduleName - | false -> [])) + (if Hashtbl.mem extra.externalReferences moduleName then + Hashtbl.find extra.externalReferences moduleName + else [])) let env = fileEnv Collector.file @@ -720,9 +720,9 @@ struct | `Exported (env, name) -> ( match Hashtbl.find_opt - (match tip = Type with - | true -> env.qExported.types - | false -> env.qExported.values) + (match tip with + | Type -> env.qExported.types + | _ -> env.qExported.values) name with | Some stamp -> diff --git a/analysis/src/References.ml b/analysis/src/References.ml index 4bd7e7f24..a9cb727fe 100644 --- a/analysis/src/References.ml +++ b/analysis/src/References.ml @@ -434,9 +434,8 @@ let forLocalStamp ~package ~file ~extra stamp tip = let refs = refs |> Utils.filterMap (fun (p, t, l) -> - match p = path && t = tip with - | true -> Some l - | false -> None) + if p = path && t = tip then Some l + else None) in Some (file.uri, refs)))) in diff --git a/analysis/src/Shared.ml b/analysis/src/Shared.ml index b9fee0ccd..cf9c1efcb 100644 --- a/analysis/src/Shared.ml +++ b/analysis/src/Shared.ml @@ -39,9 +39,9 @@ let typeTbl = Hashtbl.create 1 let typeToString (t : Types.type_expr) = match - match !cacheTypeToString with - | true -> Hashtbl.find_opt typeTbl (t.id, t) - | false -> None + if !cacheTypeToString then + Hashtbl.find_opt typeTbl (t.id, t) + else None with | None -> let s = PrintType.printExpr t in diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index f9c5ec083..57a0f84a7 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -24,7 +24,7 @@ let getCmt ?(interface = true) p = match p with | Impl (c, _) | Intf (c, _) -> c | IntfAndImpl (cint, _, cimpl, _) -> ( - match interface with true -> cint | false -> cimpl) + if interface then cint else cimpl) type visibilityPath = | File of Uri2.t * string @@ -235,4 +235,4 @@ let locationToString ({Location.loc_start; loc_end}, loc) = pos2.character (locToString loc) (* for debugging *) -let _ = locationToString \ No newline at end of file +let _ = locationToString From 8e72d4da902449c8a426581a484604ada121c1d5 Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Mon, 26 Apr 2021 04:55:12 -0700 Subject: [PATCH 2/2] Format --- analysis/src/Files.ml | 11 ++++------- analysis/src/FindFiles.ml | 7 ++----- analysis/src/NewCompletions.ml | 3 +-- analysis/src/PrepareUtils.ml | 13 +++++-------- analysis/src/ProcessCmt.ml | 4 ++-- analysis/src/Shared.ml | 22 +++++++++------------- analysis/src/SharedTypes.ml | 3 +-- 7 files changed, 24 insertions(+), 39 deletions(-) diff --git a/analysis/src/Files.ml b/analysis/src/Files.ml index 5bb17c03f..3372c4eef 100644 --- a/analysis/src/Files.ml +++ b/analysis/src/Files.ml @@ -6,9 +6,8 @@ let removeExtraDots path = (* Win32 & MacOS are case-insensitive *) let pathEq = - if Sys.os_type = "Linux" - then fun a b -> a = b -else fun a b -> String.lowercase_ascii a = String.lowercase_ascii b + if Sys.os_type = "Linux" then fun a b -> a = b + else fun a b -> String.lowercase_ascii a = String.lowercase_ascii b let pathStartsWith text prefix = String.length prefix <= String.length text @@ -38,9 +37,7 @@ let relpath base path = loop (split Filename.dir_sep base) (split Filename.dir_sep path) in String.concat Filename.dir_sep - ((match base with - | [] -> ["."] - | _ -> List.map (fun _ -> "..") base) + ((match base with [] -> ["."] | _ -> List.map (fun _ -> "..") base) @ path) |> removeExtraDots @@ -99,7 +96,7 @@ let rec collect ?(checkDir = fun _ -> true) path test = collect ~checkDir (Filename.concat path name) test) |> List.concat else [] - | _ -> ( if test path then [path] else []) + | _ -> if test path then [path] else [] let fileConcat a b = if diff --git a/analysis/src/FindFiles.ml b/analysis/src/FindFiles.ml index 5abe4d49a..0d0a3a20c 100644 --- a/analysis/src/FindFiles.ml +++ b/analysis/src/FindFiles.ml @@ -16,8 +16,7 @@ let getSourceDirectories ~includeDev base config = Json.get "dir" item |?> Json.string |? "Must specify directory" in let typ = - if includeDev then - "lib" + if includeDev then "lib" else item |> Json.get "type" |?> Json.string |? "lib" in if typ = "dev" then [] @@ -109,9 +108,7 @@ let collectFiles directory = let source = Utils.find (fun name -> - if getName name = modName then - Some (directory /+ name) - else None) + if getName name = modName then Some (directory /+ name) else None) sources in (modName, SharedTypes.Impl (compiled, source))) diff --git a/analysis/src/NewCompletions.ml b/analysis/src/NewCompletions.ml index 2f3ba3be6..9fc60cbd5 100644 --- a/analysis/src/NewCompletions.ml +++ b/analysis/src/NewCompletions.ml @@ -553,8 +553,7 @@ let processCompletable ~findItems ~package ~rawOpens |> String.concat "." in let completionName name = - if modulePathMinusOpens = "" then - name + if modulePathMinusOpens = "" then name else modulePathMinusOpens ^ "." ^ name in let parts = modulePath @ [partialName] in diff --git a/analysis/src/PrepareUtils.ml b/analysis/src/PrepareUtils.ml index 975b5402d..626069295 100644 --- a/analysis/src/PrepareUtils.ml +++ b/analysis/src/PrepareUtils.ml @@ -13,25 +13,22 @@ let combine one two = | None, None -> None | Some a, None -> Some a | None, Some b -> Some b - | Some a, Some b -> ( if a = b then Some a else Some 0 ) + | Some a, Some b -> if a = b then Some a else Some 0 let trimFirst num string = let length = String.length string in - if length > num then -String.sub string num (length - num) - else "" + if length > num then String.sub string num (length - num) else "" let cleanOffStars doc = let lines = Str.split (Str.regexp_string "\n") doc in let rec loop lines = match lines with | [] -> None - | [one] -> ( - match String.trim one with "" -> None | _ -> findStars one ) + | [one] -> ( match String.trim one with "" -> None | _ -> findStars one) | one :: rest -> ( match String.trim one with | "" -> loop rest - | _ -> combine (findStars one) (loop rest) ) + | _ -> combine (findStars one) (loop rest)) in let num = loop lines in match num with @@ -42,4 +39,4 @@ let cleanOffStars doc = | one :: rest -> (if findStars one <> None then trimFirst num one else String.trim one) ^ "\n" - ^ String.concat "\n" (rest |> List.map (trimFirst num)) ) + ^ String.concat "\n" (rest |> List.map (trimFirst num))) diff --git a/analysis/src/ProcessCmt.ml b/analysis/src/ProcessCmt.ml index 3e22874ea..7a20404ad 100644 --- a/analysis/src/ProcessCmt.ml +++ b/analysis/src/ProcessCmt.ml @@ -531,8 +531,8 @@ let extraForFile ~(file : SharedTypes.file) = (loc :: (if Hashtbl.mem extra.internalReferences stamp then - Hashtbl.find extra.internalReferences stamp - else [])) + Hashtbl.find extra.internalReferences stamp + else [])) in file.stamps.modules |> Hashtbl.iter (fun stamp d -> diff --git a/analysis/src/Shared.ml b/analysis/src/Shared.ml index cf9c1efcb..4f02164d0 100644 --- a/analysis/src/Shared.ml +++ b/analysis/src/Shared.ml @@ -4,16 +4,16 @@ let tryReadCmt cmt = match Cmt_format.read_cmt cmt with | exception Cmi_format.Error err -> Error - ( "Failed to load " ^ cmt ^ " as a cmt w/ ocaml version " ^ "406" - ^ ", error: " + ("Failed to load " ^ cmt ^ " as a cmt w/ ocaml version " ^ "406" + ^ ", error: " ^ - ( Cmi_format.report_error Format.str_formatter err; - Format.flush_str_formatter () ) ) + (Cmi_format.report_error Format.str_formatter err; + Format.flush_str_formatter ())) | exception err -> Error - ( "Invalid cmt format " ^ cmt - ^ " - probably wrong ocaml version, expected " ^ Config.version ^ " : " - ^ Printexc.to_string err ) + ("Invalid cmt format " ^ cmt + ^ " - probably wrong ocaml version, expected " ^ Config.version ^ " : " + ^ Printexc.to_string err) | x -> Ok x (** TODO move to the Process_ stuff *) @@ -26,9 +26,7 @@ let rec dig typ = let digConstructor expr = let expr = dig expr in - match expr.desc with - | Tconstr (path, _args, _memo) -> Some path - | _ -> None + match expr.desc with Tconstr (path, _args, _memo) -> Some path | _ -> None let declToString ?(recStatus = Types.Trec_not) name t = PrintType.printDecl ~recStatus name t @@ -39,9 +37,7 @@ let typeTbl = Hashtbl.create 1 let typeToString (t : Types.type_expr) = match - if !cacheTypeToString then - Hashtbl.find_opt typeTbl (t.id, t) - else None + if !cacheTypeToString then Hashtbl.find_opt typeTbl (t.id, t) else None with | None -> let s = PrintType.printExpr t in diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 57a0f84a7..9218d959b 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -23,8 +23,7 @@ let getSrc p = let getCmt ?(interface = true) p = match p with | Impl (c, _) | Intf (c, _) -> c - | IntfAndImpl (cint, _, cimpl, _) -> ( - if interface then cint else cimpl) + | IntfAndImpl (cint, _, cimpl, _) -> if interface then cint else cimpl type visibilityPath = | File of Uri2.t * string