Skip to content

Commit

Permalink
Merge pull request #574 from OmniSharp/streaming-diagnostics-2
Browse files Browse the repository at this point in the history
Streaming diagnostics
  • Loading branch information
david-driscoll committed Jun 5, 2016
2 parents e93897e + b65f410 commit 1e55d31
Show file tree
Hide file tree
Showing 18 changed files with 642 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/OmniSharp.Abstractions/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ public static class OmnisharpEndpoints
public const string CheckReadyStatus = "/checkreadystatus";
public const string StopServer = "/stopserver";

public const string Open = "/open";
public const string Close = "/close";
public const string Diagnostics = "/diagnostics";

public static class V2
{
public const string GetCodeActions = "/v2/getcodeactions";
public const string RunCodeAction = "/v2/runcodeaction";
}

public const string GetTestStartInfo = "/v2/getteststartinfo";

public const string RunDotNetTest = "/v2/runtest";
}
}
9 changes: 9 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/DiagnosticMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace OmniSharp.Models
{
public class DiagnosticMessage
{
public IEnumerable<DiagnosticResult> Results { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/DiagnosticResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OmniSharp.Models
{
public class DiagnosticResult
{
public string FileName { get; set; }
public IEnumerable<DiagnosticLocation> QuickFixes { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/DiagnosticsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.Diagnostics, typeof(DiagnosticsRequest), typeof(DiagnosticsResponse))]
public class DiagnosticsRequest : Request
{
}

public class DiagnosticsResponse : IAggregateResponse
{
public IAggregateResponse Merge(IAggregateResponse response) { return response; }
}
}
17 changes: 9 additions & 8 deletions src/OmniSharp.Abstractions/Models/v1/EventTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ namespace OmniSharp.Models
{
public static class EventTypes
{
public static readonly string ProjectAdded = "ProjectAdded";
public static readonly string ProjectChanged = "ProjectChanged";
public static readonly string ProjectRemoved = "ProjectRemoved";
public static readonly string Error = "Error";
public static readonly string MsBuildProjectDiagnostics = "MsBuildProjectDiagnostics";
public static readonly string PackageRestoreStarted = "PackageRestoreStarted";
public static readonly string PackageRestoreFinished = "PackageRestoreFinished";
public static readonly string UnresolvedDependencies = "UnresolvedDependencies";
public static readonly string ProjectAdded = nameof(ProjectAdded);
public static readonly string ProjectChanged = nameof(ProjectChanged);
public static readonly string ProjectRemoved = nameof(ProjectRemoved);
public static readonly string Error = nameof(Error);
public static readonly string Diagnostic = nameof(Diagnostic);
public static readonly string MsBuildProjectDiagnostics = nameof(MsBuildProjectDiagnostics);
public static readonly string PackageRestoreStarted = nameof(PackageRestoreStarted);
public static readonly string PackageRestoreFinished = nameof(PackageRestoreFinished);
public static readonly string UnresolvedDependencies = nameof(UnresolvedDependencies);
}
}
11 changes: 11 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/FileCloseRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.Close, typeof(FileCloseRequest), typeof(FileCloseResponse))]
public class FileCloseRequest : Request { }
}
12 changes: 12 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/FileCloseResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OmniSharp.Models
{
public class FileCloseResponse : IAggregateResponse
{
public IAggregateResponse Merge(IAggregateResponse response) { return response; }
}
}
11 changes: 11 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/FileOpenRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Mef;

namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.Open, typeof(FileOpenRequest), typeof(FileOpenResponse))]
public class FileOpenRequest : Request { }
}
12 changes: 12 additions & 0 deletions src/OmniSharp.Abstractions/Models/v1/FileOpenResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OmniSharp.Models
{
public class FileOpenResponse : IAggregateResponse
{
public IAggregateResponse Merge(IAggregateResponse response) { return response; }
}
}
2 changes: 1 addition & 1 deletion src/OmniSharp.Abstractions/Models/v1/FindSymbolsRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OmniSharp.Mef;

