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

Commit 9b7fb53

Browse files
committed
Don't read .merlin file but get opens from bsconfig.
1 parent 6efa1b2 commit 9b7fb53

File tree

6 files changed

+41
-103
lines changed

6 files changed

+41
-103
lines changed

src/Log.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let spamError = ref false
1+
let spamError = ref true
22

33
let log msg =
44
if !spamError then (

src/MerlinFile.ml

-19
This file was deleted.

src/MerlinFile.mli

-1
This file was deleted.

src/Packages.ml

+32-42
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
open Infix
22
open TopTypes
33

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-
144
(* Creates the `pathsForModule` hashtbl, which maps a `moduleName` to it's `paths` (the ml/re, mli/rei, cmt, and cmti files) *)
155
let makePathsForModule (localModules : (string * SharedTypes.paths) list)
166
(dependencyModules : (string * SharedTypes.paths) list) =
177
let pathsForModule = Hashtbl.create 30 in
188
dependencyModules
19-
|> List.iter (fun (modName, paths) -> Hashtbl.replace pathsForModule modName paths);
9+
|> List.iter (fun (modName, paths) ->
10+
Hashtbl.replace pathsForModule modName paths);
2011
localModules
21-
|> List.iter (fun (modName, paths) -> Hashtbl.replace pathsForModule modName paths);
12+
|> List.iter (fun (modName, paths) ->
13+
Hashtbl.replace pathsForModule modName paths);
2214
pathsForModule
2315

2416
let newBsPackage rootPath =
@@ -52,25 +44,25 @@ let newBsPackage rootPath =
5244
let localModules =
5345
FindFiles.findProjectFiles ~debug:true namespace rootPath
5446
localSourceDirs compiledBase
55-
(*
47+
(*
5648
|> List.map(((name, paths)) => (switch (namespace) {
5749
| None => name
5850
| Some(n) => name ++ "-" ++ n }, paths)); *)
5951
in
6052
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));
6355
localModules
6456
|> 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");
7062
let pathsForModule =
7163
makePathsForModule localModules dependencyModules
7264
in
73-
let opens =
65+
let opens_from_namespace =
7466
match namespace with
7567
| None -> []
7668
| Some namespace ->
@@ -80,27 +72,25 @@ let newBsPackage rootPath =
8072
[FindFiles.nameSpaceToName namespace]
8173
in
8274
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 ->
9078
List.fold_left
9179
(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
10392
in
93+
Log.log ("Opens from bsconfig: " ^ (opens |> String.concat " "));
10494
let interModuleDependencies =
10595
Hashtbl.create (List.length localModules)
10696
in
@@ -112,7 +102,7 @@ let newBsPackage rootPath =
112102
opens;
113103
namespace;
114104
interModuleDependencies;
115-
}) ) )
105+
})))
116106

117107
let findRoot ~uri packagesByRoot =
118108
let path = Uri2.toPath uri in
@@ -147,7 +137,7 @@ let getPackage ~uri state =
147137
| Ok package ->
148138
Hashtbl.replace state.rootForUri uri package.rootPath;
149139
Hashtbl.replace state.packagesByRoot package.rootPath package;
150-
Ok package )
140+
Ok package)
151141
with
152142
| Error e -> Error e
153-
| Ok package -> Ok package )
143+
| Ok package -> Ok package)

src/RResult.ml

-10
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,3 @@ let toOptionAndLog err =
88
Log.log e;
99
None
1010
| Ok v -> Some v
11-
12-
module InfixResult = struct
13-
let ( |?>> ) a fn = match a with Ok a -> Ok (fn a) | Error e -> Error e
14-
15-
let ( |? ) a default = match a with Ok a -> a | Error _ -> default
16-
end
17-
18-
open InfixResult
19-
20-
let withDefault d v = v |? d

src/Utils.ml

+8-30
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let split_on_char sep s =
99
for i = length s - 1 downto 0 do
1010
if unsafe_get s i = sep then (
1111
r := sub s (i + 1) (!j - i - 1) :: !r;
12-
j := i )
12+
j := i)
1313
done;
1414
sub s 0 !j :: !r
1515

@@ -41,10 +41,6 @@ let endsWith s suffix =
4141

4242
let cmtLocFromVscode (line, col) = (line + 1, col)
4343

44-
let sliceToEnd s start =
45-
let l = String.length s in
46-
match start <= l with true -> String.sub s start (l - start) | false -> ""
47-
4844
let locWithinLoc inner outer =
4945
let open Location in
5046
inner.loc_start.pos_cnum >= outer.loc_start.pos_cnum
@@ -64,23 +60,21 @@ let chopLocationEnd loc length =
6460
loc_end = {loc.loc_end with pos_cnum = loc.loc_end.pos_cnum - length};
6561
}
6662

67-
let chopPrefix s prefix = sliceToEnd s (String.length prefix)
68-
6963
(** An optional List.find *)
7064
let rec find fn items =
7165
match items with
7266
| [] -> None
7367
| one :: rest -> (
74-
match fn one with None -> find fn rest | Some x -> Some x )
68+
match fn one with None -> find fn rest | Some x -> Some x)
7569

7670
let dedup items =
7771
let m = Hashtbl.create (List.length items) in
7872
items
7973
|> List.filter (fun a ->
80-
if Hashtbl.mem m a then false
81-
else (
82-
Hashtbl.add m a ();
83-
true ))
74+
if Hashtbl.mem m a then false
75+
else (
76+
Hashtbl.add m a ();
77+
true))
8478

8579
let tupleOfLexing {Lexing.pos_lnum; pos_cnum; pos_bol} =
8680
(pos_lnum - 1, pos_cnum - pos_bol)
@@ -92,27 +86,11 @@ let tupleOfLexing {Lexing.pos_lnum; pos_cnum; pos_bol} =
9286
let locationContainsFuzzy {Location.loc_start; loc_end} (l, c) =
9387
tupleOfLexing loc_start <= (l, c) && tupleOfLexing loc_end >= (l - 5, c)
9488

95-
(*
96-
* Quotes filename when not quoted
97-
* Example:
98-
* myFile.exe -> 'myFile.exe'
99-
* 'myFile.exe' -> 'myFile.exe'
100-
*)
101-
let maybeQuoteFilename filename =
102-
let len = String.length filename in
103-
if len < 1 then ""
104-
else
105-
let firstChar = filename.[0] in
106-
let lastChar = filename.[len - 1] in
107-
match (firstChar, lastChar) with
108-
| '\'', '\'' | '"', '"' -> filename
109-
| _ -> Filename.quote filename
110-
11189
let filterMap f =
11290
let rec aux accu = function
11391
| [] -> List.rev accu
11492
| x :: l -> (
115-
match f x with None -> aux accu l | Some v -> aux (v :: accu) l )
93+
match f x with None -> aux accu l | Some v -> aux (v :: accu) l)
11694
in
11795
aux []
11896

@@ -122,6 +100,6 @@ let filterMapIndex f =
122100
| x :: l -> (
123101
match f i x with
124102
| None -> aux accu i l
125-
| Some v -> aux (v :: accu) (i + 1) l )
103+
| Some v -> aux (v :: accu) (i + 1) l)
126104
in
127105
aux [] 0

0 commit comments

Comments
 (0)