Skip to content

Commit 07fbffa

Browse files
committed
refactor
1 parent 6cced21 commit 07fbffa

File tree

2 files changed

+55
-64
lines changed

2 files changed

+55
-64
lines changed

analysis/src/Hover.ml

+12-15
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,21 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
184184
| None -> None
185185
| Some file -> (
186186
let env = QueryEnv.fromFile file in
187-
match ResolvePath.resolvePath ~env ~path ~package with
187+
match References.exportedForTip ~env ~path ~package ~tip with
188188
| None -> None
189-
| Some (env, name) -> (
190-
match References.exportedForTip ~env ~name tip with
189+
| Some (_env, _name, stamp) -> (
190+
match Stamps.findModule file.stamps stamp with
191191
| None -> None
192-
| Some stamp -> (
193-
match Stamps.findModule file.stamps stamp with
192+
| Some md -> (
193+
match References.resolveModuleReference ~file ~package md with
194194
| None -> None
195-
| Some md -> (
196-
match References.resolveModuleReference ~file ~package md with
197-
| None -> None
198-
| Some (file, declared) ->
199-
let name, docstring =
200-
match declared with
201-
| Some d -> (d.name.txt, d.docstring)
202-
| None -> (file.moduleName, file.structure.docstring)
203-
in
204-
showModule ~docstring ~name ~file declared)))))
195+
| Some (file, declared) ->
196+
let name, docstring =
197+
match declared with
198+
| Some d -> (d.name.txt, d.docstring)
199+
| None -> (file.moduleName, file.structure.docstring)
200+
in
201+
showModule ~docstring ~name ~file declared))))
205202
| LModule NotFound -> None
206203
| TopLevelModule name -> (
207204
match ProcessCmt.fileForModule ~package name with

analysis/src/References.ml

+43-49
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,23 @@ let getConstructor (file : File.t) stamp name =
145145
| Some const -> Some const)
146146
| _ -> None)
147147

148-
let exportedForTip ~(env : QueryEnv.t) ~name (tip : Tip.t) =
149-
match tip with
150-
| Value -> Exported.find env.exported Exported.Value name
151-
| Field _ | Constructor _ | Type ->
152-
Exported.find env.exported Exported.Type name
153-
| Module -> Exported.find env.exported Exported.Module name
148+
let exportedForTip ~env ~path ~package ~(tip : Tip.t) =
149+
match ResolvePath.resolvePath ~env ~path ~package with
150+
| None ->
151+
Log.log ("Cannot resolve path " ^ pathToString path);
152+
None
153+
| Some (env, name) -> (
154+
let kind =
155+
match tip with
156+
| Value -> Exported.Value
157+
| Field _ | Constructor _ | Type -> Exported.Type
158+
| Module -> Exported.Module
159+
in
160+
match Exported.find env.exported kind name with
161+
| None ->
162+
Log.log ("Exported not found for tip " ^ name ^ " > " ^ Tip.toString tip);
163+
None
164+
| Some stamp -> Some (env, name, stamp))
154165

155166
let definedForLoc ~file ~package locKind =
156167
let inner ~file stamp (tip : Tip.t) =
@@ -180,25 +191,17 @@ let definedForLoc ~file ~package locKind =
180191
None
181192
| Some file -> (
182193
let env = QueryEnv.fromFile file in
183-
match ResolvePath.resolvePath ~env ~path ~package with
184-
| None ->
185-
Log.log ("Cannot resolve path " ^ pathToString path);
186-
None
187-
| Some (env, name) -> (
188-
match exportedForTip ~env ~name tip with
194+
match exportedForTip ~env ~path ~package ~tip with
195+
| None -> None
196+
| Some (env, name, stamp) -> (
197+
maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name);
198+
match inner ~file:env.file stamp tip with
189199
| None ->
190-
Log.log
191-
("Exported not found for tip " ^ name ^ " > " ^ Tip.toString tip);
200+
Log.log "could not get defined";
192201
None
193-
| Some stamp -> (
194-
maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name);
195-
match inner ~file:env.file stamp tip with
196-
| None ->
197-
Log.log "could not get defined";
198-
None
199-
| Some res ->
200-
maybeLog "Yes!! got it";
201-
Some res))))
202+
| Some res ->
203+
maybeLog "Yes!! got it";
204+
Some res)))
202205

203206
(** Find alternative declaration: from res in case of interface, or from resi in case of implementation *)
204207
let alternateDeclared ~(file : File.t) ~package (declared : _ Declared.t) tip =
@@ -217,12 +220,10 @@ let alternateDeclared ~(file : File.t) ~package (declared : _ Declared.t) tip =
217220
let path = ModulePath.toPath declared.modulePath declared.name.txt in
218221
maybeLog ("find declared for path " ^ pathToString path);
219222
let declaredOpt =
220-
match ResolvePath.resolvePath ~env ~path ~package with
223+
match exportedForTip ~env ~path ~package ~tip with
221224
| None -> None
222-
| Some (env, name) -> (
223-
match exportedForTip ~env ~name tip with
224-
| None -> None
225-
| Some stamp -> declaredForTip ~stamps:file.stamps stamp tip)
225+
| Some (_env, _name, stamp) ->
226+
declaredForTip ~stamps:file.stamps stamp tip
226227
in
227228
match declaredOpt with
228229
| None -> None
@@ -373,16 +374,12 @@ let definitionForLocItem ~full:{file; package} locItem =
373374
| None -> None
374375
| Some file -> (
375376
let env = QueryEnv.fromFile file in
376-
match ResolvePath.resolvePath ~env ~path ~package with
377+
match exportedForTip ~env ~path ~package ~tip with
377378
| None -> None
378-
| Some (env, name) -> (
379-
maybeLog ("resolved path:" ^ name);
380-
match exportedForTip ~env ~name tip with
381-
| None -> None
382-
| Some stamp ->
383-
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
384-
maybeLog ("Got stamp " ^ string_of_int stamp);
385-
definition ~file:env.file ~package stamp tip)))
379+
| Some (env, _name, stamp) ->
380+
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
381+
maybeLog ("Got stamp " ^ string_of_int stamp);
382+
definition ~file:env.file ~package stamp tip))
386383

387384
let digConstructor ~env ~package path =
388385
match ResolvePath.resolveFromCompilerPath ~env ~package path with
@@ -557,17 +554,14 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
557554
| None -> []
558555
| Some file -> (
559556
let env = QueryEnv.fromFile file in
560-
match ResolvePath.resolvePath ~env ~path ~package with
557+
match exportedForTip ~env ~path ~package ~tip with
561558
| None -> []
562-
| Some (env, name) -> (
563-
match exportedForTip ~env ~name tip with
559+
| Some (env, _name, stamp) -> (
560+
match Cmt.fullFromUri ~uri:env.file.uri with
564561
| None -> []
565-
| Some stamp -> (
566-
match Cmt.fullFromUri ~uri:env.file.uri with
567-
| None -> []
568-
| Some full ->
569-
maybeLog
570-
("Finding references for (global) " ^ Uri.toString env.file.uri
571-
^ " and stamp " ^ string_of_int stamp ^ " and tip "
572-
^ Tip.toString tip);
573-
forLocalStamp ~full stamp tip))))
562+
| Some full ->
563+
maybeLog
564+
("Finding references for (global) " ^ Uri.toString env.file.uri
565+
^ " and stamp " ^ string_of_int stamp ^ " and tip "
566+
^ Tip.toString tip);
567+
forLocalStamp ~full stamp tip)))

0 commit comments

Comments
 (0)