Skip to content

Commit ebd758e

Browse files
authored
Move flatErrors tests from fsharpqa (#15251)
* temp * tests * flaterrors * update tests
1 parent 175736d commit ebd758e

File tree

21 files changed

+402
-243
lines changed

21 files changed

+402
-243
lines changed

src/Compiler/Interactive/fsi.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4689,7 +4689,7 @@ type FsiEvaluationSession
46894689
let errs = diagnosticsLogger.GetDiagnostics()
46904690

46914691
let errorInfos =
4692-
DiagnosticHelpers.CreateDiagnostics(errorOptions, true, scriptFile, errs, true)
4692+
DiagnosticHelpers.CreateDiagnostics(errorOptions, true, scriptFile, errs, true, tcConfigB.flatErrors)
46934693

46944694
let userRes =
46954695
match res with

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,8 @@ module internal ParseAndCheckFile =
22072207
mainInputFileName,
22082208
diagnosticsOptions: FSharpDiagnosticOptions,
22092209
sourceText: ISourceText,
2210-
suggestNamesForErrors: bool
2210+
suggestNamesForErrors: bool,
2211+
flatErrors: bool
22112212
) =
22122213
let mutable options = diagnosticsOptions
22132214
let diagnosticsCollector = ResizeArray<_>()
@@ -2218,7 +2219,16 @@ module internal ParseAndCheckFile =
22182219

22192220
let collectOne severity diagnostic =
22202221
for diagnostic in
2221-
DiagnosticHelpers.ReportDiagnostic(options, false, mainInputFileName, fileInfo, diagnostic, severity, suggestNamesForErrors) do
2222+
DiagnosticHelpers.ReportDiagnostic(
2223+
options,
2224+
false,
2225+
mainInputFileName,
2226+
fileInfo,
2227+
diagnostic,
2228+
severity,
2229+
suggestNamesForErrors,
2230+
flatErrors
2231+
) do
22222232
diagnosticsCollector.Add diagnostic
22232233

22242234
if severity = FSharpDiagnosticSeverity.Error then
@@ -2327,7 +2337,7 @@ module internal ParseAndCheckFile =
23272337

23282338
usingLexbufForParsing (createLexbuf options.LangVersionText sourceText, fileName) (fun lexbuf ->
23292339
let errHandler =
2330-
DiagnosticsHandler(false, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors)
2340+
DiagnosticsHandler(false, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors, false)
23312341

23322342
let lexfun = createLexerFunction fileName options lexbuf errHandler
23332343

@@ -2421,6 +2431,7 @@ module internal ParseAndCheckFile =
24212431
options: FSharpParsingOptions,
24222432
userOpName: string,
24232433
suggestNamesForErrors: bool,
2434+
flatErrors: bool,
24242435
identCapture: bool
24252436
) =
24262437
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "parseFile", fileName)
@@ -2429,7 +2440,7 @@ module internal ParseAndCheckFile =
24292440
Activity.start "ParseAndCheckFile.parseFile" [| Activity.Tags.fileName, fileName |]
24302441

24312442
let errHandler =
2432-
DiagnosticsHandler(true, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors)
2443+
DiagnosticsHandler(true, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors, flatErrors)
24332444

24342445
use _ = UseDiagnosticsLogger errHandler.DiagnosticsLogger
24352446

@@ -2596,7 +2607,14 @@ module internal ParseAndCheckFile =
25962607

25972608
// Initialize the error handler
25982609
let errHandler =
2599-
DiagnosticsHandler(true, mainInputFileName, tcConfig.diagnosticsOptions, sourceText, suggestNamesForErrors)
2610+
DiagnosticsHandler(
2611+
true,
2612+
mainInputFileName,
2613+
tcConfig.diagnosticsOptions,
2614+
sourceText,
2615+
suggestNamesForErrors,
2616+
tcConfig.flatErrors
2617+
)
26002618

26012619
use _ = UseDiagnosticsLogger errHandler.DiagnosticsLogger
26022620

@@ -3260,6 +3278,7 @@ type FsiInteractiveChecker(legacyReferenceResolver, tcConfig: TcConfig, tcGlobal
32603278
parsingOptions,
32613279
userOpName,
32623280
suggestNamesForErrors,
3281+
tcConfig.flatErrors,
32633282
tcConfig.captureIdentifiersWhenParsing
32643283
)
32653284

