Skip to content

Commit

Permalink
Merge pull request #59 from OmniSharp/fix/52
Browse files Browse the repository at this point in the history
Fixes #52
  • Loading branch information
david-driscoll authored Jan 10, 2018
2 parents c990609 + 88d900e commit 1158fd8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sample/SampleServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static async Task MainAsync(string[] args)
server.AddHandler(new TextDocumentHandler(server));

await server.Initialize();
await server.WasShutDown;
await server.WaitForExit;
}
}
}
9 changes: 6 additions & 3 deletions src/Server/Abstractions/IAwaitableTermination.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace OmniSharp.Extensions.LanguageServer.Server.Abstractions
using System.Threading.Tasks;

namespace OmniSharp.Extensions.LanguageServer.Server.Abstractions
{
public interface IAwaitableTermination
{
System.Threading.Tasks.Task WasShutDown { get; }
Task WasShutDown { get; }
Task WaitForExit { get; }
}
}
}
9 changes: 8 additions & 1 deletion src/Server/Handlers/ExitHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Server.Abstractions;

namespace OmniSharp.Extensions.LanguageServer.Server.Handlers
{
Expand All @@ -12,9 +13,15 @@ public ExitHandler(ShutdownHandler shutdownHandler)
_shutdownHandler = shutdownHandler;
}

private readonly TaskCompletionSource<int> _exitedSource = new TaskCompletionSource<int>(TaskContinuationOptions.LongRunning);
public Task WaitForExit => _exitedSource.Task;


public Task Handle()
{
Exit?.Invoke(_shutdownHandler.ShutdownRequested ? 0 : 1);
var result = _shutdownHandler.ShutdownRequested ? 0 : 1;
Exit?.Invoke(result);
_exitedSource.SetResult(result);
return Task.CompletedTask;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Server/Handlers/ShutdownHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace OmniSharp.Extensions.LanguageServer.Server.Handlers
{
public class ShutdownHandler : IShutdownHandler, IAwaitableTermination
public class ShutdownHandler : IShutdownHandler
{
public event ShutdownEventHandler Shutdown;

public bool ShutdownRequested { get; private set; }

private readonly TaskCompletionSource<bool> _shutdownSource = new TaskCompletionSource<bool>(TaskContinuationOptions.LongRunning);
Task IAwaitableTermination.WasShutDown => _shutdownSource.Task;
public Task WasShutDown => _shutdownSource.Task;
public Task Handle(object request, CancellationToken token)
{
ShutdownRequested = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ public TaskCompletionSource<JToken> GetRequest(long id)
return _responseRouter.GetRequest(id);
}

public Task WasShutDown => ((IAwaitableTermination)_shutdownHandler).WasShutDown;
public Task WasShutDown => _shutdownHandler.WasShutDown;
public Task WaitForExit => _exitHandler.WaitForExit;

public void Dispose()
{
Expand Down

0 comments on commit 1158fd8

Please sign in to comment.