@@ -17,7 +17,9 @@ type Reference =
1717 Kind : ReferenceKind
1818 }
1919
20- type Abbreviation = Abbreviation of unit
20+ type Abbreviation =
21+ | ModuleAbbreviation
22+ | TypeAbbreviation
2123
2224/// Reference to a module or type, found in the AST
2325type ReferenceOrAbbreviation =
@@ -26,6 +28,12 @@ type ReferenceOrAbbreviation =
2628
2729type private References = ReferenceOrAbbreviation seq
2830
31+ module Array =
32+ let split < 'a , 'b , 'c > ( splitter : 'a -> Choice < 'b , 'c >) ( items : 'a []) =
33+ let items = items |> Array.map splitter
34+ items |> Array.choose ( function Choice1Of2 x -> Some x | _ -> None),
35+ items |> Array.choose ( function Choice2Of2 x -> Some x | _ -> None)
36+
2937module ASTVisit =
3038 let rec visitSynModuleDecl ( decl : SynModuleDecl ) : References =
3139 // TODO
@@ -45,7 +53,7 @@ module ASTVisit =
4553 | SynModuleDecl.Types( synTypeDefns, range) ->
4654 visitSynTypeDefns synTypeDefns
4755 | SynModuleDecl.ModuleAbbrev( ident, longId, range) ->
48- [ ReferenceOrAbbreviation.Abbreviation ( Abbreviation.Abbreviation ()) ]
56+ [ ReferenceOrAbbreviation.Abbreviation Abbreviation.ModuleAbbreviation ]
4957 | SynModuleDecl.NamespaceFragment synModuleOrNamespace ->
5058 visitSynModuleOrNamespace synModuleOrNamespace
5159 | SynModuleDecl.NestedModule( synComponentInfo, isRecursive, synModuleDecls, isContinuing, range, synModuleDeclNestedModuleTrivia) ->
@@ -380,7 +388,7 @@ module ASTVisit =
380388 yield ! visitParserDetail parserDetail
381389 yield ! visitType rhsType
382390 // TODO This shouldn't be needed, but for some reason it fixes the 'graph' mode in lib.fs etc.
383- yield ( ReferenceOrAbbreviation.Abbreviation ( Abbreviation.Abbreviation ()) )
391+ yield ( ReferenceOrAbbreviation.Abbreviation Abbreviation.TypeAbbreviation )
384392 }
385393 | SynTypeDefnSimpleRepr.LibraryOnlyILAssembly( ilType, range) ->
386394 []
@@ -1094,18 +1102,13 @@ module ASTVisit =
10941102 synModuleOrNamespaces
10951103 |> Seq.collect visitSynModuleOrNamespace
10961104 |> Seq.toArray
1097-
1105+
10981106 /// Extract partial module references from partial module or type references
1099- let extractModuleSegments ( stuff : ReferenceOrAbbreviation seq ) : LongIdent [] * bool =
1100-
1101- let refs =
1102- stuff
1103- |> Seq.choose ( function | ReferenceOrAbbreviation.Reference r -> Some r | ReferenceOrAbbreviation.Abbreviation _ -> None)
1104- |> Seq.toArray
1105- let abbreviations =
1107+ let extractModuleSegments ( stuff : ReferenceOrAbbreviation seq ): LongIdent [] * Abbreviation [] =
1108+ let refs , abbreviations =
11061109 stuff
1107- |> Seq.choose ( function | ReferenceOrAbbreviation.Reference _ -> None | ReferenceOrAbbreviation.Abbreviation a -> Some a)
11081110 |> Seq.toArray
1111+ |> Array.split ( function | ReferenceOrAbbreviation.Reference r -> Choice1Of2 r | ReferenceOrAbbreviation.Abbreviation a -> Choice2Of2 a)
11091112
11101113 let moduleRefs =
11111114 refs
@@ -1120,9 +1123,8 @@ module ASTVisit =
11201123 | n -> x.Ident.GetSlice( Some 0 , n - 2 |> Some) |> Some
11211124 )
11221125 |> Seq.toArray
1123- let containsModuleAbbreviations = abbreviations.Length > 0
11241126
1125- moduleRefs, containsModuleAbbreviations
1127+ moduleRefs, abbreviations
11261128
11271129 let findModuleRefs ( ast : ParsedInput ) =
11281130 let typeAndModuleRefs = findModuleAndTypeRefs ast
@@ -1158,7 +1160,7 @@ module TopModulesExtraction =
11581160 | SynModuleOrNamespace( longId, isRecursive, synModuleOrNamespaceKind, synModuleDecls, preXmlDoc, synAttributeLists, synAccessOption, range, synModuleOrNamespaceTrivia) ->
11591161 if mightHaveAutoOpen synAttributeLists then
11601162 // Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
1161- // Treat it as a type - as soon as the parent module is reachable, consider the file being used
1163+ // Stay safe and as soon as the parent module is reachable, consider this module reachable as well
11621164 [| LongIdent.Empty|]
11631165 else
11641166 [| longId|]
0 commit comments