|
24 | 24 |
|
25 | 25 | namespace OmniSharp.Extensions.LanguageServer.Server
|
26 | 26 | {
|
27 |
| - public class LanguageServerOptions |
28 |
| - { |
29 |
| - public LanguageServerOptions() |
30 |
| - { |
31 |
| - } |
32 |
| - |
33 |
| - public Stream Input { get; set; } |
34 |
| - public Stream Output { get; set; } |
35 |
| - public ILoggerFactory LoggerFactory { get; set; } |
36 |
| - public ISerializer Serializer { get; set; } |
37 |
| - public IHandlerCollection Handlers { get; set; } = new HandlerCollection(); |
38 |
| - public IRequestProcessIdentifier RequestProcessIdentifier { get; set; } |
39 |
| - public ILspReciever Reciever { get; set; } = new LspReciever(); |
40 |
| - public IServiceCollection Services { get; set; } = new ServiceCollection(); |
41 |
| - internal List<Type> HandlerTypes { get; set; } = new List<Type>(); |
42 |
| - internal List<Assembly> HandlerAssemblies { get; set; } = new List<Assembly>(); |
43 |
| - internal bool AddDefaultLoggingProvider { get; set; } |
44 |
| - } |
45 |
| - |
46 |
| - public static class LanguageServerOptionsExtensions |
47 |
| - { |
48 |
| - public static LanguageServerOptions WithInput(this LanguageServerOptions options, Stream input) |
49 |
| - { |
50 |
| - options.Input = input; |
51 |
| - return options; |
52 |
| - } |
53 |
| - |
54 |
| - public static LanguageServerOptions WithOutput(this LanguageServerOptions options, Stream output) |
55 |
| - { |
56 |
| - options.Output = output; |
57 |
| - return options; |
58 |
| - } |
59 |
| - |
60 |
| - public static LanguageServerOptions WithLoggerFactory(this LanguageServerOptions options, ILoggerFactory loggerFactory) |
61 |
| - { |
62 |
| - options.LoggerFactory = loggerFactory; |
63 |
| - return options; |
64 |
| - } |
65 |
| - |
66 |
| - public static LanguageServerOptions WithRequestProcessIdentifier(this LanguageServerOptions options, IRequestProcessIdentifier requestProcessIdentifier) |
67 |
| - { |
68 |
| - options.RequestProcessIdentifier = requestProcessIdentifier; |
69 |
| - return options; |
70 |
| - } |
71 |
| - |
72 |
| - public static LanguageServerOptions WithSerializer(this LanguageServerOptions options, ISerializer serializer) |
73 |
| - { |
74 |
| - options.Serializer = serializer; |
75 |
| - return options; |
76 |
| - } |
77 |
| - |
78 |
| - public static LanguageServerOptions WithReciever(this LanguageServerOptions options, ILspReciever reciever) |
79 |
| - { |
80 |
| - options.Reciever = reciever; |
81 |
| - return options; |
82 |
| - } |
83 |
| - |
84 |
| - public static LanguageServerOptions AddHandler<T>(this LanguageServerOptions options) |
85 |
| - where T : class, IJsonRpcHandler |
86 |
| - { |
87 |
| - options.Services.AddSingleton<IJsonRpcHandler, T>(); |
88 |
| - return options; |
89 |
| - } |
90 |
| - |
91 |
| - public static LanguageServerOptions AddHandler<T>(this LanguageServerOptions options, T handler) |
92 |
| - where T : IJsonRpcHandler |
93 |
| - { |
94 |
| - options.Services.AddSingleton<IJsonRpcHandler>(handler); |
95 |
| - return options; |
96 |
| - } |
97 |
| - |
98 |
| - public static LanguageServerOptions AddHandlers(this LanguageServerOptions options, Type type) |
99 |
| - { |
100 |
| - options.HandlerTypes.Add(type); |
101 |
| - return options; |
102 |
| - } |
103 |
| - |
104 |
| - public static LanguageServerOptions AddHandlers(this LanguageServerOptions options, TypeInfo typeInfo) |
105 |
| - { |
106 |
| - options.HandlerTypes.Add(typeInfo.AsType()); |
107 |
| - return options; |
108 |
| - } |
109 |
| - |
110 |
| - public static LanguageServerOptions AddHandlers(this LanguageServerOptions options, Assembly assembly) |
111 |
| - { |
112 |
| - options.HandlerAssemblies.Add(assembly); |
113 |
| - return options; |
114 |
| - } |
115 |
| - |
116 |
| - public static LanguageServerOptions AddDefaultLoggingProvider(this LanguageServerOptions options) |
117 |
| - { |
118 |
| - options.AddDefaultLoggingProvider = true; |
119 |
| - return options; |
120 |
| - } |
121 |
| - } |
122 |
| - |
123 |
| - public class LanguageServer : ILanguageServer, IInitializeHandler, IInitializedHandler, IDisposable, IAwaitableTermination |
| 27 | + public class LanguageServer : ILanguageServer, IInitializeHandler, IInitializedHandler, IAwaitableTermination |
124 | 28 | {
|
125 | 29 | private readonly Connection _connection;
|
126 | 30 | private readonly ILspRequestRouter _requestRouter;
|
@@ -372,42 +276,28 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
|
372 | 276 | };
|
373 | 277 | }
|
374 | 278 |
|
375 |
| - var textSyncHandlers = _collection |
376 |
| - .Select(x => x.Handler) |
377 |
| - .OfType<ITextDocumentSyncHandler>() |
378 |
| - .ToArray(); |
| 279 | + var textDocumentSyncKind = _collection.ContainsHandler(typeof(IDidChangeTextDocumentHandler)) |
| 280 | + ? _collection |
| 281 | + .OfType<IDidChangeTextDocumentHandler>() |
| 282 | + .Where(x => x.Change != TextDocumentSyncKind.None) |
| 283 | + .Min(z => z.Change) |
| 284 | + : TextDocumentSyncKind.None; |
379 | 285 |
|
380 | 286 | if (_clientVersion == ClientVersion.Lsp2)
|
381 | 287 | {
|
382 |
| - if (textSyncHandlers.Any()) |
383 |
| - { |
384 |
| - serverCapabilities.TextDocumentSync = textSyncHandlers |
385 |
| - .Where(x => x.Options.Change != TextDocumentSyncKind.None) |
386 |
| - .Min<ITextDocumentSyncHandler, TextDocumentSyncKind>(z => z.Options.Change); |
387 |
| - } |
388 |
| - else |
389 |
| - { |
390 |
| - serverCapabilities.TextDocumentSync = TextDocumentSyncKind.None; |
391 |
| - } |
| 288 | + serverCapabilities.TextDocumentSync = textDocumentSyncKind; |
392 | 289 | }
|
393 | 290 | else
|
394 | 291 | {
|
395 |
| - if (ccp.HasStaticHandler(textDocumentCapabilities.Synchronization)) |
396 |
| - { |
397 |
| - // TODO: Merge options |
398 |
| - serverCapabilities.TextDocumentSync = |
399 |
| - textSyncHandlers.FirstOrDefault()?.Options ?? new TextDocumentSyncOptions() { |
400 |
| - Change = TextDocumentSyncKind.None, |
401 |
| - OpenClose = false, |
402 |
| - Save = new SaveOptions() { IncludeText = false }, |
403 |
| - WillSave = false, |
404 |
| - WillSaveWaitUntil = false |
405 |
| - }; |
406 |
| - } |
407 |
| - else |
408 |
| - { |
409 |
| - serverCapabilities.TextDocumentSync = TextDocumentSyncKind.None; |
410 |
| - } |
| 292 | + serverCapabilities.TextDocumentSync = new TextDocumentSyncOptions() { |
| 293 | + Change = textDocumentSyncKind, |
| 294 | + OpenClose = _collection.ContainsHandler(typeof(IDidOpenTextDocumentHandler)) || _collection.ContainsHandler(typeof(IDidCloseTextDocumentHandler)), |
| 295 | + Save = _collection.ContainsHandler(typeof(IDidSaveTextDocumentHandler)) ? |
| 296 | + new SaveOptions() { IncludeText = true /* TODO: Make configurable */ } : |
| 297 | + null, |
| 298 | + WillSave = _collection.ContainsHandler(typeof(IWillSaveTextDocumentHandler)), |
| 299 | + WillSaveWaitUntil = _collection.ContainsHandler(typeof(IWillSaveWaitUntilTextDocumentHandler)) |
| 300 | + }; |
411 | 301 | }
|
412 | 302 |
|
413 | 303 | _reciever.Initialized();
|
|
0 commit comments