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

Commit 3100963

Browse files
committed
Clean up Infix.
1 parent e90cdd8 commit 3100963

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

src/rescript-editor-support/EditorSupportCommands.re

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
open Infix;
21
module J = JsonShort;
32

43
let dumpLocations = (state, ~package, ~file, ~extra, ~selectPos, uri) => {
@@ -51,10 +50,12 @@ let dumpLocations = (state, ~package, ~file, ~extra, ~selectPos, uri) => {
5150
~markdown=!state.settings.clientNeedsPlainText,
5251
~showPath=state.settings.showModulePathOnHover,
5352
loc,
54-
)
55-
|? "";
53+
);
5654
let hover =
57-
hoverText == "" ? [] : [("hover", dedupHover(hoverText, i))];
55+
switch (hoverText) {
56+
| None => []
57+
| Some(s) => [("hover", dedupHover(s, i))]
58+
};
5859

5960
let uriLocOpt =
6061
References.definitionForLoc(
@@ -134,7 +135,7 @@ let dump = files => {
134135
files
135136
|> List.iter(pathWithPos => {
136137
let (filePath, selectPos) = pathWithPos |> splitLineChar;
137-
let filePath = maybeConcat(Unix.getcwd(), filePath);
138+
let filePath = Files.maybeConcat(Unix.getcwd(), filePath);
138139
let uri = Utils.toUri(filePath);
139140
let result =
140141
switch (State.getFullFromCmt(uri, state)) {
@@ -174,7 +175,7 @@ let complete = (~pathWithPos, ~currentFile) => {
174175
};
175176
switch (pathWithPos |> splitLineChar) {
176177
| (filePath, Some(pos)) =>
177-
let filePath = maybeConcat(Unix.getcwd(), filePath);
178+
let filePath = Files.maybeConcat(Unix.getcwd(), filePath);
178179
let uri = Utils.toUri(filePath);
179180
let result =
180181
switch (State.getFullFromCmt(uri, state)) {

src/rescript-editor-support/Files.re

+20
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,23 @@ let rec collect = (~checkDir=_ => true, path, test) =>
187187
}
188188
| _ => test(path) ? [path] : []
189189
};
190+
191+
let fileConcat = (a, b) =>
192+
if (b != ""
193+
&& b.[0] == '.'
194+
&& String.length(b) >= 2
195+
&& b.[1] == Filename.dir_sep.[0]) {
196+
Filename.concat(a, String.sub(b, 2, String.length(b) - 2));
197+
} else {
198+
Filename.concat(a, b);
199+
};
200+
201+
let isFullPath = b =>
202+
b.[0] == '/' || Sys.win32 && String.length(b) > 1 && b.[1] == ':';
203+
204+
let maybeConcat = (a, b) =>
205+
if (b != "" && isFullPath(b)) {
206+
b;
207+
} else {
208+
fileConcat(a, b);
209+
};

src/rescript-editor-support/FindFiles.re

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let findProjectFiles =
147147
(~debug, namespace, root, sourceDirectories, compiledBase) => {
148148
let files =
149149
sourceDirectories
150-
|> List.map(Infix.fileConcat(root))
150+
|> List.map(Files.fileConcat(root))
151151
|> ifDebug(debug, "Source directories", String.concat(" - "))
152152
|> List.map(name => Files.collect(name, isSourceFile))
153153
|> List.concat
@@ -308,7 +308,7 @@ let findDependencyFiles = (~debug, base, config) => {
308308
Log.log("Compiled base: " ++ compiledBase);
309309
};
310310
let compiledDirectories =
311-
directories |> List.map(Infix.fileConcat(compiledBase));
311+
directories |> List.map(Files.fileConcat(compiledBase));
312312
let compiledDirectories =
313313
namespace == None
314314
? compiledDirectories

src/rescript-editor-support/Infix.re

+1-21
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ let (|?<) = (o, fn) =>
5252
| Some(v) => fn(v)
5353
};
5454

55-
let fileConcat = (a, b) =>
56-
if (b != ""
57-
&& b.[0] == '.'
58-
&& String.length(b) >= 2
59-
&& b.[1] == Filename.dir_sep.[0]) {
60-
Filename.concat(a, String.sub(b, 2, String.length(b) - 2));
61-
} else {
62-
Filename.concat(a, b);
63-
};
64-
6555
let logIfAbsent = (message, x) =>
6656
switch (x) {
6757
| None =>
@@ -70,14 +60,4 @@ let logIfAbsent = (message, x) =>
7060
| _ => x
7161
};
7262

73-
let isFullPath = b =>
74-
b.[0] == '/' || Sys.win32 && String.length(b) > 1 && b.[1] == ':';
75-
76-
let maybeConcat = (a, b) =>
77-
if (b != "" && isFullPath(b)) {
78-
b;
79-
} else {
80-
fileConcat(a, b);
81-
};
82-
83-
let (/+) = fileConcat;
63+
let (/+) = Files.fileConcat;

src/rescript-editor-support/Packages.re

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ let newBsPackage = (~reportDiagnostics, state, rootPath) => {
112112
"Got source directories " ++ String.concat(" - ", localSourceDirs),
113113
);
114114
let localCompiledDirs =
115-
localSourceDirs |> List.map(Infix.fileConcat(compiledBase));
115+
localSourceDirs |> List.map(Files.fileConcat(compiledBase));
116116
let localCompiledDirs =
117117
namespace == None
118118
? localCompiledDirs : [compiledBase, ...localCompiledDirs];

0 commit comments

Comments
 (0)