-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (42 loc) · 1.8 KB
/
Copy pathProgram.cs
File metadata and controls
47 lines (42 loc) · 1.8 KB
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
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Heddle.LanguageServer.Protocol;
using StreamJsonRpc;
namespace Heddle.LanguageServer
{
/// <summary>
/// The <c>heddle-lsp</c> entry point (phase 6 D6): stdio, header-delimited, source-generated STJ over
/// StreamJsonRpc. <c>--version</c> prints the informational version and exits 0.
/// </summary>
internal static class Program
{
internal static async Task<int> Main(string[] args)
{
if (args.Length > 0 && (args[0] == "--version" || args[0] == "-v"))
{
Console.Out.WriteLine(LspServer.InformationalVersion);
return 0;
}
var server = new LspServer();
var formatter = new SystemTextJsonFormatter();
ConfigureFormatter(formatter);
var handler = new HeaderDelimitedMessageHandler(
Console.OpenStandardOutput(), Console.OpenStandardInput(), formatter);
var rpc = new JsonRpc(handler);
server.Attach(rpc);
rpc.AddLocalRpcTarget(server, new JsonRpcTargetOptions { AllowNonPublicInvocation = false });
rpc.StartListening();
var exitCode = await server.ExitCode.ConfigureAwait(false);
return exitCode;
}
internal static void ConfigureFormatter(SystemTextJsonFormatter formatter)
{
formatter.JsonSerializerOptions.TypeInfoResolver = LspJsonContext.Default;
formatter.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
formatter.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
formatter.JsonSerializerOptions.AllowDuplicateProperties = false;
}
}
}