Skip to content

Commit

Permalink
Upgrade to JsonRpc.Standard 0.3.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
CXuesong committed May 27, 2017
1 parent 86ad2aa commit 68f6b1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
4 changes: 2 additions & 2 deletions DemoLanguageServer/DemoLanguageServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CXuesong.JsonRpc.Dataflow" Version="0.3.0" />
<PackageReference Include="CXuesong.JsonRpc.Standard" Version="0.3.0" />
<PackageReference Include="CXuesong.JsonRpc.Standard" Version="0.3.1" />
<PackageReference Include="CXuesong.JsonRpc.Streams" Version="0.3.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.3.0" />
Expand Down
51 changes: 21 additions & 30 deletions DemoLanguageServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//#define WAIT_FOR_DEBUGGER
//#define USE_CONSOLE_READER

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using JsonRpc.Dataflow;
using JsonRpc.Standard.Client;
using JsonRpc.Standard.Contracts;
using JsonRpc.Standard.Server;
using JsonRpc.Streams;
using LanguageServer.VsCode;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Debug;
Expand All @@ -33,53 +32,50 @@ static void Main(string[] args)
logWriter.AutoFlush = true;
}
using (logWriter)
#if !USE_CONSOLE_READER
using (var cin = Console.OpenStandardInput())
using (var bcin = new BufferedStream(cin))
#endif
using (var cout = Console.OpenStandardOutput())
using (var reader = new PartwiseStreamMessageReader(bcin))
using (var writer = new PartwiseStreamMessageWriter(cout))
{
var contractResolver = new JsonRpcContractResolver
{
NamingStrategy = new CamelCaseJsonRpcNamingStrategy(),
ParameterValueConverter = new CamelCaseJsonValueConverter(),
};
var client = new JsonRpcClient();
var clientHandler = new StreamRpcClientHandler();
var client = new JsonRpcClient(clientHandler);
if (debugMode)
{
client.MessageSending += (_, e) =>
// We want to capture log all the LSP server-to-client calls as well
clientHandler.MessageSending += (_, e) =>
{
lock (logWriter) logWriter.WriteLine("<C{0}", e.Message);
};
client.MessageReceiving += (_, e) =>
clientHandler.MessageReceiving += (_, e) =>
{
lock (logWriter) logWriter.WriteLine(">C{0}", e.Message);
};
}
// Configure & build service host
var session = new LanguageServerSession(client, contractResolver);
var host = BuildServiceHost(session, logWriter, contractResolver, debugMode);
// Connect the datablocks
var target = new PartwiseStreamMessageTargetBlock(cout);
#if USE_CONSOLE_READER

var source = new ByLineTextMessageSourceBlock(Console.In);
#else
var source = new PartwiseStreamMessageSourceBlock(bcin);
#endif
using (host.Attach(source, target))
// We want to capture log all the server-to-client calls as well
using (client.Attach(source, target))
// If we want server to stop, just stop the "source"
using (session.CancellationToken.Register(() => source.Complete()))
var host = BuildServiceHost(logWriter, contractResolver, debugMode);
var serverHandler = new StreamRpcServerHandler(host,
StreamRpcServerHandlerOptions.ConsistentResponseSequence |
StreamRpcServerHandlerOptions.SupportsRequestCancellation);
serverHandler.DefaultFeatures.Set(session);
// If we want server to stop, just stop the "source"
using (serverHandler.Attach(reader, writer))
using (clientHandler.Attach(reader, writer))
{
// Wait for the "stop" request.
session.CancellationToken.WaitHandle.WaitOne();
}
logWriter.WriteLine("Exited");
logWriter?.WriteLine("Exited");
}
}

private static DataflowRpcServiceHost BuildServiceHost(LanguageServerSession session, TextWriter logWriter,
private static IJsonRpcServiceHost BuildServiceHost(TextWriter logWriter,
IJsonRpcContractResolver contractResolver, bool debugMode)
{
var loggerFactory = new LoggerFactory();
Expand All @@ -101,13 +97,8 @@ private static DataflowRpcServiceHost BuildServiceHost(LanguageServerSession ses
lock (logWriter) logWriter.WriteLine("< {0}", context.Response);
});
}
var host = builder.Build();
var features = new FeatureCollection();
features.Set(session);
return new DataflowRpcServiceHost(host, features,
DataflowRpcServiceHostOptions.ConsistentResponseSequence |
DataflowRpcServiceHostOptions.SupportsRequestCancellation);
return builder.Build();
}

}
}
2 changes: 1 addition & 1 deletion LanguageServer.VsCode/LanguageServer.VsCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CXuesong.JsonRpc.Standard" Version="0.3.0" />
<PackageReference Include="CXuesong.JsonRpc.Standard" Version="0.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
</ItemGroup>

Expand Down

0 comments on commit 68f6b1f

Please sign in to comment.