Skip to content

Commit 052bae1

Browse files
committed
Refactor: remove a bunch of Ok/Error.
1 parent 7dae77c commit 052bae1

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

analysis/src/BuildSystem.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ let getBsPlatformDir rootPath =
1313
else result
1414
in
1515
match result with
16-
| Some path -> Ok path
16+
| Some path -> Some path
1717
| None ->
1818
let message = "bs-platform could not be found" in
1919
Log.log message;
20-
Error message
20+
None
2121

2222
let getLibBs root = Files.ifExists (root /+ "lib" /+ "bs")
2323

2424
let getStdlib base =
2525
match getBsPlatformDir base with
26-
| Error e -> Error e
27-
| Ok bsPlatformDir -> Ok (bsPlatformDir /+ "lib" /+ "ocaml")
26+
| None -> None
27+
| Some bsPlatformDir -> Some (bsPlatformDir /+ "lib" /+ "ocaml")

analysis/src/Cmt.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ open SharedTypes
33
let fromUri ~uri =
44
let path = Uri2.toPath uri in
55
match Packages.getPackage ~uri with
6-
| Error message ->
7-
prerr_endline message;
8-
None
9-
| Ok package -> (
6+
| None -> None
7+
| Some package -> (
108
let moduleName =
119
BuildSystem.namespacedName package.namespace (FindFiles.getName path)
1210
in

analysis/src/FindFiles.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ let findDependencyFiles base config =
237237
([], []))
238238
in
239239
match BuildSystem.getStdlib base with
240-
| Error e -> Error e
241-
| Ok stdlibDirectory ->
240+
| None -> None
241+
| Some stdlibDirectory ->
242242
let compiledDirectories, projectFiles =
243243
let files, directories = List.split depFiles in
244244
(List.concat files, List.concat directories)
245245
in
246246
let allFiles = projectFiles @ collectFiles stdlibDirectory in
247-
Ok (compiledDirectories, allFiles)
247+
Some (compiledDirectories, allFiles)

analysis/src/Packages.ml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,24 @@ let makePathsForModule ~projectFilesAndPaths ~dependenciesFilesAndPaths =
1111
Hashtbl.replace pathsForModule modName paths);
1212
pathsForModule
1313

14-
let newBsPackage rootPath =
15-
let path = Filename.concat rootPath "bsconfig.json" in
16-
match Files.readFile path with
17-
| None -> Error ("Unable to read " ^ path)
14+
let newBsPackage ~rootPath =
15+
let bsconfig = Filename.concat rootPath "bsconfig.json" in
16+
match Files.readFile bsconfig with
17+
| None ->
18+
Log.log ("Unable to read " ^ bsconfig);
19+
None
1820
| Some raw -> (
1921
let config = Json.parse raw in
2022
Log.log {|📣 📣 NEW BSB PACKAGE 📣 📣|};
2123
Log.log ("- location: " ^ rootPath);
2224
let libBs = BuildSystem.getLibBs rootPath in
2325
match FindFiles.findDependencyFiles rootPath config with
24-
| Error e -> Error e
25-
| Ok (dependencyDirectories, dependenciesFilesAndPaths) -> (
26+
| None -> None
27+
| Some (dependencyDirectories, dependenciesFilesAndPaths) -> (
2628
match libBs with
27-
| None ->
28-
Error
29-
"Please run the build first so that the editor can analyze the \
30-
project's artifacts."
29+
| None -> None
3130
| Some libBs ->
32-
Ok
31+
Some
3332
(let namespace = FindFiles.getNamespace config in
3433
let sourceDirectories =
3534
FindFiles.getSourceDirectories ~includeDev:true ~baseDir:rootPath
@@ -111,17 +110,20 @@ let findRoot ~uri packagesByRoot =
111110
let getPackage ~uri =
112111
let open SharedTypes in
113112
if Hashtbl.mem state.rootForUri uri then
114-
Ok (Hashtbl.find state.packagesByRoot (Hashtbl.find state.rootForUri uri))
113+
Some (Hashtbl.find state.packagesByRoot (Hashtbl.find state.rootForUri uri))
115114
else
116115
match findRoot ~uri state.packagesByRoot with
117-
| None -> Error "No root directory found"
116+
| None ->
117+
Log.log "No root directory found";
118+
None
118119
| Some (`Root rootPath) ->
119120
Hashtbl.replace state.rootForUri uri rootPath;
120-
Ok (Hashtbl.find state.packagesByRoot (Hashtbl.find state.rootForUri uri))
121+
Some
122+
(Hashtbl.find state.packagesByRoot (Hashtbl.find state.rootForUri uri))
121123
| Some (`Bs rootPath) -> (
122-
match newBsPackage rootPath with
123-
| Error e -> Error e
124-
| Ok package ->
124+
match newBsPackage ~rootPath with
125+
| None -> None
126+
| Some package ->
125127
Hashtbl.replace state.rootForUri uri package.rootPath;
126128
Hashtbl.replace state.packagesByRoot package.rootPath package;
127-
Ok package)
129+
Some package)

0 commit comments

Comments
 (0)