Skip to content

Commit 5619bfa

Browse files
LSP
1 parent fae7af9 commit 5619bfa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+296
-385
lines changed

src/Client/LanguageClient.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using OmniSharp.Extensions.LanguageServer.Protocol.Shared;
2525
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
2626
using OmniSharp.Extensions.LanguageServer.Shared;
27+
// ReSharper disable SuspiciousTypeConversion.Global
2728

2829
namespace OmniSharp.Extensions.LanguageServer.Client
2930
{
@@ -51,50 +52,50 @@ public class LanguageClient : JsonRpcServerBase, ILanguageClient
5152

5253
// private readonly ILanguageClientConfiguration _configuration;
5354
private readonly IEnumerable<ICapability> _capabilities;
54-
private readonly object _initializationOptions;
55-
private readonly DocumentUri _rootUri;
55+
private readonly object? _initializationOptions;
56+
private readonly DocumentUri? _rootUri;
5657
private readonly InitializeTrace _trace;
5758
private readonly ClientCapabilities _clientCapabilities;
5859
private readonly LanguageProtocolSettingsBag _settingsBag;
5960
private bool _started;
6061
private readonly int? _concurrency;
6162

62-
internal static IContainer CreateContainer(LanguageClientOptions options, IServiceProvider outerServiceProvider) =>
63+
internal static IContainer CreateContainer(LanguageClientOptions options, IServiceProvider? outerServiceProvider) =>
6364
JsonRpcServerContainer.Create(outerServiceProvider)
6465
.AddLanguageClientInternals(options, outerServiceProvider);
6566

6667
public static LanguageClient Create(LanguageClientOptions options) => Create(options, null);
6768
public static LanguageClient Create(Action<LanguageClientOptions> optionsAction) => Create(optionsAction, null);
6869

69-
public static LanguageClient Create(Action<LanguageClientOptions> optionsAction, IServiceProvider outerServiceProvider)
70+
public static LanguageClient Create(Action<LanguageClientOptions> optionsAction, IServiceProvider? outerServiceProvider)
7071
{
7172
var options = new LanguageClientOptions();
7273
optionsAction(options);
7374
return Create(options, outerServiceProvider);
7475
}
7576

76-
public static LanguageClient Create(LanguageClientOptions options, IServiceProvider outerServiceProvider) =>
77+
public static LanguageClient Create(LanguageClientOptions options, IServiceProvider? outerServiceProvider) =>
7778
CreateContainer(options, outerServiceProvider).Resolve<LanguageClient>();
7879

7980
public static Task<LanguageClient> From(LanguageClientOptions options) => From(options, null, CancellationToken.None);
8081
public static Task<LanguageClient> From(Action<LanguageClientOptions> optionsAction) => From(optionsAction, null, CancellationToken.None);
8182
public static Task<LanguageClient> From(LanguageClientOptions options, CancellationToken cancellationToken) => From(options, null, cancellationToken);
8283
public static Task<LanguageClient> From(Action<LanguageClientOptions> optionsAction, CancellationToken cancellationToken) => From(optionsAction, null, cancellationToken);
8384

84-
public static Task<LanguageClient> From(LanguageClientOptions options, IServiceProvider outerServiceProvider) =>
85+
public static Task<LanguageClient> From(LanguageClientOptions options, IServiceProvider? outerServiceProvider) =>
8586
From(options, outerServiceProvider, CancellationToken.None);
8687

87-
public static Task<LanguageClient> From(Action<LanguageClientOptions> optionsAction, IServiceProvider outerServiceProvider) =>
88+
public static Task<LanguageClient> From(Action<LanguageClientOptions> optionsAction, IServiceProvider? outerServiceProvider) =>
8889
From(optionsAction, outerServiceProvider, CancellationToken.None);
8990

90-
public static Task<LanguageClient> From(Action<LanguageClientOptions> optionsAction, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
91+
public static Task<LanguageClient> From(Action<LanguageClientOptions> optionsAction, IServiceProvider? outerServiceProvider, CancellationToken cancellationToken)
9192
{
9293
var options = new LanguageClientOptions();
9394
optionsAction(options);
9495
return From(options, outerServiceProvider, cancellationToken);
9596
}
9697

97-
public static async Task<LanguageClient> From(LanguageClientOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
98+
public static async Task<LanguageClient> From(LanguageClientOptions options, IServiceProvider? outerServiceProvider, CancellationToken cancellationToken)
9899
{
99100
var server = Create(options, outerServiceProvider);
100101
await server.Initialize(cancellationToken);
@@ -212,10 +213,10 @@ public async Task Initialize(CancellationToken token)
212213
Trace = _trace,
213214
ClientInfo = _clientInfo,
214215
Capabilities = _clientCapabilities,
215-
RootUri = _rootUri,
216-
RootPath = _rootUri?.GetFileSystemPath(),
216+
RootUri = _rootUri!,
217+
RootPath = _rootUri?.GetFileSystemPath() ?? string.Empty,
217218
WorkspaceFolders = new Container<WorkspaceFolder>(WorkspaceFoldersManager.CurrentWorkspaceFolders),
218-
InitializationOptions = _initializationOptions
219+
InitializationOptions = _initializationOptions!
219220
};
220221

221222
var capabilitiesObject = new JObject();
@@ -367,11 +368,11 @@ public async Task Shutdown()
367368
_connection.Dispose();
368369
}
369370

370-
private Supports<T> UseOrTryAndFindCapability<T>(Supports<T> supports) where T : class
371+
private Supports<T> UseOrTryAndFindCapability<T>(Supports<T> supports) where T : class?
371372
{
372373
var value = supports.IsSupported
373374
? supports.Value
374-
: _capabilities.OfType<T>().FirstOrDefault();
375+
: _capabilities.OfType<T>().FirstOrDefault()!;
375376
if (value is IDynamicCapability dynamicCapability)
376377
{
377378
dynamicCapability.DynamicRegistration = _collection.ContainsHandler(typeof(IRegisterCapabilityHandler));
@@ -382,18 +383,17 @@ private Supports<T> UseOrTryAndFindCapability<T>(Supports<T> supports) where T :
382383

383384
public IObservable<InitializeResult> Start => _initializeComplete.AsObservable();
384385

385-
bool IResponseRouter.TryGetRequest(long id, [NotNullWhen(true)] out string method, [NotNullWhen(true)] out TaskCompletionSource<JToken> pendingTask) => _responseRouter.TryGetRequest(id, out method, out pendingTask);
386+
bool IResponseRouter.TryGetRequest(long id, [NotNullWhen(true)] out string method, [NotNullWhen(true)]out TaskCompletionSource<JToken> pendingTask) =>
387+
_responseRouter.TryGetRequest(id, out method, out pendingTask);
386388

387389
public Task<InitializeResult> WasStarted => _initializeComplete.ToTask();
388390

389391
public void Dispose()
390392
{
391-
_connection?.Dispose();
392-
_disposable?.Dispose();
393+
_connection.Dispose();
394+
_disposable.Dispose();
393395
}
394396

395-
public IDictionary<string, JToken> Experimental { get; } = new Dictionary<string, JToken>();
396-
397397
public IDisposable Register(Action<ILanguageClientRegistry> registryAction)
398398
{
399399
var manager = new CompositeHandlersManager(_collection);

src/Client/LanguageClientOptions.cs

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,118 +25,116 @@ public LanguageClientOptions()
2525
TextDocument = new TextDocumentClientCapabilities()
2626
};
2727

28-
public ClientInfo ClientInfo { get; set; }
29-
public DocumentUri RootUri { get; set; }
28+
public ClientInfo? ClientInfo { get; set; }
29+
public DocumentUri? RootUri { get; set; }
3030
public bool WorkspaceFolders { get; set; } = true;
3131
public bool DynamicRegistration { get; set; } = true;
3232
public bool ProgressTokens { get; set; } = true;
3333

3434
public string RootPath
3535
{
36-
get => RootUri.GetFileSystemPath();
36+
get => RootUri?.GetFileSystemPath() ?? string.Empty;
3737
set => RootUri = DocumentUri.FromFileSystemPath(value);
3838
}
3939

4040
public InitializeTrace Trace { get; set; }
4141

42-
public object InitializationOptions { get; set; }
42+
public object? InitializationOptions { get; set; }
4343

44-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, IJsonRpcHandler handler, JsonRpcHandlerOptions options) =>
44+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, IJsonRpcHandler handler, JsonRpcHandlerOptions? options) =>
4545
AddHandler(method, handler, options);
4646

47-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, JsonRpcHandlerFactory handlerFunc, JsonRpcHandlerOptions options) =>
47+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, JsonRpcHandlerFactory handlerFunc, JsonRpcHandlerOptions? options) =>
4848
AddHandler(method, handlerFunc, options);
4949

