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

Commit ce245dc

Browse files
committed
Some mechanical cleaning
Should be correct
1 parent 8de51da commit ce245dc

File tree

1 file changed

+65
-94
lines changed

1 file changed

+65
-94
lines changed

src/EditorSupportCommands.ml

Lines changed: 65 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ let dumpLocations state ~package ~file ~extra ~selectPos uri =
5656
in
5757
(* Skip if range is all zero, unless it's a module *)
5858
let skipZero =
59-
(not locIsModule) && loc.loc_start |> posIsZero
60-
&& loc.loc_end |> posIsZero
59+
(not locIsModule) && posIsZero loc.loc_start
60+
&& posIsZero loc.loc_end
6161
in
6262
let range = ("range", rangeOfLoc loc) in
6363
( [
@@ -125,60 +125,44 @@ let complete ~path ~line ~col ~currentFile =
125125
print_endline result
126126

127127
let hover state ~file ~line ~col ~extra ~package =
128+
let open TopTypes in
128129
let locations =
129130
extra.SharedTypes.locations
130131
|> List.filter (fun (l, _) -> not l.Location.loc_ghost)
131132
in
132-
let locations =
133-
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
134-
match References.locForPos ~extra:{extra with locations} pos with
135-
| None -> []
136-
| Some l -> [l]
137-
in
138-
let locationsInfo =
139-
locations
140-
|> Utils.filterMap (fun (_, loc) ->
141-
let locIsModule =
142-
match loc with
143-
| SharedTypes.LModule _ | TopLevelModule _ -> true
144-
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
145-
in
146-
let hoverText =
147-
Hover.newHover ~file
148-
~getModule:(State.fileForModule state ~package)
149-
loc
150-
in
151-
let hover =
152-
match hoverText with
153-
| None -> None
154-
| Some s ->
155-
let open Protocol in
156-
Some {contents = s}
157-
in
158-
let uriLocOpt =
159-
References.definitionForLoc ~pathsForModule:package.pathsForModule
160-
~file ~getUri:(State.fileForUri state)
161-
~getModule:(State.fileForModule state ~package)
162-
loc
163-
in
164-
let skipZero =
165-
match uriLocOpt with
166-
| None -> false
167-
| Some (_, loc) ->
168-
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
169-
pos_lnum = 1 && pos_cnum - pos_bol = 0
170-
in
171-
(* Skip if range is all zero, unless it's a module *)
172-
(not locIsModule) && loc.loc_start |> posIsZero
173-
&& loc.loc_end |> posIsZero
174-
in
175-
match hover with
176-
| Some hover when not skipZero -> Some hover
177-
| _ -> None)
178-
in
179-
match locationsInfo with
180-
| [] -> Protocol.null
181-
| head :: _ -> Protocol.stringifyHover head
133+
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
134+
match References.locForPos ~extra:{extra with locations} pos with
135+
| None -> Protocol.null
136+
| Some (_, loc) -> (
137+
let locIsModule =
138+
match loc with
139+
| SharedTypes.LModule _ | TopLevelModule _ -> true
140+
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
141+
in
142+
let uriLocOpt =
143+
References.definitionForLoc ~pathsForModule:package.pathsForModule ~file
144+
~getUri:(State.fileForUri state)
145+
~getModule:(State.fileForModule state ~package)
146+
loc
147+
in
148+
let skipZero =
149+
match uriLocOpt with
150+
| None -> false
151+
| Some (_, loc) ->
152+
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
153+
pos_lnum = 1 && pos_cnum - pos_bol = 0
154+
in
155+
(* Skip if range is all zero, unless it's a module *)
156+
(not locIsModule) && posIsZero loc.loc_start && posIsZero loc.loc_end
157+
in
158+
if skipZero then Protocol.null
159+
else
160+
let hoverText =
161+
Hover.newHover ~file ~getModule:(State.fileForModule state ~package) loc
162+
in
163+
match hoverText with
164+
| None -> Protocol.null
165+
| Some s -> Protocol.stringifyHover {contents = s})
182166

183167
let hover ~path ~line ~col =
184168
let state = TopTypes.empty () in
@@ -198,48 +182,35 @@ let definition state ~file ~line ~col ~extra ~package =
198182
extra.SharedTypes.locations
199183
|> List.filter (fun (l, _) -> not l.Location.loc_ghost)
200184
in
201-
let locations =
202-
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
203-
match References.locForPos ~extra:{extra with locations} pos with
204-
| None -> []
205-
| Some l -> [l]
206-
in
207-
let locationsInfo =
208-
locations
209-
|> Utils.filterMap (fun (_, loc) ->
210-
let locIsModule =
211-
match loc with
212-
| SharedTypes.LModule _ | TopLevelModule _ -> true
213-
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
214-
in
215-
let uriLocOpt =
216-
References.definitionForLoc ~pathsForModule:package.pathsForModule
217-
~file ~getUri:(State.fileForUri state)
218-
~getModule:(State.fileForModule state ~package)
219-
loc
220-
in
221-
let def, skipZero =
222-
match uriLocOpt with
223-
| None -> (None, false)
224-
| Some (uri2, loc) ->
225-
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
226-
pos_lnum = 1 && pos_cnum - pos_bol = 0
227-
in
228-
(* Skip if range is all zero, unless it's a module *)
229-
let skipZero =
230-
(not locIsModule) && loc.loc_start |> posIsZero
231-
&& loc.loc_end |> posIsZero
232-
in
233-
let open Protocol in
234-
( Some {uri = Uri2.toString uri2; range = Utils.cmtLocToRange loc},
235-
skipZero )
236-
in
237-
let skip = skipZero || def = None in
238-
match skip with true -> None | false -> def)
239-
in
240-
match locationsInfo with
241-
| [] -> Protocol.null
242-
| head :: _ -> Protocol.stringifyLocation head
185+
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
186+
match References.locForPos ~extra:{extra with locations} pos with
187+
| None -> Protocol.null
188+
| Some (_, loc) -> (
189+
let locIsModule =
190+
match loc with
191+
| SharedTypes.LModule _ | TopLevelModule _ -> true
192+
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
193+
in
194+
let uriLocOpt =
195+
References.definitionForLoc ~pathsForModule:package.pathsForModule ~file
196+
~getUri:(State.fileForUri state)
197+
~getModule:(State.fileForModule state ~package)
198+
loc
199+
in
200+
match uriLocOpt with
201+
| None -> Protocol.null
202+
| Some (uri2, loc) ->
203+
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
204+
pos_lnum = 1 && pos_cnum - pos_bol = 0
205+
in
206+
(* Skip if range is all zero, unless it's a module *)
207+
let skipZero =
208+
(not locIsModule) && posIsZero loc.loc_start && posIsZero loc.loc_end
209+
in
210+
if skipZero then Protocol.null
211+
else
212+
Protocol.stringifyLocation
213+
{uri = Uri2.toString uri2; range = Utils.cmtLocToRange loc})
243214

244215
let definition ~path ~line ~col =
245216
let state = TopTypes.empty () in

0 commit comments

Comments
 (0)