Skip to content

Commit 95c3a1e

Browse files
committed
Refactor digConstructor.
1 parent e95c809 commit 95c3a1e

File tree

4 files changed

+26
-37
lines changed

4 files changed

+26
-37
lines changed

analysis/.depend

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ src/NewCompletions.cmx : \
5151
src/vendor/compiler-libs-406/types.cmx \
5252
src/SharedTypes.cmx \
5353
src/Shared.cmx \
54+
src/References.cmx \
5455
src/Protocol.cmx \
5556
src/ProcessCmt.cmx \
5657
src/vendor/compiler-libs-406/path.cmx \
5758
src/PartialParser.cmx \
5859
src/Log.cmx \
59-
src/vendor/compiler-libs-406/ident.cmx \
60-
src/Hover.cmx
60+
src/vendor/compiler-libs-406/ident.cmx
6161
src/Packages.cmx : \
6262
src/Utils.cmx \
6363
src/Uri2.cmx \

analysis/src/Hover.ml

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
let digConstructor ~env ~package path =
2-
match ProcessCmt.resolveFromCompilerPath ~env ~package path with
3-
| `Not_found -> None
4-
| `Stamp stamp -> (
5-
match Hashtbl.find_opt env.file.stamps.types stamp with
6-
| None -> None
7-
| Some t -> Some (env, t))
8-
| `Exported (env, name) -> (
9-
match Hashtbl.find_opt env.exported.types name with
10-
| None -> None
11-
| Some stamp -> (
12-
match Hashtbl.find_opt env.file.stamps.types stamp with
13-
| None -> None
14-
| Some t -> Some (env, t)))
15-
| _ -> None
16-
171
let codeBlock code = Printf.sprintf "```rescript\n%s\n```" code
182

193
let showModuleTopLevel ~docstring ~name
@@ -121,7 +105,7 @@ let newHover ~full:{SharedTypes.file; package} locItem =
121105
match typ |> Shared.digConstructor with
122106
| None -> None
123107
| Some path -> (
124-
match digConstructor ~env ~package path with
108+
match References.digConstructor ~env ~package path with
125109
| None -> None
126110
| Some (_env, {docstring; name = {txt}; item = {decl}}) ->
127111
if Utils.isUncurriedInternal path then None

analysis/src/NewCompletions.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~parts =
804804
match declared.item |> Shared.digConstructor with
805805
| None -> []
806806
| Some path -> (
807-
match Hover.digConstructor ~env ~package path with
807+
match References.digConstructor ~env ~package path with
808808
| None -> []
809809
| Some (env, typ) -> (
810810
match
@@ -826,7 +826,7 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~parts =
826826
match attr.typ |> Shared.digConstructor with
827827
| None -> None
828828
| Some path ->
829-
Hover.digConstructor ~env ~package path))
829+
References.digConstructor ~env ~package path))
830830
| _ -> None))
831831
(Some (env, typ))
832832
with
@@ -995,7 +995,7 @@ let processCompletable ~findItems ~full ~package ~rawOpens
995995
let getField ~env ~typ fieldName =
996996
match getConstr typ with
997997
| Some path -> (
998-
match Hover.digConstructor ~env ~package path with
998+
match References.digConstructor ~env ~package path with
999999
| None -> None
10001000
| Some (env1, declared) -> (
10011001
let t = declared.item in
@@ -1166,7 +1166,7 @@ let processCompletable ~findItems ~full ~package ~rawOpens
11661166
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> getObj t1
11671167
| Tobject (tObj, _) -> getFields tObj
11681168
| Tconstr (path, _, _) -> (
1169-
match Hover.digConstructor ~env:envRef.contents ~package path with
1169+
match References.digConstructor ~env:envRef.contents ~package path with
11701170
| Some (env, {item = {decl = {type_manifest = Some tt}}}) ->
11711171
envRef := env;
11721172
getObj tt

analysis/src/References.ml

+19-14
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,22 @@ let definitionForLocItem ~full:{file; package} locItem =
364364
maybeLog ("Got stamp " ^ string_of_int stamp);
365365
definition ~file:env.file ~package stamp tip)))
366366

367+
let digConstructor ~env ~package path =
368+
match ProcessCmt.resolveFromCompilerPath ~env ~package path with
369+
| `Not_found -> None
370+
| `Stamp stamp -> (
371+
match Hashtbl.find_opt env.file.stamps.types stamp with
372+
| None -> None
373+
| Some t -> Some (env, t))
374+
| `Exported (env, name) -> (
375+
match Hashtbl.find_opt env.exported.types name with
376+
| None -> None
377+
| Some stamp -> (
378+
match Hashtbl.find_opt env.file.stamps.types stamp with
379+
| None -> None
380+
| Some t -> Some (env, t)))
381+
| _ -> None
382+
367383
let typeDefinitionForLocItem ~full:{file; package} locItem =
368384
match locItem.locType with
369385
| Constant _ | TopLevelModule _ | LModule _ -> None
@@ -373,20 +389,9 @@ let typeDefinitionForLocItem ~full:{file; package} locItem =
373389
match Shared.digConstructor typ with
374390
| None -> None
375391
| Some path -> (
376-
match ProcessCmt.resolveFromCompilerPath ~env ~package path with
377-
| `Not_found -> None
378-
| `Stamp stamp -> (
379-
match Hashtbl.find_opt env.file.stamps.types stamp with
380-
| None -> None
381-
| Some declared -> Some (env.file.uri, declared.item.decl.type_loc))
382-
| `Exported (env, name) -> (
383-
match Hashtbl.find_opt env.exported.types name with
384-
| None -> None
385-
| Some stamp -> (
386-
match Hashtbl.find_opt env.file.stamps.types stamp with
387-
| None -> None
388-
| Some declared -> Some (env.file.uri, declared.item.decl.type_loc))))
389-
)
392+
match digConstructor ~env ~package path with
393+
| Some (env, declared) -> Some (env.file.uri, declared.item.decl.type_loc)
394+
| None -> None))
390395

391396
let isVisible (declared : _ SharedTypes.declared) =
392397
declared.isExported

0 commit comments

Comments
 (0)