5050
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandlers(params IJsonRpcHandler[] handlers) => AddHandlers(handlers);
5151

52-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(JsonRpcHandlerFactory handlerFunc, JsonRpcHandlerOptions options) =>
52+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(JsonRpcHandlerFactory handlerFunc, JsonRpcHandlerOptions? options) =>
5353
AddHandler(handlerFunc, options);
5454

55-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(IJsonRpcHandler handler, JsonRpcHandlerOptions options) => AddHandler(handler, options);
55+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(IJsonRpcHandler handler, JsonRpcHandlerOptions? options) => AddHandler(handler, options);
5656

57-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler<TTHandler>(JsonRpcHandlerOptions options) => AddHandler<TTHandler>(options);
57+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler<TTHandler>(JsonRpcHandlerOptions? options) => AddHandler<TTHandler>(options);
5858

59-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler<TTHandler>(string method, JsonRpcHandlerOptions options) =>
59+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler<TTHandler>(string method, JsonRpcHandlerOptions? options) =>
6060
AddHandler<TTHandler>(method, options);
6161

62-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(Type type, JsonRpcHandlerOptions options) => AddHandler(type, options);
62+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(Type type, JsonRpcHandlerOptions? options) => AddHandler(type, options);
6363

64-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
64+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions? options) =>
6565
AddHandler(method, type, options);
6666

