@@ -15,6 +15,8 @@ open Microsoft.FSharp.Compiler.Range
1515
1616type internal ShortIdent = string
1717type Idents = ShortIdent[]
18+ type MaybeUnresolvedIdent = { Ident: ShortIdent ; Resolved: bool }
19+ type MaybeUnresolvedIdents = MaybeUnresolvedIdent[]
1820type IsAutoOpen = bool
1921
2022[<AutoOpen>]
@@ -458,15 +460,18 @@ module internal Entity =
458460| _ -> candidateNs.Length
459461 candidateNs.[ 0 .. nsCount- 1 ]
460462
461- let tryCreate ( targetNamespace : Idents option , targetScope : Idents , partiallyQualifiedName : Idents ,
462- requiresQualifiedAccessParent : Idents option , autoOpenParent : Idents option ,
463- candidateNamespace : Idents option , candidate : Idents ) =
463+ let tryCreate ( targetNamespace : Idents option , targetScope : Idents , partiallyQualifiedName : MaybeUnresolvedIdents ,
464+ requiresQualifiedAccessParent : Idents option , autoOpenParent : Idents option , candidateNamespace : Idents option , candidate : Idents ) =
464465match candidatewith
465466| [||] -> [||]
466467| _ ->
467468 partiallyQualifiedName
468469|> Array.heads
469- |> Array.choose( fun parts ->
470+ // the last part must be unresolved, otherwise we show false positive suggestions like
471+ // "open System" for `let _ = System.DateTime.Naaaw`. Here only "Naaw" is unresolved.
472+ |> Array.filter( fun x -> not ( x.[ x.Length- 1 ]. Resolved))
473+ |> Array.choose( fun parts ->
474+ let parts = parts|> Array.map( fun x -> x.Ident)
470475if not ( candidate|> Array.endsWith parts) then None
471476else
472477let identCount = parts.Length
@@ -547,29 +552,25 @@ module internal ParsedInput =
547552| SynConstructorArgs.Pats ps-> ps
548553| SynConstructorArgs.NamePatPairs( xs, _) -> List.map snd xs
549554
550- let internal longIdentToArray ( longIdent : LongIdent ): Idents =
551- longIdent|> Seq.map string|> Seq.toArray
552-
553- /// Returns all Idents and LongIdents found in an untyped AST.
554- let internal getLongIdents ( input : ParsedInput option ) : IDictionary < Range.pos , Idents > =
555- let identsByEndPos = Dictionary< Range.pos, Idents>()
555+ /// Returns all `Ident`s and `LongIdent`s found in an untyped AST.
556+ let internal getLongIdents ( input : ParsedInput option ) : IDictionary < Range.pos , LongIdent > =
557+ let identsByEndPos = Dictionary< Range.pos, LongIdent>()
556558
557559let addLongIdent ( longIdent : LongIdent ) =
558- let idents = longIdentToArray longIdent
559560for identin longIdentdo
560- identsByEndPos.[ ident.idRange.End] <- idents
561+ identsByEndPos.[ ident.idRange.End] <- longIdent
561562
562563let addLongIdentWithDots ( LongIdentWithDots ( longIdent , lids ) as value ) =
563- match longIdentToArray longIdentwith
564- | [|| ] -> ()
565- | [|_| ] as idents-> identsByEndPos.[ value.Range.End] <- idents
564+ match longIdentwith
565+ | [] -> ()
566+ | [_ ] as idents-> identsByEndPos.[ value.Range.End] <- idents
566567| idents->
567568for dotRangein lidsdo
568569 identsByEndPos.[ Range.mkPos dotRange.EndLine( dotRange.EndColumn- 1 )] <- idents
569570 identsByEndPos.[ value.Range.End] <- idents
570571
571572let addIdent ( ident : Ident ) =
572- identsByEndPos.[ ident.idRange.End] <- [| ident.idText | ]
573+ identsByEndPos.[ ident.idRange.End] <- [ ident]
573574
574575let rec walkImplFileInput ( ParsedImplFileInput ( _ , _ , _ , _ , _ , moduleOrNamespaceList , _ )) =
575576 List.iter walkSynModuleOrNamespace moduleOrNamespaceList
@@ -886,7 +887,7 @@ module internal ParsedInput =
886887 walkImplFileInput input
887888| _ -> ()
888889//debug "%A" idents
889- identsByEndPos :> _
890+ upcast identsByEndPos
890891
891892let getLongIdentAt ast pos =
892893let idents = getLongIdents( Some ast)
@@ -1003,13 +1004,12 @@ module internal ParsedInput =
10031004|> Seq.sortBy( fun ( m , _ , _ ) -> - m.Length)
10041005|> Seq.toList
10051006
1006- fun ( partiallyQualifiedName : Idents ) ( requiresQualifiedAccessParent : Idents option , autoOpenParent : Idents option ,
1007- entityNamespace : Idents option , entity : Idents ) ->
1007+ fun ( partiallyQualifiedName : MaybeUnresolvedIdents )
1008+ ( requiresQualifiedAccessParent : Idents option , autoOpenParent : Idents option , entityNamespace : Idents option , entity : Idents ) ->
10081009match reswith
10091010| None-> [||]
10101011| Some( scope, ns, pos) ->
1011- Entity.tryCreate( ns, scope.Idents, partiallyQualifiedName, requiresQualifiedAccessParent,
1012- autoOpenParent, entityNamespace, entity)
1012+ Entity.tryCreate( ns, scope.Idents, partiallyQualifiedName, requiresQualifiedAccessParent, autoOpenParent, entityNamespace, entity)
10131013|> Array.map( fun e ->
10141014 e,
10151015match modules|> List.filter( fun ( m , _ , _ ) -> entity|> Array.startsWith m) with