@@ -18,6 +18,20 @@ let locItemsForPos ~extra pos =
1818
1919let lineColToCmtLoc ~pos :(line , col ) = (line + 1 , col)
2020
21+ (* * External references in namespaced projects are indexed by the public
22+ * namespace path, e.g. MyNamespace.MyModule1.myFunc1, while definitions live
23+ * in hidden compiled modules like MyModule1-MyNamespace.
24+ * We return the lookup key pair used by the external reference index.
25+ *)
26+ let normalizeExternalReferenceKey ~namespace ~moduleName ~path =
27+ match namespace with
28+ | Some namespace when Utils. endsWith moduleName (" -" ^ namespace) ->
29+ let suffixLen = String. length namespace + 1 in
30+ let sourceModuleLen = String. length moduleName - suffixLen in
31+ let sourceModule = String. sub moduleName 0 sourceModuleLen in
32+ (namespace, sourceModule :: path)
33+ | _ -> (moduleName, path)
34+
2135let getLocItem ~full ~pos ~debug =
2236 let log n msg = if debug then Printf. printf " getLocItem #%d: %s\n " n msg in
2337 let pos = lineColToCmtLoc ~pos in
@@ -485,6 +499,10 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
485499 in
486500 maybeLog (" Now checking path " ^ pathToString path);
487501 let thisModuleName = file.moduleName in
502+ let normalizedModuleName, normalizedPath =
503+ normalizeExternalReferenceKey ~namespace: package.namespace
504+ ~module Name:thisModuleName ~path
505+ in
488506 let externals =
489507 package.projectFiles |> FileSet. elements
490508 |> List. filter (fun name -> name <> file.moduleName)
@@ -493,14 +511,15 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
493511 |> List. map (fun {file; extra} ->
494512 match
495513 Hashtbl. find_opt extra.externalReferences
496- thisModuleName
514+ normalizedModuleName
497515 with
498516 | None -> []
499517 | Some refs ->
500518 let locs =
501519 refs
502520 |> Utils. filterMap (fun (p , t , locs ) ->
503- if p = path && t = tip then Some locs
521+ if p = normalizedPath && t = tip then
522+ Some locs
504523 else None )
505524 in
506525 locs
@@ -522,10 +541,8 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
522541 | TopLevelModule moduleName ->
523542 let otherModulesReferences =
524543 package.projectFiles |> FileSet. elements
525- |> Utils. filterMap (fun name ->
526- match ProcessCmt. fileForModule ~package name with
527- | None -> None
528- | Some file -> Cmt. fullFromUri ~uri: file.uri)
544+ |> Utils. filterMap (fun moduleName ->
545+ Cmt. fullFromModule ~package ~module Name)
529546 |> List. map (fun full ->
530547 match Hashtbl. find_opt full.extra.fileReferences moduleName with
531548 | None -> []
@@ -563,7 +580,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
563580 match exportedForTip ~env ~path ~package ~tip with
564581 | None -> []
565582 | Some (env , _name , stamp ) -> (
566- match Cmt. fullFromUri ~uri : env.file.uri with
583+ match Cmt. fullFromModule ~package ~module Name :env.file.moduleName with
567584 | None -> []
568585 | Some full ->
569586 maybeLog
0 commit comments