From 7c93e74b3bb210c81a19cd58b45c33c5b328a1a1 Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Tue, 13 Apr 2021 07:46:19 -0700 Subject: [PATCH] Remove RResult --- src/RResult.ml | 6 ----- src/References.ml | 64 +++++++++++++++++++++++++++-------------------- src/State.ml | 11 ++++---- 3 files changed, 42 insertions(+), 39 deletions(-) delete mode 100644 src/RResult.ml diff --git a/src/RResult.ml b/src/RResult.ml deleted file mode 100644 index 45afa8ae..00000000 --- a/src/RResult.ml +++ /dev/null @@ -1,6 +0,0 @@ -let toOptionAndLog err = - match err with - | Error e -> - Log.log e; - None - | Ok v -> Some v diff --git a/src/References.ml b/src/References.ml index 674071ee..07b531ad 100644 --- a/src/References.ml +++ b/src/References.ml @@ -64,27 +64,33 @@ let definedForLoc ~file ~getModule locKind = | NotFound -> None | LocalReference (stamp, tip) | Definition (stamp, tip) -> inner ~file stamp tip - | GlobalReference (moduleName, path, tip) -> - (maybeLog ("Getting global " ^ moduleName); - match getModule moduleName with - | None -> Error ("Cannot get module " ^ moduleName) - | Some file -> ( - let env = Query.fileEnv file in - match Query.resolvePath ~env ~path ~getModule with - | None -> Error ("Cannot resolve path " ^ pathToString path) - | Some (env, name) -> ( - match Query.exportedForTip ~env name tip with - | None -> - Error ("Exported not found for tip " ^ name ^ " > " ^ tipToString tip) - | Some stamp -> ( - maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name); - - match inner ~file:env.file stamp tip with - | None -> Error "could not get defined" - | Some res -> - maybeLog "Yes!! got it"; - Ok res)))) - |> RResult.toOptionAndLog + | GlobalReference (moduleName, path, tip) -> ( + maybeLog ("Getting global " ^ moduleName); + match getModule moduleName with + | None -> + Log.log ("Cannot get module " ^ moduleName); + None + | Some file -> ( + let env = Query.fileEnv file in + match Query.resolvePath ~env ~path ~getModule with + | None -> + Log.log ("Cannot resolve path " ^ pathToString path); + None + | Some (env, name) -> ( + match Query.exportedForTip ~env name tip with + | None -> + Log.log + ("Exported not found for tip " ^ name ^ " > " ^ tipToString tip); + None + | Some stamp -> ( + maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name); + match inner ~file:env.file stamp tip with + | None -> + Log.log "could not get defined"; + None + | Some res -> + maybeLog "Yes!! got it"; + Some res)))) let alternateDeclared ~file ~pathsForModule ~getUri declared tip = match Hashtbl.find_opt pathsForModule file.moduleName with @@ -97,9 +103,11 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip = let intfUri = Uri2.fromPath intf in let implUri = Uri2.fromPath impl in if intfUri = file.uri then - match getUri implUri |> RResult.toOptionAndLog with - | None -> None - | Some (file, extra) -> ( + match getUri implUri with + | Error e -> + Log.log e; + None + | Ok (file, extra) -> ( match Query.declaredForExportedTip ~stamps:file.stamps ~exported:file.contents.exported declared.name.txt tip @@ -107,9 +115,11 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip = | None -> None | Some declared -> Some (file, extra, declared)) else - match getUri intfUri |> RResult.toOptionAndLog with - | None -> None - | Some (file, extra) -> ( + match getUri intfUri with + | Error e -> + Log.log e; + None + | Ok (file, extra) -> ( match Query.declaredForExportedTip ~stamps:file.stamps ~exported:file.contents.exported declared.name.txt tip diff --git a/src/State.ml b/src/State.ml index dcb6f9a2..a29a032b 100644 --- a/src/State.ml +++ b/src/State.ml @@ -15,12 +15,11 @@ let converter src = let newDocsForCmt ~moduleName cmtCache changed cmt src = let uri = Uri2.fromPath (src |? cmt) in - match - Process_406.fileForCmt ~moduleName ~uri cmt (converter src) - |> RResult.toOptionAndLog - with - | None -> None - | Some file -> + match Process_406.fileForCmt ~moduleName ~uri cmt (converter src) with + | Error e -> + Log.log e; + None + | Ok file -> Hashtbl.replace cmtCache cmt (changed, file); Some file