6767
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandlerLink(string fromMethod, string toMethod) =>
6868
AddHandlerLink(fromMethod, toMethod);
6969

70-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options) =>
70+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions? options) =>
7171
OnJsonRequest(method, handler, options);
7272

7373
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonRequest(
74-
string method, Func<JToken, CancellationToken, Task<JToken>> handler, JsonRpcHandlerOptions options
74+
string method, Func<JToken, CancellationToken, Task<JToken>> handler, JsonRpcHandlerOptions? options
7575
) => OnJsonRequest(method, handler, options);
7676

7777
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnRequest<TParams, TResponse>(
78-
string method, Func<TParams, Task<TResponse>> handler, JsonRpcHandlerOptions options
78+
string method, Func<TParams, Task<TResponse>> handler, JsonRpcHandlerOptions? options
7979
) => OnRequest(method, handler, options);
8080

8181
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnRequest<TParams, TResponse>(
82-
string method, Func<TParams, CancellationToken, Task<TResponse>> handler, JsonRpcHandlerOptions options
82+
string method, Func<TParams, CancellationToken, Task<TResponse>> handler, JsonRpcHandlerOptions? options
8383
) => OnRequest(method, handler, options);
8484

8585
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.
86-
OnRequest<TResponse>(string method, Func<Task<TResponse>> handler, JsonRpcHandlerOptions options) => OnRequest(method, handler, options);
86+
OnRequest<TResponse>(string method, Func<Task<TResponse>> handler, JsonRpcHandlerOptions? options) => OnRequest(method, handler, options);
8787

8888
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnRequest<TResponse>(
89-
string method, Func<CancellationToken, Task<TResponse>> handler, JsonRpcHandlerOptions options
89+
string method, Func<CancellationToken, Task<TResponse>> handler, JsonRpcHandlerOptions? options
9090
) => OnRequest(method, handler, options);
9191

