Skip to content

fix load closure #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/fsharp/fsi/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,11 +2251,10 @@ type internal FsiInteractionProcessor
let names = names |> List.filter (fun name -> name.StartsWith(stem,StringComparison.Ordinal))
names

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

let loadClosure = None
let fsiInteractiveChecker = FsiInteractiveChecker(checker, tcConfig, istate.tcGlobals, istate.tcImports, istate.tcState, loadClosure)
let fsiInteractiveChecker = FsiInteractiveChecker(referenceResolver, checker, tcConfig, istate.tcGlobals, istate.tcImports, istate.tcState)
fsiInteractiveChecker.ParseAndCheckInteraction(text)


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

member x.ParseAndCheckInteraction(code) =
fsiInteractionProcessor.ParseAndCheckInteraction (checker.ReactorOps, fsiInteractionProcessor.CurrentState, code)
fsiInteractionProcessor.ParseAndCheckInteraction (referenceResolver, checker.ReactorOps, fsiInteractionProcessor.CurrentState, code)

member x.CurrentPartialAssemblySignature =
fsiDynamicCompiler.CurrentPartialAssemblySignature (fsiInteractionProcessor.CurrentState)
Expand Down
14 changes: 9 additions & 5 deletions src/fsharp/vs/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2614,9 +2614,8 @@ type BackgroundCompiler(referenceResolver, projectCacheSize, keepAssemblyContent
#endif
let loadedTimeStamp = defaultArg loadedTimeStamp DateTime.MaxValue // Not 'now', we don't want to force reloading
let applyCompilerOptions tcConfigB =
let collect _name = ()
let fsiCompilerOptions = CompileOptions.GetCoreFsiCompilerOptions tcConfigB
CompileOptions.ParseCompilerOptions (collect, fsiCompilerOptions, Array.toList otherFlags)
CompileOptions.ParseCompilerOptions (ignore, fsiCompilerOptions, Array.toList otherFlags)
let fas = LoadClosure.ComputeClosureOfSourceText(referenceResolver,filename, source, CodeContext.Editing, useSimpleResolution, useFsiAuxLib, new Lexhelp.LexResourceManager(), applyCompilerOptions)
let otherFlags =
[| yield "--noframework"; yield "--warn:3";
Expand Down Expand Up @@ -3000,25 +2999,30 @@ type FSharpChecker(referenceResolver, projectCacheSize, keepAssemblyContents, ke
member internal __.FrameworkImportsCache = backgroundCompiler.FrameworkImportsCache


type FsiInteractiveChecker(reactorOps: IReactorOperations, tcConfig, tcGlobals, tcImports, tcState, loadClosure) =
type FsiInteractiveChecker(referenceResolver, reactorOps: IReactorOperations, tcConfig: TcConfig, tcGlobals, tcImports, tcState) =
let keepAssemblyContents = false

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

member __.ParseAndCheckInteraction (source) =

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

let applyCompilerOptions tcConfigB =
let fsiCompilerOptions = CompileOptions.GetCoreFsiCompilerOptions tcConfigB
CompileOptions.ParseCompilerOptions (ignore, fsiCompilerOptions, [ ])

let loadClosure = LoadClosure.ComputeClosureOfSourceText(referenceResolver, mainInputFileName, source, CodeContext.Editing, tcConfig.useSimpleResolution, tcConfig.useFsiAuxLib, new Lexhelp.LexResourceManager(), applyCompilerOptions)
let backgroundErrors = []
let tcErrors, tcFileResult =
Parser.TypeCheckOneFile(parseResults,source,mainInputFileName,"project",tcConfig,tcGlobals,tcImports, tcState,
loadClosure,backgroundErrors,reactorOps,(fun () -> true),(fun _ -> false),None)
Some loadClosure,backgroundErrors,reactorOps,(fun () -> true),(fun _ -> false),None)

match tcFileResult with
| Parser.TypeCheckAborted.No scope ->
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/vs/service.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ type FSharpChecker =
// An object to typecheck source in a given typechecking environment.
// Used internally to provide intellisense over F# Interactive.
type internal FsiInteractiveChecker =
internal new : ops: IReactorOperations * tcConfig: TcConfig * tcGlobals: TcGlobals * tcImports: TcImports * tcState: TcState * loadClosure: LoadClosure option -> FsiInteractiveChecker
internal new : ReferenceResolver.Resolver * ops: IReactorOperations * tcConfig: TcConfig * tcGlobals: TcGlobals * tcImports: TcImports * tcState: TcState -> FsiInteractiveChecker
member internal ParseAndCheckInteraction : source:string -> FSharpParseFileResults * FSharpCheckFileResults * FSharpCheckProjectResults
static member internal CreateErrorInfos : tcConfig: TcConfig * allErrors:bool * mainInputFileName : string * seq<ErrorLogger.PhasedError * FSharpErrorSeverity> -> FSharpErrorInfo[]

Expand Down
17 changes: 16 additions & 1 deletion tests/service/FsiTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ let ``ParseAndCheckInteraction test 1``() =
fsiSession.EvalInteraction """ let xxxxxx = 1 """
fsiSession.EvalInteraction """ type CCCC() = member x.MMMMM() = 1 + 1 """
let untypedResults, typedResults, _ = fsiSession.ParseAndCheckInteraction("xxxxxx")
untypedResults.FileName |> shouldEqual "stdin.fsx"
Path.GetFileName(untypedResults.FileName) |> shouldEqual "stdin.fsx"
untypedResults.Errors.Length |> shouldEqual 0
untypedResults.ParseHadErrors |> shouldEqual false

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

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

[<Test>]
let ``ParseAndCheckInteraction test 2``() =
let fileName1 = Path.Combine(Path.Combine(__SOURCE_DIRECTORY__, "data"), "testscript.fsx")
File.WriteAllText(fileName1, "let x = 1")
let interaction1 =
sprintf """
#load @"%s"
let y = Testscript.x + 1
""" fileName1
let untypedResults, typedResults, _ = fsiSession.ParseAndCheckInteraction interaction1
Path.GetFileName(untypedResults.FileName) |> shouldEqual "stdin.fsx"
untypedResults.Errors.Length |> shouldEqual 0
untypedResults.ParseHadErrors |> shouldEqual false


[<Test>]
let ``Bad arguments to session creation 1``() =
let inStream = new StringReader("")
Expand Down