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

Commit 505d2e4

Browse files
authored
Remove unnecessary monadic infixes (#96)
* Remove unnecessary monadic infixes * Remove more unnecessary monadic infixes
1 parent 154bb35 commit 505d2e4

File tree

8 files changed

+280
-332
lines changed

8 files changed

+280
-332
lines changed

src/FindFiles.re

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ let findDependencyFiles = (~debug, base, config) => {
299299
let namespace = getNamespace(inner);
300300
let directories =
301301
getSourceDirectories(~includeDev=false, loc, inner);
302-
/* |! "No compiled base found"; */
303302
switch (BuildSystem.getCompiledBase(loc)) {
304303
| None => None
305304
| Some(compiledBase) =>

src/Infix.re

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ let fold = (o, d, f) =>
4646
| Some(v) => f(v)
4747
};
4848

49-
let (|?<) = (o, fn) =>
50-
switch (o) {
51-
| None => ()
52-
| Some(v) => fn(v)
53-
};
54-
5549
let logIfAbsent = (message, x) =>
5650
switch (x) {
5751
| None =>

src/MessageHandlers.re

Lines changed: 118 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
open RResult;
22
open TopTypes;
3-
open Infix;
43
module J = JsonShort;
54

65
let handlers:
@@ -15,31 +14,26 @@ let handlers:
1514
| Error(e) => Error(e)
1615
| Ok((package, {file, extra})) =>
1716
let position = Utils.cmtLocFromVscode(pos);
18-
(
19-
switch (
20-
References.definitionForPos(
21-
~pathsForModule=package.pathsForModule,
22-
~file,
23-
~extra,
24-
~getUri=State.fileForUri(state),
25-
~getModule=State.fileForModule(state, ~package),
26-
position,
27-
)
28-
) {
29-
| None => None
30-
| Some((uri, loc)) =>
31-
Some(
32-
Ok((
33-
state,
34-
Json.Object([
35-
("uri", Json.String(Uri2.toString(uri))),
36-
("range", Protocol.rangeOfLoc(loc)),
37-
]),
38-
)),
39-
);
40-
}
41-
)
42-
|? Ok((state, Json.Null));
17+
switch (
18+
References.definitionForPos(
19+
~pathsForModule=package.pathsForModule,
20+
~file,
21+
~extra,
22+
~getUri=State.fileForUri(state),
23+
~getModule=State.fileForModule(state, ~package),
24+
position,
25+
)
26+
) {
27+
| None => Ok((state, Json.Null))
28+
| Some((uri, loc)) =>
29+
Ok((
30+
state,
31+
Json.Object([
32+
("uri", Json.String(Uri2.toString(uri))),
33+
("range", Protocol.rangeOfLoc(loc)),
34+
]),
35+
))
36+
}
4337
}
4438
}
4539
}
@@ -114,53 +108,44 @@ let handlers:
114108
switch (State.fileForUri(state, uri)) {
115109
| Error(e) => Error(e)
116110
| Ok((file, extra)) =>
117-
Ok(
118-
Infix.(
119-
(
120-
switch (
121-
References.locForPos(~extra, Utils.cmtLocFromVscode(pos))
122-
) {
123-
| None => None
124-
| Some((_, loc)) =>
125-
switch (
126-
References.allReferencesForLoc(
127-
~pathsForModule=package.pathsForModule,
128-
~file,
129-
~extra,
130-
~allModules=package.localModules,
131-
~getUri=State.fileForUri(state),
132-
~getModule=State.fileForModule(state, ~package),
133-
~getExtra=State.extraForModule(state, ~package),
134-
loc,
135-
)
136-
|> toOptionAndLog
137-
) {
138-
| None => None
139-
| Some(allReferences) =>
140-
Some((
141-
state,
142-
J.l(
143-
allReferences
144-
|> List.map(((fname, references)) => {
145-
let locs =
146-
fname == uri
147-
? List.filter(
148-
loc => !Protocol.locationContains(loc, pos),
149-
references,
150-
)
151-
: references;
152-
locs
153-
|> List.map(loc => Protocol.locationOfLoc(~fname, loc));
154-
})
155-
|> List.concat,
156-
),
157-
));
158-
}
159-
}
111+
switch (References.locForPos(~extra, Utils.cmtLocFromVscode(pos))) {
112+
| None => Ok((state, J.null))
113+
| Some((_, loc)) =>
114+
switch (
115+
References.allReferencesForLoc(
116+
~pathsForModule=package.pathsForModule,
117+
~file,
118+
~extra,
119+
~allModules=package.localModules,
120+
~getUri=State.fileForUri(state),
121+
~getModule=State.fileForModule(state, ~package),
122+
~getExtra=State.extraForModule(state, ~package),
123+
loc,
160124
)
161-
|? (state, J.null)
162-
),
163-
)
125+
|> toOptionAndLog
126+
) {
127+
| None => Ok((state, J.null))
128+
| Some(allReferences) =>
129+
Ok((
130+
state,
131+
J.l(
132+
allReferences
133+
|> List.map(((fname, references)) => {
134+
let locs =
135+
fname == uri
136+
? List.filter(
137+
loc => !Protocol.locationContains(loc, pos),
138+
references,
139+
)
140+
: references;
141+
locs
142+
|> List.map(loc => Protocol.locationOfLoc(~fname, loc));
143+
})
144+
|> List.concat,
145+
),
146+
));
147+
}
148+
};
164149
}
165150
}
166151
}
@@ -181,59 +166,51 @@ let handlers:
181166
switch (RJson.get("newName", params)) {
182167
| Error(e) => Error(e)
183168
| Ok(newName) =>
184-
open Infix;
185-
(
169+
switch (References.locForPos(~extra, Utils.cmtLocFromVscode(pos))) {
170+
| None => Ok((state, J.null))
171+
| Some((_, loc)) =>
186172
switch (
187-
References.locForPos(~extra, Utils.cmtLocFromVscode(pos))
173+
References.allReferencesForLoc(
174+
~file,
175+
~extra,
176+
~pathsForModule=package.pathsForModule,
177+
~allModules=package.localModules,
178+
~getModule=State.fileForModule(state, ~package),
179+
~getUri=State.fileForUri(state),
180+
~getExtra=State.extraForModule(state, ~package),
181+
loc,
182+
)
183+
|> toOptionAndLog
188184
) {
189-
| None => None
190-
| Some((_, loc)) =>
191-
switch (
192-
References.allReferencesForLoc(
193-
~file,
194-
~extra,
195-
~pathsForModule=package.pathsForModule,
196-
~allModules=package.localModules,
197-
~getModule=State.fileForModule(state, ~package),
198-
~getUri=State.fileForUri(state),
199-
~getExtra=State.extraForModule(state, ~package),
200-
loc,
201-
)
202-
|> toOptionAndLog
203-
) {
204-
| None => None
205-
| Some(allReferences) =>
206-
Some(
207-
Ok((
208-
state,
209-
J.o([
210-
(
211-
"changes",
212-
J.o(
213-
allReferences
214-
|> List.map(((fname, references)) =>
215-
(
216-
fname |> Uri2.toString,
217-
J.l(
218-
references
219-
|> List.map(loc =>
220-
J.o([
221-
( "range", Protocol.rangeOfLoc(loc)),
222-
("newText", newName),
223-
])
224-
),
185+
| None => Ok((state, J.null))
186+
| Some(allReferences) =>
187+
Ok((
188+
state,
189+
J.o([
190+
(
191+
"changes",
192+
J.o(
193+
allReferences
194+
|> List.map(((fname, references)) =>
195+
(
196+
fname |> Uri2.toString,
197+
J.l(
198+
references
199+
|> List.map(loc =>
200+
J.o([
201+
( "range", Protocol.rangeOfLoc(loc)),
202+
("newText", newName),
203+
])
225204
),
226-
)
227205
),
228-
),
229-
),
230-
]),
206+
)
207+
),
208+
),
231209
),
232-
))
233-
}
210+
]),
211+
))
234212
}
235-
)
236-
|? Ok((state, J.null))
213+
}
237214
}
238215
}
239216
}
@@ -336,33 +313,28 @@ let handlers:
336313
switch (State.fileForUri(state, uri)) {
337314
| Error(e) => Error(e)
338315
| Ok((file, extra)) =>
339-
{
340-
let pos = Utils.cmtLocFromVscode(pos);
341-
switch (References.locForPos(~extra, pos)) {
342-
| None => None
343-
| Some((location, loc)) =>
344-
switch (
345-
Hover.newHover(
346-
~file,
347-
~getModule=State.fileForModule(state, ~package),
348-
loc,
349-
)
350-
) {
351-
| None => None
352-
| Some(text) =>
353-
Some(
354-
Ok((
355-
state,
356-
J.o([
357-
("range", Protocol.rangeOfLoc(location)),
358-
("contents", text |> Protocol.contentKind),
359-
]),
360-
),
361-
))
362-
}
363-
};
364-
}
365-
|? Ok((state, J.null))
316+
let pos = Utils.cmtLocFromVscode(pos);
317+
switch (References.locForPos(~extra, pos)) {
318+
| None => Ok((state, J.null))
319+
| Some((location, loc)) =>
320+
switch (
321+
Hover.newHover(
322+
~file,
323+
~getModule=State.fileForModule(state, ~package),
324+
loc,
325+
)
326+
) {
327+
| None => Ok((state, J.null))
328+
| Some(text) =>
329+
Ok((
330+
state,
331+
J.o([
332+
("range", Protocol.rangeOfLoc(location)),
333+
("contents", text |> Protocol.contentKind),
334+
]),
335+
))
336+
}
337+
};
366338
}
367339
}
368340
}

0 commit comments

Comments
 (0)