-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathProgram.cs
82 lines (70 loc) · 2.55 KB
/
Program.cs
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
73
74
75
76
77
78
79
80
81
82
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.LanguageServer;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Extensions.LanguageServer.Server;
using Serilog;
namespace SampleServer
{
class Program
{
static void Main(string[] args)
{
MainAsync(args).Wait();
}
static async Task MainAsync(string[] args)
{
//Debugger.Launch();
//while (!System.Diagnostics.Debugger.IsAttached)
//{
// await Task.Delay(100);
//}
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Logger.Information("This only goes file...");
var server = await LanguageServer.From(options =>
options
.WithInput(Console.OpenStandardInput())
.WithOutput(Console.OpenStandardOutput())
.ConfigureLogging(x => x
.AddSerilog()
.AddLanguageServer()
.SetMinimumLevel(LogLevel.Debug))
.WithHandler<TextDocumentHandler>()
.WithHandler<DidChangeWatchedFilesHandler>()
.WithHandler<FoldingRangeHandler>()
.WithServices(services => {
services.AddSingleton<Foo>(provider => {
var loggerFactory = provider.GetService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger<Foo>();
logger.LogInformation("Configuring");
return new Foo(logger);
});
}).OnInitialize((s, request) => {
var serviceProvider = s.Services;
var foo = serviceProvider.GetService<Foo>();
return Task.CompletedTask;
})
);
await server.WaitForExit;
}
}
internal class Foo
{
private readonly ILogger<Foo> _logger;
public Foo(ILogger<Foo> logger)
{
logger.LogInformation("inside ctor");
_logger = logger;
}
public void SayFoo()
{
_logger.LogInformation("Fooooo!");
}
}
}