@@ -518,12 +518,13 @@ type TypeCheckInfo
518518let ncenv = new NameResolver( g, amap, infoReader, NameResolution.FakeInstantiationGenerator)
519519
520520/// Find the most precise naming environment for the given line and column
521- let GetBestEnvForPos cursorPos =
521+ let GetBestEnvForPos ( envsByLine : ResizeArray < range * NameResolutionEnv * AccessorDomain > []) ( cursorPos : pos ) =
522522
523+ // Find all scopes those contain given position
523524let mutable bestSoFar = None
524525
525526// Find the most deeply nested enclosing scope that contains given position
526- sResolutions.CapturedEnvs |> ResizeArray.iter( fun ( possm , env , ad ) ->
527+ envsByLine .[ cursorPos.Line ] |> ResizeArray.iter( fun ( possm , env , ad ) ->
527528if rangeContainsPos possm cursorPosthen
528529match bestSoFarwith
529530| Some( bestm,_,_) ->
@@ -540,36 +541,35 @@ type TypeCheckInfo
540541// We guarantee to only refine to a more nested environment. It may not be strictly
541542// the right environment, but will alwauys be at least as rich
542543
543- let bestAlmostIncludedSoFar = ref None
544+ letmutable bestAlmostIncludedSoFar = None
544545
545- sResolutions.CapturedEnvs |> ResizeArray.iter( fun ( possm , env , ad ) ->
546+ envsByLine .[ cursorPos.Line ] |> ResizeArray.iter( fun ( possm , env , ad ) ->
546547// take only ranges that strictly do not include cursorPos (all ranges that touch cursorPos were processed during 'Strict Inclusion' part)
547- if rangeBeforePos possm cursorPos&& not ( posEq possm.End cursorPos) then
548+ if not ( posEq possm.End cursorPos) && rangeBeforePos possm cursorPosthen
548549let contained =
549550match mostDeeplyNestedEnclosingScopewith
550551| Some( bestm,_,_) -> rangeContainsRange bestm possm
551552| None-> true
552553
553554if containedthen
554- match ! bestAlmostIncludedSoFarwith
555- | Some( rightm: range,_,_) ->
555+ match bestAlmostIncludedSoFarwith
556+ | Some( rightm: range,_,_) ->
556557if posGt possm.End rightm.End||
557558( posEq possm.End rightm.End&& posGt possm.Start rightm.Start) then
558- bestAlmostIncludedSoFar:= Some( possm, env, ad)
559- | _ -> bestAlmostIncludedSoFar:= Some( possm, env, ad))
559+ bestAlmostIncludedSoFar<- Some( possm, env, ad)
560+ | _ -> bestAlmostIncludedSoFar<- Some( possm, env, ad))
560561
561562let resEnv =
562- match ! bestAlmostIncludedSoFarwith
563- | Some(_ m , env, ad) ->
563+ match bestAlmostIncludedSoFarwith
564+ | Some(_ , env, ad) ->
564565 env, ad
565566| None->
566567match mostDeeplyNestedEnclosingScopewith
567- | Some(_ m , env, ad) ->
568+ | Some(_ , env, ad) ->
568569 env, ad
569570| None->
570- ( sFallback, AccessibleFromSomeFSharpCode)
571+ ( sFallback, AccessibleFromSomeFSharpCode)
571572let pm = mkRange mainInputFileName cursorPos cursorPos
572-
573573 resEnv, pm
574574
575575/// The items that come back from ResolveCompletionsInType are a bit
@@ -789,9 +789,17 @@ type TypeCheckInfo
789789if textChangedthen GetPreciseCompletionListFromExprTypingsResult.NoneBecauseTypecheckIsStaleAndTextChanged
790790else GetPreciseCompletionListFromExprTypingsResult.None
791791
792+ let GetEnvsByLine () : ResizeArray < range * NameResolutionEnv * AccessorDomain > [] =
793+ let maxLine = sResolutions.CapturedEnvs|> Seq.maxBy( fun ( m , _ , _ ) -> m.EndLine) |> fun ( m , _ , _ ) -> m.EndLine
794+ let envsByLine = Array.init( maxLine+ 1 ) ( fun _ -> ResizeArray())
795+ for ( m,_,_) as envin sResolutions.CapturedEnvsdo
796+ for linein m.StartLine.. m.EndLinedo
797+ envsByLine.[ line]. Add env
798+ envsByLine
799+
792800/// Find items in the best naming environment.
793801let GetEnvironmentLookupResolutions ( cursorPos , plid , filterCtors , showObsolete ) =
794- let ( nenv , ad ), m = GetBestEnvForPos cursorPos
802+ let ( nenv , ad ), m = GetBestEnvForPos( GetEnvsByLine ()) cursorPos
795803let items = NameResolution.ResolvePartialLongIdent ncenv nenv( ConstraintSolver.IsApplicableMethApprox g amap m) m ad plid showObsolete
796804let items = items|> RemoveDuplicateItems g
797805let items = items|> RemoveExplicitlySuppressed g
@@ -801,7 +809,7 @@ type TypeCheckInfo
801809
802810/// Find record fields in the best naming environment.
803811let GetClassOrRecordFieldsEnvironmentLookupResolutions ( cursorPos , plid , ( _residue : string option )) =
804- let ( nenv , ad ), m = GetBestEnvForPos cursorPos
812+ let ( nenv , ad ), m = GetBestEnvForPos( GetEnvsByLine ()) cursorPos
805813let items = NameResolution.ResolvePartialLongIdentToClassOrRecdFields ncenv nenv m ad plidfalse
806814let items = items|> RemoveDuplicateItems g
807815let items = items|> RemoveExplicitlySuppressed g
@@ -994,7 +1002,7 @@ type TypeCheckInfo
9941002
9951003/// Get the auto-complete items at a particular location.
9961004let GetDeclItemsForNamesAtPosition ( parseResultsOpt : FSharpParseFileResults option , origLongIdentOpt : string list option , residueOpt : string option , line : int , lineStr : string , colAtEndOfNamesAndResidue , filterCtors , resolveOverloads , hasTextChangedSinceLastTypecheck : ( obj * range -> bool )) =
997-
1005+
9981006let loc =
9991007match colAtEndOfNamesAndResiduewith
10001008| pastEndOfLinewhen pastEndOfLine>= lineStr.Length-> lineStr.Length
@@ -1025,7 +1033,7 @@ type TypeCheckInfo
10251033
10261034// Completion at ' { XXX = ... } "
10271035| Some( CompletionContext.RecordField( RecordContext.New( plid, residue))) ->
1028- Some( GetClassOrRecordFieldsEnvironmentLookupResolutions( mkPos line loc, plid, residue))
1036+ Some( GetClassOrRecordFieldsEnvironmentLookupResolutions( mkPos line loc, plid, residue))
10291037
10301038// Completion at ' { XXX = ... with ... } "
10311039| Some( CompletionContext.RecordField( RecordContext.CopyOnUpdate( r, ( plid, residue)))) ->
@@ -1112,16 +1120,18 @@ type TypeCheckInfo
11121120else
11131121 items
11141122
1115-
11161123static let keywordTypes = Lexhelp.Keywords.keywordTypes
11171124
1125+ member x.GetSortedNameResolutionEnvironments () = GetEnvsByLine()
1126+
11181127member x.GetVisibleNamespacesAndModulesAtPosition ( cursorPos : pos ) : ModuleOrNamespaceRef list =
1119- let ( nenv , ad ), m = GetBestEnvForPos cursorPos
1128+ let ( nenv , ad ), m = GetBestEnvForPos( GetEnvsByLine ()) cursorPos
11201129 NameResolution.GetVisibleNamespacesAndModulesAtPoint ncenv nenv m ad
11211130
1122- member x.IsRelativeNameResolvable ( cursorPos : pos , plid : string list , item : Item ) : bool =
1131+
1132+ member x.IsRelativeNameResolvable ( cursorPos : pos , plid : string list , item : Item , envsByLine : ResizeArray < range * NameResolutionEnv * AccessorDomain > []) : bool =
11231133/// Find items in the best naming environment.
1124- let ( nenv , ad ), m = GetBestEnvForPos cursorPos
1134+ let ( nenv , ad ), m = GetBestEnvForPosenvsByLine cursorPos
11251135 NameResolution.IsItemResolvable ncenv nenv m ad plid item
11261136
11271137//let items = NameResolution.ResolvePartialLongIdent ncenv nenv (fun _ _ -> true) m ad plid true
@@ -2057,8 +2067,11 @@ type FSharpCheckFileResults(errors: FSharpErrorInfo[], scopeOptX: TypeCheckInfo
20572067member info.GetVisibleNamespacesAndModulesAtPoint ( pos : pos ) : Async < ModuleOrNamespaceRef []> =
20582068 reactorOp" GetDeclarations" [| |] ( fun scope -> scope.GetVisibleNamespacesAndModulesAtPosition( pos) |> List.toArray)
20592069
2060- member info.IsRelativeNameResolvable ( pos : pos , plid : string list , item : Item ) : Async < bool > =
2061- reactorOp" IsRelativeNameResolvable" true ( fun scope -> scope.IsRelativeNameResolvable( pos, plid, item))
2070+ member info.GetNameResolutionEnvironmentsByLine () : Async < ResizeArray < range * NameResolutionEnv * AccessorDomain > []> =
2071+ reactorOp" IsRelativeNameResolvable" [||] ( fun scope -> scope.GetSortedNameResolutionEnvironments())
2072+
2073+ member info.IsRelativeNameResolvable ( pos : pos , plid : string list , item : Item , nenvsByLine : ResizeArray < range * NameResolutionEnv * AccessorDomain > []) : Async < bool > =
2074+ reactorOp" IsRelativeNameResolvable" true ( fun scope -> scope.IsRelativeNameResolvable( pos, plid, item, nenvsByLine))
20622075
20632076//----------------------------------------------------------------------------
20642077// BackgroundCompiler