Skip to content

Commit

Permalink
Revert parsing APIs (fallback to the new ones), fix VFT projects
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Sep 20, 2017
1 parent 76b0dae commit 200d144
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/fsharp/CompileOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,11 @@ let GetCoreFsiCompilerOptions (tcConfigB: TcConfigBuilder) =
testingAndQAFlags tcConfigB])
]

let ApplyCommandLineArgs(tcConfigB: TcConfigBuilder, sourceFiles: string list, commandLineArgs) =
let ApplyCommandLineArgs(tcConfigB: TcConfigBuilder, sourceFiles: string list, argv) =
try
let sourceFilesAcc = ResizeArray(sourceFiles)
let collect name = if not (Filename.isDll name) then sourceFilesAcc.Add(name)
ParseCompilerOptions(collect, GetCoreServiceCompilerOptions tcConfigB, commandLineArgs)
ParseCompilerOptions(collect, GetCoreServiceCompilerOptions tcConfigB, argv)
ResizeArray.toList(sourceFilesAcc)
with e ->
errorRecovery e range0
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/CompileOptions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ val GetCoreFscCompilerOptions : TcConfigBuilder -> CompilerOptionBlock list
val GetCoreFsiCompilerOptions : TcConfigBuilder -> CompilerOptionBlock list
val GetCoreServiceCompilerOptions : TcConfigBuilder -> CompilerOptionBlock list

// Apply args to TcConfigBuilder and return new list of source files
val ApplyCommandLineArgs: TcConfigBuilder * string list * string list -> string list
/// Apply args to TcConfigBuilder and return new list of source files
val ApplyCommandLineArgs: tcConfigB: TcConfigBuilder * sourceFiles: string list * argv: string list -> string list

// Expose the "setters" for some user switches, to enable setting of defaults
val SetOptimizeSwitch : TcConfigBuilder -> OptionSwitch -> unit
Expand Down
5 changes: 4 additions & 1 deletion src/fsharp/vs/ServiceUntypedParse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type CompletionContext =
//----------------------------------------------------------------------------

[<Sealed>]
type FSharpParseFileResults(errors : FSharpErrorInfo[], input : Ast.ParsedInput option, parseHadErrors : bool) =
type FSharpParseFileResults(errors: FSharpErrorInfo[], input: Ast.ParsedInput option, parseHadErrors: bool, dependencyFiles: string[]) =

member scope.Errors = errors

Expand Down Expand Up @@ -379,6 +379,9 @@ type FSharpParseFileResults(errors : FSharpErrorInfo[], input : Ast.ParsedInput
(fun msg ->
Trace.TraceInformation(sprintf "FCS: recovering from error in ValidateBreakpointLocationImpl: '%s'" msg)
None)

/// When these files appear or disappear the configuration for the current project is invalidated.
member scope.DependencyFiles = dependencyFiles

member scope.FileName =
match input with
Expand Down
5 changes: 4 additions & 1 deletion src/fsharp/vs/ServiceUntypedParse.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ type internal FSharpParseFileResults =
/// Return the inner-most range associated with a possible breakpoint location
member ValidateBreakpointLocation : pos:pos -> range option

/// When these files change then the build is invalid
member DependencyFiles : string[]

/// Get the errors and warnings for the parse
member Errors : FSharpErrorInfo[]

/// Indicates if any errors occurred during the parse
member ParseHadErrors : bool

internal new: errors: FSharpErrorInfo[] * input: Ast.ParsedInput option * parseHadErrors: bool -> FSharpParseFileResults
internal new: errors: FSharpErrorInfo[] * input: Ast.ParsedInput option * parseHadErrors: bool * dependencyFiles: string[] -> FSharpParseFileResults

/// Information about F# source file names
#if COMPILER_PUBLIC_API
Expand Down
49 changes: 37 additions & 12 deletions src/fsharp/vs/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,9 +1368,11 @@ type FSharpParsingOptions =
CompilingFsLib: bool
IsExe: bool
}

member x.LastFileName =
Debug.Assert(not (Array.isEmpty x.SourceFiles), "Parsing options don't contain any file")
Array.last x.SourceFiles

static member Default =
{ SourceFiles = Array.empty
ConditionalCompilationDefines = []
Expand All @@ -1379,6 +1381,7 @@ type FSharpParsingOptions =
CompilingFsLib = false
IsExe = false
}

