@@ -449,10 +449,24 @@ let OpenModulesOrNamespaces tcSink g amap scopem root env mvvs openDeclaration =
449449 CallOpenDeclarationSink tcSink openDeclaration
450450 match openDeclaration.Range with
451451 | None -> ()
452- | Some range ->
453- for modul in mvvs do
454- let item = Item.ModuleOrNamespaces [modul]
455- CallNameResolutionSink tcSink (range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Use, env.DisplayEnv, env.eAccessRights)
452+ | Some _ ->
453+ let rec loop (acc: (Item * range) list) (idents: Ident list) =
454+ match idents with
455+ | [] -> acc
456+ | [id] when id.idText = MangledGlobalName -> acc
457+ | id :: rest ->
458+ let idents = List.rev idents
459+ let range = id.idRange
460+ let acc =
461+ match ResolveLongIndentAsModuleOrNamespace ResultCollectionSettings.AllResults amap range OpenQualified env.NameEnv env.eAccessRights idents with
462+ | Result modrefs ->
463+ (acc, modrefs) ||> List.fold (fun acc (_, modref, _) ->
464+ (Item.ModuleOrNamespaces [modref], range) :: acc)
465+ | _ -> acc
466+ loop acc rest
467+
468+ for item, range in loop [] (List.rev openDeclaration.LongId) do
469+ CallNameResolutionSink tcSink (range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Use, env.DisplayEnv, env.eAccessRights)
456470 env
457471
458472let AddRootModuleOrNamespaceRefs g amap m env modrefs =
@@ -665,11 +679,11 @@ let LocateEnv ccu env enclosingNamespacePath =
665679 env
666680
667681let BuildRootModuleType enclosingNamespacePath (cpath:CompilationPath) mtyp =
668- (enclosingNamespacePath, (cpath, (mtyp,None )))
669- ||> List.foldBack (fun id (cpath, (mtyp,mspec )) ->
682+ (enclosingNamespacePath, (cpath, (mtyp,[] )))
683+ ||> List.foldBack (fun id (cpath, (mtyp,mspecs )) ->
670684 let a, b = wrapModuleOrNamespaceTypeInNamespace id cpath.ParentCompPath mtyp
671- cpath.ParentCompPath, (a,match mspec with Some _ -> mspec | None -> Some b ))
672- |>snd
685+ cpath.ParentCompPath, (a,b :: mspecs ))
686+ |>fun (_, (mtyp, mspecs)) -> mtyp, List.rev mspecs
673687
674688let BuildRootModuleExpr enclosingNamespacePath (cpath:CompilationPath) mexpr =
675689 (enclosingNamespacePath, (cpath, mexpr))
@@ -16383,7 +16397,13 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
1638316397
1638416398 // For 'namespace rec' and 'module rec' we add the thing being defined
1638516399 let mtypNS = !(envNS.eModuleOrNamespaceTypeAccumulator)
16386- let mtypRoot, mspecNSOpt = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16400+ let mtypRoot, mspecNSs = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16401+ let mspecNSOpt = List.tryHead mspecNSs
16402+
16403+ mspecNSs |> List.iter (fun mspec ->
16404+ let modref = mkLocalModRef mspec
16405+ let item = Item.ModuleOrNamespaces [modref]
16406+ CallNameResolutionSink cenv.tcSink (mspec.Range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights))
1638716407
1638816408 // For 'namespace rec' and 'module rec' we add the thing being defined
1638916409 let envNS = if isRec then AddLocalRootModuleOrNamespace cenv.tcSink cenv.g cenv.amap m envNS mtypRoot else envNS
@@ -16688,7 +16708,13 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv:cenv) parent typeNames scopem
1668816708 let envNS = ImplicitlyOpenOwnNamespace cenv.tcSink cenv.g cenv.amap m enclosingNamespacePath envNS
1668916709
1669016710 let mtypNS = !(envNS.eModuleOrNamespaceTypeAccumulator)
16691- let mtypRoot, mspecNSOpt = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16711+ let mtypRoot, mspecNSs = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16712+ let mspecNSOpt = List.tryHead mspecNSs
16713+
16714+ mspecNSs |> List.iter (fun mspec ->
16715+ let modref = mkLocalModRef mspec
16716+ let item = Item.ModuleOrNamespaces [modref]
16717+ CallNameResolutionSink cenv.tcSink (mspec.Range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights))
1669216718
1669316719 // For 'namespace rec' and 'module rec' we add the thing being defined
1669416720 let envNS = if isRec then AddLocalRootModuleOrNamespace cenv.tcSink cenv.g cenv.amap m envNS mtypRoot else envNS