Skip to content

Commit 00a87c1

Browse files
authored
Merge pull request #685 from dsyme/fix-bug1
fix load closure
2 parents 52ccde3 + a9dac50 commit 00a87c1

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

src/fsharp/fsi/fsi.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,11 +2251,10 @@ type internal FsiInteractionProcessor
22512251
let names = names |> List.filter (fun name -> name.StartsWith(stem,StringComparison.Ordinal))
22522252
names
22532253

2254-
member __.ParseAndCheckInteraction (checker, istate, text:string) =
2254+
member __.ParseAndCheckInteraction (referenceResolver, checker, istate, text:string) =
22552255
let tcConfig = TcConfig.Create(tcConfigB,validate=false)
22562256

2257-
let loadClosure = None
2258-
let fsiInteractiveChecker = FsiInteractiveChecker(checker, tcConfig, istate.tcGlobals, istate.tcImports, istate.tcState, loadClosure)
2257+
let fsiInteractiveChecker = FsiInteractiveChecker(referenceResolver, checker, tcConfig, istate.tcGlobals, istate.tcImports, istate.tcState)
22592258
fsiInteractiveChecker.ParseAndCheckInteraction(text)
22602259

22612260

@@ -2537,7 +2536,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i
25372536
fsiInteractionProcessor.CompletionsForPartialLID (fsiInteractionProcessor.CurrentState, longIdent) |> Seq.ofList
25382537

25392538
member x.ParseAndCheckInteraction(code) =
2540-
fsiInteractionProcessor.ParseAndCheckInteraction (checker.ReactorOps, fsiInteractionProcessor.CurrentState, code)
2539+
fsiInteractionProcessor.ParseAndCheckInteraction (referenceResolver, checker.ReactorOps, fsiInteractionProcessor.CurrentState, code)
25412540

25422541
member x.CurrentPartialAssemblySignature =
25432542
fsiDynamicCompiler.CurrentPartialAssemblySignature (fsiInteractionProcessor.CurrentState)