static member FromTcConfig(tcConfig: TcConfig, sourceFiles) =
{
SourceFiles = sourceFiles
Expand All @@ -1388,6 +1391,7 @@ type FSharpParsingOptions =
CompilingFsLib = tcConfig.compilingFslib
IsExe = tcConfig.target.IsExe
}

static member FromTcConfigBuidler(tcConfigB: TcConfigBuilder, sourceFiles) =
{
SourceFiles = sourceFiles
Expand All @@ -1397,6 +1401,7 @@ type FSharpParsingOptions =
CompilingFsLib = tcConfigB.compilingFslib
IsExe = tcConfigB.target.IsExe
}

/// Compare two options sets with respect to the parts of the options that are important to parsing.
static member AreSameForParsing(options1: FSharpParsingOptions, options2: FSharpParsingOptions) =
options1 = options2
Expand Down Expand Up @@ -2356,7 +2361,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
async {
foregroundParseCount <- foregroundParseCount + 1
let parseErrors, inputOpt, anyErrors = Parser.parseFile(source, filename, options)
let res = FSharpParseFileResults(parseErrors, inputOpt, anyErrors)
let res = FSharpParseFileResults(parseErrors, inputOpt, anyErrors, options.SourceFiles)
parseCacheLock.AcquireLock(fun ctok -> parseFileInProjectCache.Set(ctok, (filename, source, options), res))
return res
}
Expand All @@ -2368,11 +2373,11 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
let! builderOpt, creationErrors, decrement = getOrCreateBuilderAndKeepAlive (ctok, options, userOpName)
use _unwind = decrement
match builderOpt with
| None -> return FSharpParseFileResults(List.toArray creationErrors, None, true)
| None -> return FSharpParseFileResults(List.toArray creationErrors, None, true, options.SourceFiles)
| Some builder ->
let! inputOpt,_,_,parseErrors = builder.GetParseResultsForFile (ctok, filename)
let errors = [| yield! creationErrors; yield! ErrorHelpers.CreateErrorInfos (builder.TcConfig.errorSeverityOptions, false, filename, parseErrors) |]
return FSharpParseFileResults(errors = errors, input = inputOpt, parseHadErrors = false)
return FSharpParseFileResults(errors = errors, input = inputOpt, parseHadErrors = false, dependencyFiles = options.SourceFiles)
}
)

Expand Down Expand Up @@ -2524,7 +2529,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
use _unwind = decrement
match builderOpt with
| None ->
let parseResults = FSharpParseFileResults(List.toArray creationErrors, None, true)
let parseResults = FSharpParseFileResults(List.toArray creationErrors, None, true, options.SourceFiles)
return (parseResults, FSharpCheckFileAnswer.Aborted)

| Some builder ->
Expand All @@ -2542,7 +2547,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
let parsingOptions = FSharpParsingOptions.FromTcConfig(builder.TcConfig, Array.ofList (builder.SourceFiles))
let parseErrors, inputOpt, anyErrors = Parser.parseFile (source, filename, parsingOptions)

