1
1
open Infix
2
2
open TopTypes
3
3
4
- let escapePreprocessingFlags flag =
5
- (* ppx escaping not supported on windows yet *)
6
- if Sys. os_type = " Win32" then flag
7
- else
8
- let parts = Utils. split_on_char ' ' flag in
9
- match parts with
10
- | (("-ppx" | "-pp" ) as flag ) :: rest ->
11
- flag ^ " " ^ Utils. maybeQuoteFilename (String. concat " " rest)
12
- | _ -> flag
13
-
14
4
(* Creates the `pathsForModule` hashtbl, which maps a `moduleName` to it's `paths` (the ml/re, mli/rei, cmt, and cmti files) *)
15
5
let makePathsForModule (localModules : (string * SharedTypes.paths) list )
16
6
(dependencyModules : (string * SharedTypes.paths) list ) =
17
7
let pathsForModule = Hashtbl. create 30 in
18
8
dependencyModules
19
- |> List. iter (fun (modName , paths ) -> Hashtbl. replace pathsForModule modName paths);
9
+ |> List. iter (fun (modName , paths ) ->
10
+ Hashtbl. replace pathsForModule modName paths);
20
11
localModules
21
- |> List. iter (fun (modName , paths ) -> Hashtbl. replace pathsForModule modName paths);
12
+ |> List. iter (fun (modName , paths ) ->
13
+ Hashtbl. replace pathsForModule modName paths);
22
14
pathsForModule
23
15
24
16
let newBsPackage rootPath =
@@ -52,25 +44,25 @@ let newBsPackage rootPath =
52
44
let localModules =
53
45
FindFiles. findProjectFiles ~debug: true namespace rootPath
54
46
localSourceDirs compiledBase
55
- (*
47
+ (*
56
48
|> List.map(((name, paths)) => (switch (namespace) {
57
49
| None => name
58
50
| Some(n) => name ++ "-" ++ n }, paths)); *)
59
51
in
60
52
Log. log
61
- ( " -- All local modules found: "
62
- ^ string_of_int (List. length localModules) );
53
+ (" -- All local modules found: "
54
+ ^ string_of_int (List. length localModules));
63
55
localModules
64
56
|> List. iter (fun (name , paths ) ->
65
- Log. log name;
66
- match paths with
67
- | SharedTypes. Impl (cmt , _ ) -> Log. log (" impl " ^ cmt)
68
- | Intf (cmi , _ ) -> Log. log (" intf " ^ cmi)
69
- | _ -> Log. log " Both" );
57
+ Log. log name;
58
+ match paths with
59
+ | SharedTypes. Impl (cmt , _ ) -> Log. log (" impl " ^ cmt)
60
+ | Intf (cmi , _ ) -> Log. log (" intf " ^ cmi)
61
+ | _ -> Log. log " Both" );
70
62
let pathsForModule =
71
63
makePathsForModule localModules dependencyModules
72
64
in
73
- let opens =
65
+ let opens_from_namespace =
74
66
match namespace with
75
67
| None -> []
76
68
| Some namespace ->
@@ -80,27 +72,25 @@ let newBsPackage rootPath =
80
72
[FindFiles. nameSpaceToName namespace]
81
73
in
82
74
Log. log (" Dependency dirs " ^ String. concat " " dependencyDirectories);
83
- let opens =
84
- let flags =
85
- MerlinFile. getFlags rootPath
86
- |> RResult. withDefault [" " ]
87
- |> List. map escapePreprocessingFlags
88
- in
89
- let opens =
75
+ let opens_from_bsc_flags =
76
+ match Json. get " bsc-flags" config |?> Json. array with
77
+ | Some l ->
90
78
List. fold_left
91
79
(fun opens item ->
92
- let parts = Utils. split_on_char ' ' item in
93
- let rec loop items =
94
- match items with
95
- | "-open" :: name :: rest -> name :: loop rest
96
- | _ :: rest -> loop rest
97
- | [] -> []
98
- in
99
- opens @ loop parts)
100
- opens flags
101
- in
102
- opens
80
+ match item |> Json. string with
81
+ | None -> opens
82
+ | Some s -> (
83
+ let parts = Utils. split_on_char ' ' s in
84
+ match parts with
85
+ | "-open" :: name :: _ -> name :: opens
86
+ | _ -> opens))
87
+ [] l
88
+ | None -> []
89
+ in
90
+ let opens =
91
+ List. rev_append opens_from_bsc_flags opens_from_namespace
103
92
in
93
+ Log. log (" Opens from bsconfig: " ^ (opens |> String. concat " " ));
104
94
let interModuleDependencies =
105
95
Hashtbl. create (List. length localModules)
106
96
in
@@ -112,7 +102,7 @@ let newBsPackage rootPath =
112
102
opens;
113
103
namespace;
114
104
interModuleDependencies;
115
- }) ) )
105
+ })) )
116
106
117
107
let findRoot ~uri packagesByRoot =
118
108
let path = Uri2. toPath uri in
@@ -147,7 +137,7 @@ let getPackage ~uri state =
147
137
| Ok package ->
148
138
Hashtbl. replace state.rootForUri uri package.rootPath;
149
139
Hashtbl. replace state.packagesByRoot package.rootPath package;
150
- Ok package )
140
+ Ok package)
151
141
with
152
142
| Error e -> Error e
153
- | Ok package -> Ok package )
143
+ | Ok package -> Ok package)
0 commit comments