@@ -1139,45 +1139,49 @@ type internal FsiDynamicCompiler
11391139 let newState = { istate with tcState = tcState.NextStateAfterIncrementalFragment( tcEnvAtEndOfLastInput) }
11401140
11411141 // Find all new declarations the EvaluationListener
1142- let mutable lastValue = None
1142+ let mutable itValue = None
11431143 try
11441144 let contents = FSharpAssemblyContents( tcGlobals, tcState.Ccu, Some tcState.CcuSig, tcImports, declaredImpls)
11451145 let contentFile = contents.ImplementationFiles.[ 0 ]
1146+
11461147 // Skip the "FSI_NNNN"
1147- match contentFile.Declarations with
1148- | [ FSharpImplementationFileDeclaration.Entity (_ eFakeModule, modDecls) ] ->
1148+ match contentFile.Declarations with
1149+ | [ FSharpImplementationFileDeclaration.Entity (_ eFakeModule, modDecls) ] ->
11491150 let cenv = SymbolEnv( newState.tcGlobals, newState.tcState.Ccu, Some newState.tcState.CcuSig, newState.tcImports)
1150- for decl in modDecls do
1151- match decl with
1151+ for decl in modDecls do
1152+ match decl with
11521153 | FSharpImplementationFileDeclaration.MemberOrFunctionOrValue ( v,_,_) ->
11531154 // Report a top-level function or value definition
1154- if v.IsModuleValueOrMember && not v.IsMember then
1155- let fsiValueOpt =
1156- match v.Item with
1157- | Item.Value vref ->
1158- let optValue = newState.ilxGenerator.LookupGeneratedValue( valuePrinter.GetEvaluationContext( newState.emEnv), vref.Deref)
1159- match optValue with
1160- | Some ( res, ty) -> Some( FsiValue( res, ty, FSharpType( cenv, vref.Type)))
1161- | None -> None
1162- | _ -> None
1163-
1164- let symbol = FSharpSymbol.Create( cenv, v.Item)
1165- let symbolUse = FSharpSymbolUse( tcGlobals, newState.tcState.TcEnvFromImpls.DisplayEnv, symbol, ItemOccurence.Binding, v.DeclarationLocation)
1166- fsi.TriggerEvaluation ( fsiValueOpt, symbolUse, decl)
1167- lastValue <- fsiValueOpt
1155+ if v.IsModuleValueOrMember && not v.IsMember then
1156+ let fsiValueOpt =
1157+ match v.Item with
1158+ | Item.Value vref ->
1159+ let optValue = newState.ilxGenerator.LookupGeneratedValue( valuePrinter.GetEvaluationContext( newState.emEnv), vref.Deref)
1160+ match optValue with
1161+ | Some ( res, ty) -> Some( FsiValue( res, ty, FSharpType( cenv, vref.Type)))
1162+ | None -> None
1163+ | _ -> None
1164+
1165+ if v.CompiledName = " it" then
1166+ itValue <- fsiValueOpt
1167+
1168+ let symbol = FSharpSymbol.Create( cenv, v.Item)
1169+ let symbolUse = FSharpSymbolUse( tcGlobals, newState.tcState.TcEnvFromImpls.DisplayEnv, symbol, ItemOccurence.Binding, v.DeclarationLocation)
1170+ fsi.TriggerEvaluation ( fsiValueOpt, symbolUse, decl)
1171+
11681172 | FSharpImplementationFileDeclaration.Entity ( e,_) ->
11691173 // Report a top-level module or namespace definition
11701174 let symbol = FSharpSymbol.Create( cenv, e.Item)
11711175 let symbolUse = FSharpSymbolUse( tcGlobals, newState.tcState.TcEnvFromImpls.DisplayEnv, symbol, ItemOccurence.Binding, e.DeclarationLocation)
11721176 fsi.TriggerEvaluation ( None, symbolUse, decl)
1173- lastValue <- None
1177+
11741178 | FSharpImplementationFileDeclaration.InitAction _ ->
11751179 // Top level 'do' bindings are not reported as incremental declarations
1176- lastValue <- None
1180+ ()
11771181 | _ -> ()
11781182 with _ -> ()
11791183
1180- newState, Completed lastValue
1184+ newState, Completed itValue
11811185
11821186 /// Evaluate the given expression and produce a new interactive state.
11831187 member fsiDynamicCompiler.EvalParsedExpression ( ctok , errorLogger : ErrorLogger , istate , expr : SynExpr ) =
@@ -1194,7 +1198,7 @@ type internal FsiDynamicCompiler
11941198 | NameResolution.Item.Value vref ->
11951199 if not tcConfig.noFeedback then
11961200 valuePrinter.InvokeExprPrinter ( istate.tcState.TcEnvFromImpls.DisplayEnv, istate.emEnv, istate.ilxGenerator, vref.Deref)
1197-
1201+
11981202 /// Clear the value held in the previous "it" binding, if any, as long as it has never been referenced.
11991203 match prevIt with
12001204 | Some prevVal when not prevVal.Deref.HasBeenReferenced ->
0 commit comments