Skip to content

Commit 8c33139

Browse files
auduchinokcartermp
authored andcommitted
Add FSharpChecker.ParseFileNoCache (#7108)
* Add FSharpChecker.ParseFileNoCache * Review feedback
1 parent 274ffb1 commit 8c33139

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/fsharp/service/service.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
423423
return res
424424
}
425425

426+
member bc.ParseFileNoCache(filename, sourceText, options, userOpName) =
427+
async {
428+
let parseErrors, parseTreeOpt, anyErrors = ParseAndCheckFile.parseFile(sourceText, filename, options, userOpName, false)
429+
return FSharpParseFileResults(parseErrors, parseTreeOpt, anyErrors, options.SourceFiles)
430+
}
431+
426432
/// Fetch the parse information from the background compiler (which checks w.r.t. the FileSystem API)
427433
member __.GetBackgroundParseResultsForFileInProject(filename, options, userOpName) =
428434
reactor.EnqueueAndAwaitOpAsync(userOpName, "GetBackgroundParseResultsForFileInProject ", filename, fun ctok ->
@@ -961,6 +967,11 @@ type FSharpChecker(legacyReferenceResolver,
961967
ic.CheckMaxMemoryReached()
962968
backgroundCompiler.ParseFile(filename, sourceText, options, userOpName)
963969

970+
member ic.ParseFileNoCache(filename, sourceText, options, ?userOpName) =
971+
let userOpName = defaultArg userOpName "Unknown"
972+
ic.CheckMaxMemoryReached()
973+
backgroundCompiler.ParseFileNoCache(filename, sourceText, options, userOpName)
974+
964975
member ic.ParseFileInProject(filename, source: string, options, ?userOpName: string) =
965976
let userOpName = defaultArg userOpName "Unknown"
966977
let parsingOptions, _ = ic.GetParsingOptionsFromProjectOptions(options)

src/fsharp/service/service.fsi

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,32 @@ type public FSharpChecker =
103103
member MatchBraces: filename: string * source: string * options: FSharpProjectOptions * ?userOpName: string -> Async<(range * range)[]>
104104

105105
/// <summary>
106-
/// <para>Parse a source code file, returning a handle that can be used for obtaining navigation bar information
107-
/// To get the full information, call 'CheckFileInProject' method on the result</para>
106+
/// Parses a source code for a file and caches the results. Returns an AST that can be traversed for various features.
108107
/// </summary>
109108
///
110-
/// <param name="filename">The filename for the file.</param>
111-
/// <param name="sourceText">The full source for the file.</param>
109+
/// <param name="filename">The path for the file. The file name is used as a module name for implicit top level modules (e.g. in scripts).</param>
110+
/// <param name="sourceText">The source to be parsed.</param>
112111
/// <param name="options">Parsing options for the project or script.</param>
113112
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
114113
member ParseFile: filename: string * sourceText: ISourceText * options: FSharpParsingOptions * ?userOpName: string -> Async<FSharpParseFileResults>
115114

116115
/// <summary>
117-
/// <para>Parse a source code file, returning a handle that can be used for obtaining navigation bar information
118-
/// To get the full information, call 'CheckFileInProject' method on the result</para>
119-
/// <para>All files except the one being checked are read from the FileSystem API</para>
116+
/// Parses a source code for a file. Returns an AST that can be traversed for various features.
120117
/// </summary>
121118
///
122-
/// <param name="filename">The filename for the file.</param>
123-
/// <param name="source">The full source for the file.</param>
124-
/// <param name="options">The options for the project or script, used to determine active --define conditionals and other options relevant to parsing.</param>
119+
/// <param name="filename">The path for the file. The file name is also as a module name for implicit top level modules (e.g. in scripts).</param>
120+
/// <param name="sourceText">The source to be parsed.</param>
121+
/// <param name="options">Parsing options for the project or script.</param>
122+
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
123+
member ParseFileNoCache: filename: string * sourceText: ISourceText * options: FSharpParsingOptions * ?userOpName: string -> Async<FSharpParseFileResults>
124+
125+
/// <summary>
126+
/// Parses a source code for a file. Returns an AST that can be traversed for various features.
127+
/// </summary>
128+
///
129+
/// <param name="filename">The path for the file. The file name is also as a module name for implicit top level modules (e.g. in scripts).</param>
130+
/// <param name="sourceText">The source to be parsed.</param>
131+
/// <param name="options">Parsing options for the project or script.</param>
125132
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
126133
[<Obsolete("Please call checker.ParseFile instead. To do this, you must also pass FSharpParsingOptions instead of FSharpProjectOptions. If necessary generate FSharpParsingOptions from FSharpProjectOptions by calling checker.GetParsingOptionsFromProjectOptions(options)")>]
127134
member ParseFileInProject: filename: string * source: string * options: FSharpProjectOptions * ?userOpName: string -> Async<FSharpParseFileResults>

0 commit comments

Comments
 (0)