-
Notifications
You must be signed in to change notification settings - Fork 417
/
Copy pathDiagnosticEventForwarder.cs
59 lines (52 loc) · 2.23 KB
/
DiagnosticEventForwarder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Composition;
using OmniSharp.Eventing;
using OmniSharp.Models.Diagnostics;
using OmniSharp.Models.Events;
namespace OmniSharp.Roslyn
{
[Export, Shared]
public class DiagnosticEventForwarder
{
private readonly IEventEmitter _emitter;
[ImportingConstructor]
public DiagnosticEventForwarder(IEventEmitter emitter)
{
_emitter = emitter;
}
public bool IsEnabled { get; set; }
public void Forward(DiagnosticMessage message)
{
_emitter.Emit(EventTypes.Diagnostic, message);
}
public void BackgroundDiagnosticsStatus(BackgroundDiagnosticStatus status, int numberProjects, int numberFiles, int numberFilesRemaining)
{
// New type of background diagnostic event, allows more control of visualization in clients:
_emitter.Emit(EventTypes.BackgroundDiagnosticStatus, new BackgroundDiagnosticStatusMessage
{
Status = status,
NumberProjects = numberProjects,
NumberFilesTotal = numberFiles,
NumberFilesRemaining = numberFilesRemaining
});
// Old type of event emitted as a shim for older clients:
double percentComplete = 0;
if (numberFiles > 0 && numberFiles > numberFilesRemaining)
{
percentComplete = numberFiles <= 0
? 100
: (numberFiles - numberFilesRemaining) / (double)numberFiles;
}
_emitter.Emit(EventTypes.ProjectDiagnosticStatus, new ProjectDiagnosticStatusMessage
{
// There is no current project file being analyzed anymore since all the analysis
// executes concurrently, but we have to supply some value for the ProjectFilePath
// property for clients that only know about this event. In VS Code the following
// displays nicely as "Analyzing (24%)".
ProjectFilePath = $"({percentComplete:P0})",
Status = status == BackgroundDiagnosticStatus.Finished ?
ProjectDiagnosticStatus.Ready :
ProjectDiagnosticStatus.Started
});
}
}
}