src/fsharp/vs/service.fs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,9 +2614,8 @@ type BackgroundCompiler(referenceResolver, projectCacheSize, keepAssemblyContent
26142614
#endif
26152615
let loadedTimeStamp = defaultArg loadedTimeStamp DateTime.MaxValue // Not 'now', we don't want to force reloading
26162616
let applyCompilerOptions tcConfigB =
2617-
let collect _name = ()
26182617
let fsiCompilerOptions = CompileOptions.GetCoreFsiCompilerOptions tcConfigB
2619-
CompileOptions.ParseCompilerOptions (collect, fsiCompilerOptions, Array.toList otherFlags)
2618+
CompileOptions.ParseCompilerOptions (ignore, fsiCompilerOptions, Array.toList otherFlags)
26202619
let fas = LoadClosure.ComputeClosureOfSourceText(referenceResolver,filename, source, CodeContext.Editing, useSimpleResolution, useFsiAuxLib, new Lexhelp.LexResourceManager(), applyCompilerOptions)
26212620
let otherFlags =
26222621
[| yield "--noframework"; yield "--warn:3";
@@ -3000,25 +2999,30 @@ type FSharpChecker(referenceResolver, projectCacheSize, keepAssemblyContents, ke
30002999
member internal __.FrameworkImportsCache = backgroundCompiler.FrameworkImportsCache
30013000

30023001

3003-
type FsiInteractiveChecker(reactorOps: IReactorOperations, tcConfig, tcGlobals, tcImports, tcState, loadClosure) =
3002+
type FsiInteractiveChecker(referenceResolver, reactorOps: IReactorOperations, tcConfig: TcConfig, tcGlobals, tcImports, tcState) =
30043003
let keepAssemblyContents = false
30053004

30063005
static member CreateErrorInfos (tcConfig, allErrors, mainInputFileName, errors) =
30073006
Parser.CreateErrorInfos(tcConfig, allErrors, mainInputFileName, errors)
30083007

30093008
member __.ParseAndCheckInteraction (source) =
30103009

3011-
let mainInputFileName = "stdin.fsx"
3010+
let mainInputFileName = Path.Combine(tcConfig.implicitIncludeDir, "stdin.fsx")
30123011
// Note: projectSourceFiles is only used to compute isLastCompiland, and is ignored if Build.IsScript(mainInputFileName) is true (which it is in this case).
30133012
let projectSourceFiles = [ ]
30143013
let parseErrors, _matchPairs, inputOpt, anyErrors = Parser.ParseOneFile (source, false, true, mainInputFileName, projectSourceFiles, tcConfig)
30153014
let dependencyFiles = [] // interactions have no dependencies
30163015
let parseResults = FSharpParseFileResults(parseErrors, inputOpt, parseHadErrors = anyErrors, dependencyFiles = dependencyFiles)
30173016

3017+
let applyCompilerOptions tcConfigB =
3018+
let fsiCompilerOptions = CompileOptions.GetCoreFsiCompilerOptions tcConfigB
3019+
CompileOptions.ParseCompilerOptions (ignore, fsiCompilerOptions, [ ])
3020+
3021+
let loadClosure = LoadClosure.ComputeClosureOfSourceText(referenceResolver, mainInputFileName, source, CodeContext.Editing, tcConfig.useSimpleResolution, tcConfig.useFsiAuxLib, new Lexhelp.LexResourceManager(), applyCompilerOptions)
30183022
let backgroundErrors = []
30193023
let tcErrors, tcFileResult =
30203024
Parser.TypeCheckOneFile(parseResults,source,mainInputFileName,"project",tcConfig,tcGlobals,tcImports, tcState,
3021-
loadClosure,backgroundErrors,reactorOps,(fun () -> true),(fun _ -> false),None)
3025+
Some loadClosure,backgroundErrors,reactorOps,(fun () -> true),(fun _ -> false),None)
30223026

30233027
match tcFileResult with
30243028
| Parser.TypeCheckAborted.No scope ->

src/fsharp/vs/service.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ type FSharpChecker =
741741
// An object to typecheck source in a given typechecking environment.
742742
// Used internally to provide intellisense over F# Interactive.
743743
type internal FsiInteractiveChecker =
744-
internal new : ops: IReactorOperations * tcConfig: TcConfig * tcGlobals: TcGlobals * tcImports: TcImports * tcState: TcState * loadClosure: LoadClosure option -> FsiInteractiveChecker
744+
internal new : ReferenceResolver.Resolver * ops: IReactorOperations * tcConfig: TcConfig * tcGlobals: TcGlobals * tcImports: TcImports * tcState: TcState -> FsiInteractiveChecker
745745
member internal ParseAndCheckInteraction : source:string -> FSharpParseFileResults * FSharpCheckFileResults * FSharpCheckProjectResults
746746
static member internal CreateErrorInfos : tcConfig: TcConfig * allErrors:bool * mainInputFileName : string * seq<ErrorLogger.PhasedError * FSharpErrorSeverity> -> FSharpErrorInfo[]
747747

tests/service/FsiTests.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let ``ParseAndCheckInteraction test 1``() =
215215
fsiSession.EvalInteraction """ let xxxxxx = 1 """
216216
fsiSession.EvalInteraction """ type CCCC() = member x.MMMMM() = 1 + 1 """
217217
let untypedResults, typedResults, _ = fsiSession.ParseAndCheckInteraction("xxxxxx")
218-
untypedResults.FileName |> shouldEqual "stdin.fsx"
218+
Path.GetFileName(untypedResults.FileName) |> shouldEqual "stdin.fsx"
219219
untypedResults.Errors.Length |> shouldEqual 0
220220
untypedResults.ParseHadErrors |> shouldEqual false
221221

@@ -232,6 +232,21 @@ let ``ParseAndCheckInteraction test 1``() =
232232

233233
Assert.True(tooltip.Contains("val xxxxxx : int"))
234234

235+
[<Test>]
236+
let ``ParseAndCheckInteraction test 2``() =
237+
let fileName1 = Path.Combine(Path.Combine(__SOURCE_DIRECTORY__, "data"), "testscript.fsx")
238+
File.WriteAllText(fileName1, "let x = 1")
239+
let interaction1 =
240+
sprintf """
241+
#load @"%s"
242+
let y = Testscript.x + 1
243+
""" fileName1
244+
let untypedResults, typedResults, _ = fsiSession.ParseAndCheckInteraction interaction1
245+
Path.GetFileName(untypedResults.FileName) |> shouldEqual "stdin.fsx"
246+
untypedResults.Errors.Length |> shouldEqual 0
247+
untypedResults.ParseHadErrors |> shouldEqual false
248+
249+
235250
[<Test>]
236251
let ``Bad arguments to session creation 1``() =
237252
let inStream = new StringReader("")

0 commit comments

Comments
 (0)