-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathProgram.cs
More file actions
201 lines (177 loc) · 8.44 KB
/
Copy pathProgram.cs
File metadata and controls
201 lines (177 loc) · 8.44 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Server;
using Serilog;
// ReSharper disable UnusedParameter.Local
namespace SampleServer
{
internal class Program
{
private static void Main(string[] args)
{
MainAsync(args).Wait();
}
private static async Task MainAsync(string[] args)
{
// Debugger.Launch();
// while (!Debugger.IsAttached)
// {
// await Task.Delay(100);
// }
// Parse command line arguments
string solutionPath = null;
for (int i = 0; i < args.Length; i++)
{
if ((args[i] == "-s" || args[i] == "--solution") && i + 1 < args.Length)
{
solutionPath = args[i + 1];
break;
}
}
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
.MinimumLevel.Verbose()
.CreateLogger();
Log.Logger.Information("Starting language server with solution: {SolutionPath}", solutionPath ?? "none");
IObserver<WorkDoneProgressReport> workDone = null!;
var server = await LanguageServer.From(
options =>
options
.WithInput(Console.OpenStandardInput())
.WithOutput(Console.OpenStandardOutput())
.ConfigureLogging(
x => x
.AddSerilog(Log.Logger)
.AddLanguageProtocolLogging()
.SetMinimumLevel(LogLevel.Debug)
)
.WithHandler<TextDocumentHandler>()
.WithHandler<DidChangeWatchedFilesHandler>()
.WithHandler<FoldingRangeHandler>()
.WithHandler<MyWorkspaceSymbolsHandler>()
.WithHandler<MyDocumentSymbolHandler>()
.WithHandler<SemanticTokensHandler>()
.WithServices(x => x.AddLogging(b => b.SetMinimumLevel(LogLevel.Trace)))
.WithServices(
services =>
{
services.AddSingleton(
provider =>
{
var loggerFactory = provider.GetService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger<Foo>();
logger.LogInformation("Configuring");
return new Foo(logger);
}
);
services.AddSingleton(
new ConfigurationItem
{
Section = "typescript",
}
).AddSingleton(
new ConfigurationItem
{
Section = "terminal",
}
);
}
)
.OnInitialize(
async (server, request, token) =>
{
var manager = server.WorkDoneManager.For(
request, new WorkDoneProgressBegin
{
Title = "Server is starting...",
Percentage = 10,
}
);
workDone = manager;
await Task.Delay(2000).ConfigureAwait(false);
manager.OnNext(
new WorkDoneProgressReport
{
Percentage = 20,
Message = "loading in progress"
}
);
}
)
.OnInitialized(
async (server, request, response, token) =>
{
workDone.OnNext(
new WorkDoneProgressReport
{
Percentage = 40,
Message = "loading almost done",
}
);
await Task.Delay(2000).ConfigureAwait(false);
workDone.OnNext(
new WorkDoneProgressReport
{
Message = "loading done",
Percentage = 100,
}
);
workDone.OnCompleted();
}
)
.OnStarted(
async (languageServer, token) =>
{
using var manager = await languageServer.WorkDoneManager.Create(new WorkDoneProgressBegin { Title = "Doing some work..." })
.ConfigureAwait(false);
manager.OnNext(new WorkDoneProgressReport { Message = "doing things..." });
await Task.Delay(10000).ConfigureAwait(false);
manager.OnNext(new WorkDoneProgressReport { Message = "doing things... 1234" });
await Task.Delay(10000).ConfigureAwait(false);
manager.OnNext(new WorkDoneProgressReport { Message = "doing things... 56789" });
var logger = languageServer.Services.GetService<ILogger<Foo>>();
var configuration = await languageServer.Configuration.GetConfiguration(
new ConfigurationItem
{
Section = "typescript",
}, new ConfigurationItem
{
Section = "terminal",
}
).ConfigureAwait(false);
var baseConfig = new JObject();
foreach (var config in languageServer.Configuration.AsEnumerable())
{
baseConfig.Add(config.Key, config.Value);
}
logger.LogInformation("Base Config: {@Config}", baseConfig);
var scopedConfig = new JObject();
foreach (var config in configuration.AsEnumerable())
{
scopedConfig.Add(config.Key, config.Value);
}
logger.LogInformation("Scoped Config: {@Config}", scopedConfig);
}
)
).ConfigureAwait(false);
await server.WaitForExit.ConfigureAwait(false);
}
}
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!");
}
}
}