namespace OmniSharp.Models
namespace OmniSharp.Models
{
[OmniSharpEndpoint(OmnisharpEndpoints.FindSymbols, typeof(FindSymbolsRequest), typeof(QuickFixResponse))]
public class FindSymbolsRequest : IRequest
Expand Down
31 changes: 31 additions & 0 deletions src/OmniSharp.Abstractions/Services/DiagnosticEventForwarder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Models;
using OmniSharp.Models.V2;
using OmniSharp.Services;

namespace OmniSharp.Services
{
[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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using OmniSharp.Mef;
using OmniSharp.Models;
using OmniSharp.Services;
using OmniSharp.Workers.Diagnostics;

namespace OmniSharp.Roslyn.CSharp.Services.Diagnostics
{
[OmniSharpHandler(OmnisharpEndpoints.Diagnostics, LanguageNames.CSharp)]
public class DiagnosticsService : RequestHandler<DiagnosticsRequest, DiagnosticsResponse>
{
private readonly CSharpDiagnosticService _diagnostics;
private readonly DiagnosticEventForwarder _forwarder;
private readonly OmnisharpWorkspace _workspace;

[ImportingConstructor]
public DiagnosticsService(OmnisharpWorkspace workspace, DiagnosticEventForwarder forwarder, CSharpDiagnosticService diagnostics)
{
_forwarder = forwarder;
_workspace = workspace;
_diagnostics = diagnostics;
}

public Task<DiagnosticsResponse> Handle(DiagnosticsRequest request)
{
if (!_forwarder.IsEnabled)
{
_forwarder.IsEnabled = true;
}

var documents = request.FileName != null
? new [] { request.FileName }
: _workspace.CurrentSolution.Projects.SelectMany(project => project.Documents.Select(x => x.FilePath));

_diagnostics.QueueDiagnostics(documents.ToArray());

return Task.FromResult(new DiagnosticsResponse());
}
}
}
33 changes: 33 additions & 0 deletions src/OmniSharp.Roslyn.CSharp/Services/Files/FileCloseService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using OmniSharp.Mef;
using OmniSharp.Models;

namespace OmniSharp.Roslyn.CSharp.Services.Files
{
[OmniSharpHandler(OmnisharpEndpoints.Close, LanguageNames.CSharp)]
public class FileCloseService : RequestHandler<FileCloseRequest, FileCloseResponse>
{
private readonly OmnisharpWorkspace _workspace;

[ImportingConstructor]
public FileCloseService(OmnisharpWorkspace workspace)
{
_workspace = workspace;
}

public Task<FileCloseResponse> Handle(FileCloseRequest request)
{
var documents = _workspace.GetDocuments(request.FileName);
foreach (var document in documents)
{
_workspace.CloseDocument(document.Id);
}
return Task.FromResult(new FileCloseResponse());
}
}
}
33 changes: 33 additions & 0 deletions src/OmniSharp.Roslyn.CSharp/Services/Files/FileOpenService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using OmniSharp.Mef;
using OmniSharp.Models;

namespace OmniSharp.Roslyn.CSharp.Services.Files
{
[OmniSharpHandler(OmnisharpEndpoints.Open, LanguageNames.CSharp)]
public class FileOpenService : RequestHandler<FileOpenRequest, FileOpenResponse>
{
private readonly OmnisharpWorkspace _workspace;

[ImportingConstructor]
public FileOpenService(OmnisharpWorkspace workspace)
{
_workspace = workspace;
}

public Task<FileOpenResponse> Handle(FileOpenRequest request)
{
var documents = _workspace.GetDocuments(request.FileName);
foreach (var document in documents)
{
_workspace.OpenDocument(document.Id, false);
}
return Task.FromResult(new FileOpenResponse());
}
}
}
Loading

0 comments on commit 1e55d31

Please sign in to comment.