Skip to content

Commit 465676e

Browse files
committed
flaterrors
1 parent 417a055 commit 465676e

File tree

10 files changed

+65
-53
lines changed

10 files changed

+65
-53
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: 8 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,7 @@ 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(options, false, mainInputFileName, fileInfo, diagnostic, severity, suggestNamesForErrors, flatErrors) do
22222223
diagnosticsCollector.Add diagnostic
22232224

22242225
if severity = FSharpDiagnosticSeverity.Error then
@@ -2327,7 +2328,7 @@ module internal ParseAndCheckFile =
23272328

23282329
usingLexbufForParsing (createLexbuf options.LangVersionText sourceText, fileName) (fun lexbuf ->
23292330
let errHandler =
2330-
DiagnosticsHandler(false, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors)
2331+
DiagnosticsHandler(false, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors, false)
23312332

23322333
let lexfun = createLexerFunction fileName options lexbuf errHandler
23332334

@@ -2421,6 +2422,7 @@ module internal ParseAndCheckFile =
24212422
options: FSharpParsingOptions,
24222423
userOpName: string,
24232424
suggestNamesForErrors: bool,
2425+
flatErrors: bool,
24242426
identCapture: bool
24252427
) =
24262428
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "parseFile", fileName)
@@ -2429,7 +2431,7 @@ module internal ParseAndCheckFile =
24292431
Activity.start "ParseAndCheckFile.parseFile" [| Activity.Tags.fileName, fileName |]
24302432

24312433
let errHandler =
2432-
DiagnosticsHandler(true, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors)
2434+
DiagnosticsHandler(true, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors, flatErrors)
24332435

24342436
use _ = UseDiagnosticsLogger errHandler.DiagnosticsLogger
24352437

@@ -2596,7 +2598,7 @@ module internal ParseAndCheckFile =
25962598

25972599
// Initialize the error handler
25982600
let errHandler =
2599-
DiagnosticsHandler(true, mainInputFileName, tcConfig.diagnosticsOptions, sourceText, suggestNamesForErrors)
2601+
DiagnosticsHandler(true, mainInputFileName, tcConfig.diagnosticsOptions, sourceText, suggestNamesForErrors, tcConfig.flatErrors)
26002602

26012603
use _ = UseDiagnosticsLogger errHandler.DiagnosticsLogger
26022604

@@ -3260,6 +3262,7 @@ type FsiInteractiveChecker(legacyReferenceResolver, tcConfig: TcConfig, tcGlobal
32603262
parsingOptions,
32613263
userOpName,
32623264
suggestNamesForErrors,
3265+
tcConfig.flatErrors,
32633266
tcConfig.captureIdentifiersWhenParsing
32643267
)
32653268

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: 16 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,7 @@ 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 = mkCompilationDiagnosticsHandlers (argv |> Array.contains "--flaterrors")
141141

142142
let result =
143143
tryCompile diagnosticsLogger (fun exiter ->
@@ -487,7 +487,7 @@ type BackgroundCompiler
487487
checkFileInProjectCache.Set(ltok, key, res)
488488
res)
489489

490-
member _.ParseFile(fileName: string, sourceText: ISourceText, options: FSharpParsingOptions, cache: bool, userOpName: string) =
490+
member _.ParseFile(fileName: string, sourceText: ISourceText, options: FSharpParsingOptions, cache: bool, flatErrors: bool, userOpName: string) =
491491
async {
492492
use _ =
493493
Activity.start
@@ -507,14 +507,14 @@ type BackgroundCompiler
507507
Interlocked.Increment(&actualParseFileCount) |> ignore
508508

509509
let parseDiagnostics, parseTree, anyErrors =
510-
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, suggestNamesForErrors, captureIdentifiersWhenParsing)
510+
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, suggestNamesForErrors, flatErrors, captureIdentifiersWhenParsing)
511511

512512
let res = FSharpParseFileResults(parseDiagnostics, parseTree, anyErrors, options.SourceFiles)
513513
parseCacheLock.AcquireLock(fun ltok -> parseFileCache.Set(ltok, (fileName, hash, options), res))
514514
return res
515515
else
516516
let parseDiagnostics, parseTree, anyErrors =
517-
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, false, captureIdentifiersWhenParsing)
517+
ParseAndCheckFile.parseFile (sourceText, fileName, options, userOpName, false, flatErrors, captureIdentifiersWhenParsing)
518518

519519
return FSharpParseFileResults(parseDiagnostics, parseTree, anyErrors, options.SourceFiles)
520520
}
@@ -537,7 +537,7 @@ type BackgroundCompiler
537537
let parseTree, _, _, parseDiagnostics = builder.GetParseResultsForFile fileName
538538