src/Compiler/Service/FSharpCheckerResults.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ module internal ParseAndCheckFile =
537537
options: FSharpParsingOptions *
538538
userOpName: string *
539539
suggestNamesForErrors: bool *
540+
flatErrors: bool *
540541
identCapture: bool ->
541542
FSharpDiagnostic[] * ParsedInput * bool
542543

src/Compiler/Service/IncrementalBuild.fs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,16 +1599,18 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc
15991599
}
16001600

16011601
let diagnostics =
1602-
match builderOpt with
1603-
| Some builder ->
1604-
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions
1605-
let diagnosticsLogger = CompilationDiagnosticLogger("IncrementalBuilderCreation", diagnosticsOptions)
1606-
delayedLogger.CommitDelayedDiagnostics diagnosticsLogger
1607-
diagnosticsLogger.GetDiagnostics()
1608-
| _ ->
1609-
Array.ofList delayedLogger.Diagnostics
1602+
let diagnostics, flatErrors =
1603+
match builderOpt with
1604+
| Some builder ->
1605+
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions
1606+
let diagnosticsLogger = CompilationDiagnosticLogger("IncrementalBuilderCreation", diagnosticsOptions)
1607+
delayedLogger.CommitDelayedDiagnostics diagnosticsLogger
1608+
diagnosticsLogger.GetDiagnostics(), builder.TcConfig.flatErrors
1609+
| _ ->
1610+
Array.ofList delayedLogger.Diagnostics, false
1611+
diagnostics
16101612
|> Array.map (fun (diagnostic, severity) ->
1611-
FSharpDiagnostic.CreateFromException(diagnostic, severity, range.Zero, suggestNamesForErrors))
1613+
FSharpDiagnostic.CreateFromException(diagnostic, severity, range.Zero, suggestNamesForErrors, flatErrors))
16121614

16131615
return builderOpt, diagnostics
16141616
}

src/Compiler/Service/ServiceAssemblyContent.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ module AssemblyContent =
247247
// are not triggered (see "if not entity.IsProvided") and the other data accessed is immutable or computed safely
248248
// on-demand. However a more compete review may be warranted.
249249

250-
use _ignoreAllDiagnostics = new DiagnosticsScope()
250+
use _ignoreAllDiagnostics = new DiagnosticsScope(false)
251251

252252
signature.TryGetEntities()
253253
|> Seq.collect (traverseEntity contentType Parent.Empty)
@@ -265,7 +265,7 @@ module AssemblyContent =
265265
// concurrently with other threads. On an initial review this is not a problem since type provider computations
266266
// are not triggered (see "if not entity.IsProvided") and the other data accessed is immutable or computed safely
267267
// on-demand. However a more compete review may be warranted.
268-
use _ignoreAllDiagnostics = new DiagnosticsScope()
268+
use _ignoreAllDiagnostics = new DiagnosticsScope(false)
269269

270270
#if !NO_TYPEPROVIDERS
271271
match assemblies |> List.filter (fun x -> not x.IsProviderGenerated), fileName with

src/Compiler/Service/ServiceParsedInputOps.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ module ParsedInput =
20122012
// We ignore all diagnostics during this operation
20132013
//
20142014
// Based on an initial review, no diagnostics should be generated. However the code should be checked more closely.
2015-
use _ignoreAllDiagnostics = new DiagnosticsScope()
2015+
use _ignoreAllDiagnostics = new DiagnosticsScope(false)
20162016

20172017
let mutable result = None
20182018
let mutable ns = None
@@ -2175,7 +2175,7 @@ module ParsedInput =
21752175
// We ignore all diagnostics during this operation
21762176
//
21772177
// Based on an initial review, no diagnostics should be generated. However the code should be checked more closely.
2178-
use _ignoreAllDiagnostics = new DiagnosticsScope()
2178+
use _ignoreAllDiagnostics = new DiagnosticsScope(false)
21792179

21802180
match res with
21812181
| None -> [||]

src/Compiler/Service/service.fs

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ module Helpers =
9999
| _ -> false
100100

