Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit c498478

Browse files
committed
Remove orError
1 parent 5e46a50 commit c498478

File tree

3 files changed

+24
-44
lines changed

3 files changed

+24
-44
lines changed

src/Packages.ml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ let newBsPackage rootPath =
2525
match FindFiles.findDependencyFiles ~debug:true rootPath config with
2626
| Error e -> Error e
2727
| Ok (dependencyDirectories, dependencyModules) -> (
28-
match
29-
compiledBase
30-
|> RResult.orError
31-
"You need to run bsb first so that rescript-editor-support can \
32-
access the compiled artifacts.\n\
33-
Once you've run bsb, restart the language server."
34-
with
35-
| Error e -> Error e
36-
| Ok compiledBase ->
28+
match compiledBase with
29+
| None ->
30+
Error
31+
"You need to run bsb first so that rescript-editor-support can \
32+
access the compiled artifacts.\n\
33+
Once you've run bsb, restart the language server."
34+
| Some compiledBase ->
3735
Ok
3836
(let namespace = FindFiles.getNamespace config in
3937
let localSourceDirs =
@@ -118,12 +116,9 @@ let getPackage ~uri state =
118116
if Hashtbl.mem state.rootForUri uri then
119117
Ok (Hashtbl.find state.packagesByRoot (Hashtbl.find state.rootForUri uri))
120118
else
121-
match
122-
findRoot ~uri state.packagesByRoot
123-
|> RResult.orError "No root directory found"
124-
with
125-
| Error e -> Error e
126-
| Ok root -> (
119+
match findRoot ~uri state.packagesByRoot with
120+
| None -> Error "No root directory found"
121+
| Some root -> (
127122
match
128123
match root with
129124
| `Root rootPath ->

src/RResult.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
let resultOfOption err v = match v with Some v -> Ok v | None -> Error err
2-
3-
let orError = resultOfOption
4-
51
let toOptionAndLog err =
62
match err with
73
| Error e ->

src/References.ml

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,22 @@ let definedForLoc ~file ~getModule locKind =
6666
inner ~file stamp tip
6767
| GlobalReference (moduleName, path, tip) ->
6868
(maybeLog ("Getting global " ^ moduleName);
69-
match
70-
getModule moduleName
71-
|> RResult.orError ("Cannot get module " ^ moduleName)
72-
with
73-
| Error e -> Error e
74-
| Ok file -> (
69+
match getModule moduleName with
70+
| None -> Error ("Cannot get module " ^ moduleName)
71+
| Some file -> (
7572
let env = Query.fileEnv file in
76-
match
77-
Query.resolvePath ~env ~path ~getModule
78-
|> RResult.orError ("Cannot resolve path " ^ pathToString path)
79-
with
80-
| Error e -> Error e
81-
| Ok (env, name) -> (
82-
match
83-
Query.exportedForTip ~env name tip
84-
|> RResult.orError
85-
("Exported not found for tip " ^ name ^ " > " ^ tipToString tip)
86-
with
87-
| Error e -> Error e
88-
| Ok stamp -> (
73+
match Query.resolvePath ~env ~path ~getModule with
74+
| None -> Error ("Cannot resolve path " ^ pathToString path)
75+
| Some (env, name) -> (
76+
match Query.exportedForTip ~env name tip with
77+
| None ->
78+
Error ("Exported not found for tip " ^ name ^ " > " ^ tipToString tip)
79+
| Some stamp -> (
8980
maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name);
90-
match
91-
inner ~file:env.file stamp tip
92-
|> RResult.orError "could not get defined"
93-
with
94-
| Error e -> Error e
95-
| Ok res ->
81+
82+
match inner ~file:env.file stamp tip with
83+
| None -> Error "could not get defined"
84+
| Some res ->
9685
maybeLog "Yes!! got it";
9786
Ok res))))
9887
|> RResult.toOptionAndLog

0 commit comments

Comments
 (0)