92-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnRequest<TParams>(string method, Func<TParams, Task> handler, JsonRpcHandlerOptions options) =>
92+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnRequest<TParams>(string method, Func<TParams, Task> handler, JsonRpcHandlerOptions? options) =>
9393
OnRequest(method, handler, options);
9494

9595
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnRequest<TParams>(
96-
string method, Func<TParams, CancellationToken, Task> handler, JsonRpcHandlerOptions options
96+
string method, Func<TParams, CancellationToken, Task> handler, JsonRpcHandlerOptions? options
9797
) => OnRequest(method, handler, options);
9898

9999
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnRequest<TParams>(
100-
string method, Func<CancellationToken, Task> handler, JsonRpcHandlerOptions options
100+
string method, Func<CancellationToken, Task> handler, JsonRpcHandlerOptions? options
101101
) => OnRequest<TParams>(method, handler, options);
102102

103103
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification<TParams>(
104-
string method, Action<TParams, CancellationToken> handler, JsonRpcHandlerOptions options
104+
string method, Action<TParams, CancellationToken> handler, JsonRpcHandlerOptions? options
105105
) => OnNotification(method, handler, options);
106106

107-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonNotification(string method, Action<JToken> handler, JsonRpcHandlerOptions options) =>
107+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonNotification(string method, Action<JToken> handler, JsonRpcHandlerOptions? options) =>
108108
OnJsonNotification(method, handler, options);
109109

110110
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonNotification(
111-
string method, Func<JToken, CancellationToken, Task> handler, JsonRpcHandlerOptions options
111+
string method, Func<JToken, CancellationToken, Task> handler, JsonRpcHandlerOptions? options
112112
) => OnJsonNotification(method, handler, options);
113113

114-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonNotification(string method, Func<JToken, Task> handler, JsonRpcHandlerOptions options) =>
114+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonNotification(string method, Func<JToken, Task> handler, JsonRpcHandlerOptions? options) =>
115115
OnJsonNotification(method, handler, options);
116116

117117
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonNotification(
118-
string method, Action<JToken, CancellationToken> handler, JsonRpcHandlerOptions options
118+
string method, Action<JToken, CancellationToken> handler, JsonRpcHandlerOptions? options
119119
) => OnJsonNotification(method, handler, options);
120120

121-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification<TParams>(string method, Action<TParams> handler, JsonRpcHandlerOptions options) =>
121+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification<TParams>(string method, Action<TParams> handler, JsonRpcHandlerOptions? options) =>
122122
OnNotification(method, handler, options);
123123

124124
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification<TParams>(
125-
string method, Func<TParams, CancellationToken, Task> handler, JsonRpcHandlerOptions options
125+
string method, Func<TParams, CancellationToken, Task> handler, JsonRpcHandlerOptions? options
126126
) => OnNotification(method, handler, options);
127127

128128
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.
129-
OnNotification<TParams>(string method, Func<TParams, Task> handler, JsonRpcHandlerOptions options) => OnNotification(method, handler, options);
129+
OnNotification<TParams>(string method, Func<TParams, Task> handler, JsonRpcHandlerOptions? options) => OnNotification(method, handler, options);
130130

131-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification(string method, Action handler, JsonRpcHandlerOptions options) =>
131+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification(string method, Action handler, JsonRpcHandlerOptions? options) =>
132132
OnNotification(method, handler, options);
133133

134134
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.
135-
OnNotification(string method, Func<CancellationToken, Task> handler, JsonRpcHandlerOptions options) => OnNotification(method, handler, options);
135+
OnNotification(string method, Func<CancellationToken, Task> handler, JsonRpcHandlerOptions? options) => OnNotification(method, handler, options);
136136

137-
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification(string method, Func<Task> handler, JsonRpcHandlerOptions options) =>
137+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnNotification(string method, Func<Task> handler, JsonRpcHandlerOptions? options) =>
138138
OnNotification(method, handler, options);
139-
140-
public override IRequestProcessIdentifier RequestProcessIdentifier { get; set; }
141139
}
142140
}

0 commit comments

Comments
 (0)