101101
module CompileHelpers =
102-
let mkCompilationDiagnosticsHandlers () =
102+
let mkCompilationDiagnosticsHandlers (flatErrors) =
103103
let diagnostics = ResizeArray<_>()
104104

105105
let diagnosticsLogger =
106106
{ new DiagnosticsLogger("CompileAPI") with
107107

108108
member _.DiagnosticSink(diag, isError) =
109-
diagnostics.Add(FSharpDiagnostic.CreateFromException(diag, isError, range0, true)) // Suggest names for errors
109+
diagnostics.Add(FSharpDiagnostic.CreateFromException(diag, isError, range0, true, flatErrors)) // Suggest names for errors
110110

111111
member _.ErrorCount =
112112
diagnostics
@@ -137,7 +137,8 @@ module CompileHelpers =
137137
/// Compile using the given flags. Source files names are resolved via the FileSystem API. The output file must be given by a -o flag.
138138
let compileFromArgs (ctok, argv: string[], legacyReferenceResolver, tcImportsCapture, dynamicAssemblyCreator) =
139139

140-
let diagnostics, diagnosticsLogger, loggerProvider = mkCompilationDiagnosticsHandlers ()
140+
let diagnostics, diagnosticsLogger, loggerProvider =
141+
mkCompilationDiagnosticsHandlers (argv |> Array.contains "--flaterrors")
141142

142143
let result =
143144
tryCompile diagnosticsLogger (fun exiter ->
@@ -487,7 +488,7 @@ type BackgroundCompiler
487488
checkFileInProjectCache.Set(ltok, key, res)
488489
res)
489490

490-
member _.ParseFile(fileName: string, sourceText: ISourceText, options: FSharpParsingOptions, cache: bool, userOpName: string) =
491+
member _.ParseFile(fileName: string, sourceText: ISourceText, options: FSharpParsingOptions, cache: bool, flatErrors: bool, userOpName: string) =
491492
async {
492493
use _ =
493494
Activity.start
@@ -507,14 +508,22 @@ type BackgroundCompiler
507508
Interlocked.Increment(&actualParseFileCount) |> ignore
508509

509510
let parseDiagnostics, parseTree, anyErrors =
510-
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, suggestNamesForErrors, captureIdentifiersWhenParsing)
511+
ParseAndCheckFile.parseFile (
512+
sourceText,
513+
fileName,
514+
options,
515+
userOpName,
516+
suggestNamesForErrors,
517+
flatErrors,
518+
captureIdentifiersWhenParsing
519+
)
511520

512521
let res = FSharpParseFileResults(parseDiagnostics, parseTree, anyErrors, options.SourceFiles)
513522
parseCacheLock.AcquireLock(fun ltok -> parseFileCache.Set(ltok, (fileName, hash, options), res))
514523
return res
515524
else
516525
let parseDiagnostics, parseTree, anyErrors =
517-
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, false, captureIdentifiersWhenParsing)
526+
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, false, flatErrors, captureIdentifiersWhenParsing)
518527

519528
return FSharpParseFileResults(parseDiagnostics, parseTree, anyErrors, options.SourceFiles)
520529
}
@@ -537,7 +546,14 @@ type BackgroundCompiler
537546
let parseTree, _, _, parseDiagnostics = builder.GetParseResultsForFile fileName
538547

539548
let parseDiagnostics =
540-
DiagnosticHelpers.CreateDiagnostics(builder.TcConfig.diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors)
549+
DiagnosticHelpers.CreateDiagnostics(
550+
builder.TcConfig.diagnosticsOptions,
551+
false,
552+
fileName,
553+
parseDiagnostics,
554+
suggestNamesForErrors,
555+
builder.TcConfig.flatErrors
556+
)
541557

542558
let diagnostics = [| yield! creationDiags; yield! parseDiagnostics |]
543559

@@ -767,6 +783,7 @@ type BackgroundCompiler
767783
parsingOptions,
768784
userOpName,
769785
suggestNamesForErrors,
786+
builder.TcConfig.flatErrors,
770787
captureIdentifiersWhenParsing
771788
)
772789

@@ -835,12 +852,26 @@ type BackgroundCompiler
835852
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions
836853