let parseResults = FSharpParseFileResults(parseErrors, inputOpt, anyErrors)
let parseResults = FSharpParseFileResults(parseErrors, inputOpt, anyErrors, options.SourceFiles)
let! checkResults = bc.CheckOneFileImpl(parseResults, source, filename, options, textSnapshotInfo, fileVersion, builder, tcPrior, creationErrors, userOpName)
return parseResults, checkResults
finally
Expand All @@ -2557,7 +2562,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
use _unwind = decrement
match builderOpt with
| None ->
let parseResults = FSharpParseFileResults(Array.ofList creationErrors, None, true)
let parseResults = FSharpParseFileResults(Array.ofList creationErrors, None, true, options.SourceFiles)
let typedResults = MakeCheckFileResultsEmpty(filename, creationErrors)
return (parseResults, typedResults)
| Some builder ->
Expand All @@ -2566,7 +2571,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
let errorOptions = builder.TcConfig.errorSeverityOptions
let untypedErrors = [| yield! creationErrors; yield! ErrorHelpers.CreateErrorInfos (errorOptions, false, filename, untypedErrors) |]
let tcErrors = [| yield! creationErrors; yield! ErrorHelpers.CreateErrorInfos (errorOptions, false, filename, tcProj.Errors) |]
let parseResults = FSharpParseFileResults(errors = untypedErrors, input = inputOpt, parseHadErrors = false)
let parseResults = FSharpParseFileResults(errors = untypedErrors, input = inputOpt, parseHadErrors = false, dependencyFiles = Array.ofList builder.AllDependenciesDeprecated)
let loadClosure = scriptClosureCacheLock.AcquireLock (fun ltok -> scriptClosureCache.TryGet (ltok, options) )
let scope =
TypeCheckInfo(tcProj.TcConfig, tcProj.TcGlobals, tcProj.TcState.PartialAssemblySignature, tcProj.TcState.Ccu, tcProj.TcImports, tcProj.TcEnvAtEnd.AccessRights,
Expand Down Expand Up @@ -2803,7 +2808,8 @@ type FSharpChecker(legacyReferenceResolver, projectCacheSize, keepAssemblyConten

member ic.ReferenceResolver = legacyReferenceResolver

member ic.MatchBraces(filename, source, options: FSharpParsingOptions) =
member ic.MatchBraces(filename, source, options: FSharpParsingOptions, ?userOpName: string) =
let _ = defaultArg userOpName "Unknown"
async {
match braceMatchCache.TryGet(AssumeAnyCallerThreadWithoutEvidence(), (filename, source, options)) with
| Some res -> return res
Expand All @@ -2813,10 +2819,26 @@ type FSharpChecker(legacyReferenceResolver, projectCacheSize, keepAssemblyConten
return res
}

member ic.ParseFile(filename, source, options) =
member ic.GetParsingOptionsFromProjectOptions(options): FSharpParsingOptions =
let sourceFiles = List.ofArray options.SourceFiles
let argv = List.ofArray options.OtherOptions
let parsingOptions, _ = ic.GetParsingOptionsFromSourceFilesAndCommandLineArgs(sourceFiles, argv)
parsingOptions

member ic.MatchBraces(filename, source, options: FSharpProjectOptions, ?userOpName: string) =
let _ = defaultArg userOpName "Unknown"
ic.MatchBraces(filename, source, ic.GetParsingOptionsFromProjectOptions(options), ?userOpName = userOpName)

member ic.ParseFile(filename, source, options, ?userOpName: string) =
let _ = defaultArg userOpName "Unknown"
ic.CheckMaxMemoryReached()
backgroundCompiler.ParseFile(filename, source, options)


member ic.ParseFileInProject(filename, source, options, ?userOpName: string) =
let _ = defaultArg userOpName "Unknown"
ic.ParseFile(filename, source, ic.GetParsingOptionsFromProjectOptions(options))

member ic.GetBackgroundParseResultsForFileInProject (filename,options, ?userOpName: string) =
let userOpName = defaultArg userOpName "Unknown"
backgroundCompiler.GetBackgroundParseResultsForFileInProject(filename, options, userOpName)
Expand Down Expand Up @@ -3002,14 +3024,17 @@ type FSharpChecker(legacyReferenceResolver, projectCacheSize, keepAssemblyConten
ExtraProjectInfo=extraProjectInfo
Stamp = None }

member ic.GetParsingOptionsFromCommandLineArgs(argv) =
member ic.GetParsingOptionsFromSourceFilesAndCommandLineArgs(initialSourceFiles, argv) =
use errorScope = new ErrorScope()
let tcConfigBuilder = TcConfigBuilder.Initial

// Apply command-line arguments and collect more source files if they are in the arguments
let sourceFilesNew = ApplyCommandLineArgs(tcConfigBuilder, [], argv)
let sourceFilesNew = ApplyCommandLineArgs(tcConfigBuilder, initialSourceFiles, argv)
FSharpParsingOptions.FromTcConfigBuidler(tcConfigBuilder, Array.ofList sourceFilesNew), errorScope.Diagnostics

member ic.GetParsingOptionsFromCommandLineArgs(argv) =
ic.GetParsingOptionsFromSourceFilesAndCommandLineArgs([], argv)

/// Begin background parsing the given project.
member ic.StartBackgroundCompile(options, ?userOpName) =
let userOpName = defaultArg userOpName "Unknown"
Expand Down Expand Up @@ -3082,7 +3107,7 @@ type FsiInteractiveChecker(legacyReferenceResolver, reactorOps: IReactorOperatio
let parsingOptions = FSharpParsingOptions.FromTcConfig(tcConfig, [| filename |])
let parseErrors, inputOpt, anyErrors = Parser.parseFile (source, filename, parsingOptions)
let dependencyFiles = [] // interactions have no dependencies
let parseResults = FSharpParseFileResults(parseErrors, inputOpt, parseHadErrors = anyErrors)
let parseResults = FSharpParseFileResults(parseErrors, inputOpt, parseHadErrors = anyErrors, dependencyFiles = parsingOptions.SourceFiles)

let backgroundDiagnostics = []

Expand Down
38 changes: 36 additions & 2 deletions src/fsharp/vs/service.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,19 @@ type internal FSharpChecker =
/// <param name="filename">The filename for the file, used to help caching of results.</param>
/// <param name="source">The full source for the file.</param>
/// <param name="options">Parsing options for the project or script.</param>
member MatchBraces: filename: string * source: string * options: FSharpParsingOptions -> Async<(range * range)[]>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member MatchBraces: filename: string * source: string * options: FSharpParsingOptions * ?userOpName: string -> Async<(range * range)[]>

/// <summary>
/// Parse a source code file, returning information about brace matching in the file.
/// Return an enumeration of the matching parenthetical tokens in the file.
/// </summary>
///
/// <param name="filename">The filename for the file, used to help caching of results.</param>
/// <param name="source">The full source for the file.</param>
/// <param name="options">Parsing options for the project or script.</param>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member MatchBraces: filename: string * source: string * options: FSharpProjectOptions * ?userOpName: string -> Async<(range * range)[]>

/// <summary>
/// <para>Parse a source code file, returning a handle that can be used for obtaining navigation bar information
Expand All @@ -412,7 +424,20 @@ type internal FSharpChecker =
/// <param name="filename">The filename for the file.</param>
/// <param name="source">The full source for the file.</param>
/// <param name="options">Parsing options for the project or script.</param>
member ParseFile: filename: string * source: string * options: FSharpParsingOptions -> Async<FSharpParseFileResults>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member ParseFile: filename: string * source: string * options: FSharpParsingOptions * ?userOpName: string -> Async<FSharpParseFileResults>

/// <summary>
/// <para>Parse a source code file, returning a handle that can be used for obtaining navigation bar information
/// To get the full information, call 'CheckFileInProject' method on the result</para>
/// <para>All files except the one being checked are read from the FileSystem API</para>
/// </summary>
///
/// <param name="filename">The filename for the file.</param>
/// <param name="source">The full source for the file.</param>
/// <param name="options">The options for the project or script, used to determine active --define conditionals and other options relevant to parsing.</param>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member ParseFileInProject: filename: string * source: string * options: FSharpProjectOptions * ?userOpName: string -> Async<FSharpParseFileResults>

/// <summary>
/// <para>Check a source code file, returning a handle to the results of the parse including
Expand Down Expand Up @@ -529,6 +554,15 @@ type internal FSharpChecker =
/// so that references are re-resolved.</param>
member GetProjectOptionsFromCommandLineArgs : projectFileName: string * argv: string[] * ?loadedTimeStamp: DateTime * ?extraProjectInfo: obj -> FSharpProjectOptions

/// <summary>
/// <para>Get the FSharpParsingOptions implied by a set of command line arguments.</para>
/// </summary>
///
/// <param name="projectFileName">Used to differentiate between projects and for the base directory of the project.</param>
/// <param name="argv">The command line arguments for the project build.</param>
/// <param name="loadedTimeStamp">Indicates when the script was loaded into the editing environment,
/// so that an 'unload' and 'reload' action will cause the script to be considered as a new project,
/// so that references are re-resolved.</param>
member GetParsingOptionsFromCommandLineArgs: string list -> FSharpParsingOptions * FSharpErrorInfo list

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type internal FSharpBraceMatchingService

static let defaultUserOpName = "BraceMatching"

static member GetBraceMatchingResult(checker: FSharpChecker, sourceText, fileName, options, position: int, userOpName: string) =
static member GetBraceMatchingResult(checker: FSharpChecker, sourceText, fileName, options: FSharpProjectOptions, position: int, userOpName: string) =
async {
let! matchedBraces = checker.MatchBraces(fileName, sourceText.ToString(), options, userOpName)
let isPositionInRange range =
Expand Down
2 changes: 1 addition & 1 deletion vsintegration/src/FSharp.LanguageService/FSharpSource.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type internal IFSharpSource_DEPRECATED =
/// Store a ProjectSite for obtaining a task provider
abstract ProjectSite : IProjectSite option with get,set
/// Specify the files that should trigger a rebuild for the project behind this source
abstract SetDependencyFiles : string list -> bool
abstract SetDependencyFiles : string[] -> bool



Expand Down

0 comments on commit 200d144

Please sign in to comment.