-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (64 loc) · 2.76 KB
/
Program.cs
File metadata and controls
72 lines (64 loc) · 2.76 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Microsoft.Extensions.DependencyInjection; // <-- indispensable pour AddSingleton
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Extensions.LanguageServer.Server;
using Serilog;
using Serilog.Debugging;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
namespace XSharpLanguageServer
{
class Program
{
static async Task Main(string[] args)
{
//var exeInfo = new FileInfo(Assembly.GetEntryAssembly().Location);
//var exePath = Path.GetDirectoryName(exeInfo.FullName);
//var logPath = args.Length > 0 ? args[0] : AppContext.BaseDirectory;
var logPath = Environment.GetEnvironmentVariable("XSHARPLSP_LOG_PATH");
if (!string.IsNullOrEmpty(logPath))
{
var logFile = Path.Combine(logPath, "XSharpLSPServer.log");
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.File(logFile, rollingInterval: RollingInterval.Day)
.WriteTo.Debug()
.CreateLogger();
Log.Information("Starting XSharp Language Server, log file : {LogFile}", logFile);
}
else
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Debug()
.CreateLogger();
Log.Information("Starting XSharp Language Server");
}
var server = await LanguageServer.From(options =>
options.WithInput(Console.OpenStandardInput())
.WithOutput(Console.OpenStandardOutput())
// Shared Services via Dependency Injection
.WithServices(services =>
{
// Shared buffer
services.AddSingleton<IDictionary<DocumentUri, string>>(
sp => new Dictionary<DocumentUri, string>());
services.AddLogging(builder =>
{
builder.ClearProviders();
builder.AddSerilog(Log.Logger, dispose: true);
});
})
// Register Handlers, resolved by DI
.WithHandler<XSharpSemanticTokensHandler>()
.WithHandler<XSharpTextDocumentSyncHandler>()
);
await server.WaitForExit;
}
}
}