837854
let parseDiagnostics =
838-
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors)
855+
DiagnosticHelpers.CreateDiagnostics(
856+
diagnosticsOptions,
857+
false,
858+
fileName,
859+
parseDiagnostics,
860+
suggestNamesForErrors,
861+
builder.TcConfig.flatErrors
862+
)
839863

840864
let parseDiagnostics = [| yield! creationDiags; yield! parseDiagnostics |]
841865

842866
let tcDiagnostics =
843-
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, tcDiagnostics, suggestNamesForErrors)
867+
DiagnosticHelpers.CreateDiagnostics(
868+
diagnosticsOptions,
869+
false,
870+
fileName,
871+
tcDiagnostics,
872+
suggestNamesForErrors,
873+
builder.TcConfig.flatErrors
874+
)
844875

845876
let tcDiagnostics = [| yield! creationDiags; yield! tcDiagnostics |]
846877

@@ -994,7 +1025,14 @@ type BackgroundCompiler
9941025
let tcDependencyFiles = tcInfo.tcDependencyFiles
9951026

9961027
let tcDiagnostics =
997-
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, true, fileName, tcDiagnostics, suggestNamesForErrors)
1028+
DiagnosticHelpers.CreateDiagnostics(
1029+
diagnosticsOptions,
1030+
true,
1031+
fileName,
1032+
tcDiagnostics,
1033+
suggestNamesForErrors,
1034+
builder.TcConfig.flatErrors
1035+
)
9981036

9991037
let diagnostics = [| yield! creationDiags; yield! tcDiagnostics |]
10001038

@@ -1083,8 +1121,6 @@ type BackgroundCompiler
10831121
[| Activity.Tags.fileName, fileName; Activity.Tags.userOpName, _userOpName |]
10841122

10851123
cancellable {
1086-
use diagnostics = new DiagnosticsScope()
1087-
10881124
// Do we add a reference to FSharp.Compiler.Interactive.Settings by default?
10891125
let useFsiAuxLib = defaultArg useFsiAuxLib true
10901126
let useSdkRefs = defaultArg useSdkRefs true
@@ -1102,6 +1138,8 @@ type BackgroundCompiler
11021138

11031139
let otherFlags = defaultArg otherFlags extraFlags
11041140

1141+
use diagnostics = new DiagnosticsScope(otherFlags |> Array.contains "--flaterrors")
1142+
11051143
let useSimpleResolution = otherFlags |> Array.exists (fun x -> x = "--simpleresolution")
11061144

11071145
let loadedTimeStamp = defaultArg loadedTimeStamp DateTime.MaxValue // Not 'now', we don't want to force reloading
@@ -1159,7 +1197,8 @@ type BackgroundCompiler
11591197

11601198
let diags =
11611199
loadClosure.LoadClosureRootFileDiagnostics
1162-
|> List.map (fun (exn, isError) -> FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false))
1200+
|> List.map (fun (exn, isError) ->
1201+
FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false, options.OtherOptions |> Array.contains "--flaterrors"))
11631202

11641203
return options, (diags @ diagnostics.Diagnostics)
11651204
}
@@ -1414,7 +1453,7 @@ type FSharpChecker
14141453
member _.ParseFile(fileName, sourceText, options, ?cache, ?userOpName: string) =
14151454
let cache = defaultArg cache true
14161455
let userOpName = defaultArg userOpName "Unknown"
1417-
backgroundCompiler.ParseFile(fileName, sourceText, options, cache, userOpName)
1456+
backgroundCompiler.ParseFile(fileName, sourceText, options, cache, false, userOpName)
14181457

14191458
member ic.ParseFileInProject(fileName, source: string, options, ?cache: bool, ?userOpName: string) =
14201459
let parsingOptions, _ = ic.GetParsingOptionsFromProjectOptions(options)
@@ -1650,7 +1689,7 @@ type FSharpChecker
16501689
member _.GetParsingOptionsFromCommandLineArgs(sourceFiles, argv, ?isInteractive, ?isEditing) =
16511690
let isEditing = defaultArg isEditing false
16521691
let isInteractive = defaultArg isInteractive false
1653-
use errorScope = new DiagnosticsScope()
1692+
use errorScope = new DiagnosticsScope(argv |> List.contains "--flaterrors")
16541693

16551694
let tcConfigB =
16561695
TcConfigBuilder.CreateNew(

0 commit comments

Comments
 (0)