539539
let parseDiagnostics =
540-
DiagnosticHelpers.CreateDiagnostics(builder.TcConfig.diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors)
540+
DiagnosticHelpers.CreateDiagnostics(builder.TcConfig.diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)
541541

542542
let diagnostics = [| yield! creationDiags; yield! parseDiagnostics |]
543543

@@ -767,6 +767,7 @@ type BackgroundCompiler
767767
parsingOptions,
768768
userOpName,
769769
suggestNamesForErrors,
770+
builder.TcConfig.flatErrors,
770771
captureIdentifiersWhenParsing
771772
)
772773

@@ -835,12 +836,12 @@ type BackgroundCompiler
835836
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions
836837

837838
let parseDiagnostics =
838-
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors)
839+
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, parseDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)
839840

840841
let parseDiagnostics = [| yield! creationDiags; yield! parseDiagnostics |]
841842

842843
let tcDiagnostics =
843-
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, tcDiagnostics, suggestNamesForErrors)
844+
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, false, fileName, tcDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)
844845

845846
let tcDiagnostics = [| yield! creationDiags; yield! tcDiagnostics |]
846847

@@ -994,7 +995,7 @@ type BackgroundCompiler
994995
let tcDependencyFiles = tcInfo.tcDependencyFiles
995996

996997
let tcDiagnostics =
997-
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, true, fileName, tcDiagnostics, suggestNamesForErrors)
998+
DiagnosticHelpers.CreateDiagnostics(diagnosticsOptions, true, fileName, tcDiagnostics, suggestNamesForErrors, builder.TcConfig.flatErrors)
998999

9991000
let diagnostics = [| yield! creationDiags; yield! tcDiagnostics |]
10001001

@@ -1083,8 +1084,6 @@ type BackgroundCompiler
10831084
[| Activity.Tags.fileName, fileName; Activity.Tags.userOpName, _userOpName |]
10841085

10851086
cancellable {
1086-
use diagnostics = new DiagnosticsScope()
1087-
10881087
// Do we add a reference to FSharp.Compiler.Interactive.Settings by default?
10891088
let useFsiAuxLib = defaultArg useFsiAuxLib true
10901089
let useSdkRefs = defaultArg useSdkRefs true
@@ -1102,6 +1101,8 @@ type BackgroundCompiler
11021101

11031102
let otherFlags = defaultArg otherFlags extraFlags
11041103

1104+
use diagnostics = new DiagnosticsScope (otherFlags |> Array.contains "--flaterrors")
1105+
11051106
let useSimpleResolution = otherFlags |> Array.exists (fun x -> x = "--simpleresolution")
11061107

11071108
let loadedTimeStamp = defaultArg loadedTimeStamp DateTime.MaxValue // Not 'now', we don't want to force reloading
@@ -1159,7 +1160,7 @@ type BackgroundCompiler
11591160

11601161
let diags =
11611162
loadClosure.LoadClosureRootFileDiagnostics
1162-
|> List.map (fun (exn, isError) -> FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false))
1163+
|> List.map (fun (exn, isError) -> FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false, options.OtherOptions |> Array.contains "--flaterrors"))
11631164

11641165
return options, (diags @ diagnostics.Diagnostics)
11651166
}
@@ -1414,7 +1415,7 @@ type FSharpChecker
14141415
member _.ParseFile(fileName, sourceText, options, ?cache, ?userOpName: string) =
14151416
let cache = defaultArg cache true
14161417
let userOpName = defaultArg userOpName "Unknown"
1417-
backgroundCompiler.ParseFile(fileName, sourceText, options, cache, userOpName)
1418+
backgroundCompiler.ParseFile(fileName, sourceText, options, cache, false, userOpName)
14181419

14191420
member ic.ParseFileInProject(fileName, source: string, options, ?cache: bool, ?userOpName: string) =
14201421
let parsingOptions, _ = ic.GetParsingOptionsFromProjectOptions(options)
@@ -1650,7 +1651,7 @@ type FSharpChecker
16501651
member _.GetParsingOptionsFromCommandLineArgs(sourceFiles, argv, ?isInteractive, ?isEditing) =
16511652
let isEditing = defaultArg isEditing false
16521653
let isInteractive = defaultArg isInteractive false
1653-
use errorScope = new DiagnosticsScope()
1654+
use errorScope = new DiagnosticsScope (argv |> List.contains "--flaterrors")
16541655

16551656
let tcConfigB =
16561657
TcConfigBuilder.CreateNew(

0 commit comments

Comments
 (0)