Skip to content

Commit fae7af9

Browse files
LSP Protocol 2/2
1 parent 15db871 commit fae7af9

Some content is hidden

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

44 files changed

+234
-254
lines changed

src/Protocol/AbstractHandlers.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public abstract class Request<TParams, TResult, TCapability, TRegistrationOption
2323
where TCapability : ICapability
2424
{
2525
private readonly TRegistrationOptions _registrationOptions;
26-
protected TCapability Capability { get; private set; }
26+
protected TCapability Capability { get; private set; } = default!;
2727

2828
protected Request(TRegistrationOptions registrationOptions) => _registrationOptions = registrationOptions;
2929

@@ -44,7 +44,7 @@ public abstract class PartialResult<TItem, TResponse, TCapability, TRegistration
4444
private readonly TRegistrationOptions _registrationOptions;
4545
private readonly IProgressManager _progressManager;
4646
private readonly Func<TItem, TResponse> _factory;
47-
protected TCapability Capability { get; private set; }
47+
protected TCapability Capability { get; private set; } = default!;
4848

4949
protected PartialResult(
5050
TRegistrationOptions registrationOptions,
@@ -63,7 +63,7 @@ CancellationToken cancellationToken
6363
)
6464
{
6565
var observer = _progressManager.For(request, cancellationToken);
66-
if (observer != null)
66+
if (observer == ProgressObserver<TItem>.Noop)
6767
{
6868
Handle(request, observer, cancellationToken);
6969
await observer;
@@ -72,7 +72,7 @@ CancellationToken cancellationToken
7272

7373
var subject = new AsyncSubject<TItem>();
7474
// in the event nothing is emitted...
75-
subject.OnNext(default);
75+
subject.OnNext(default!);
7676
Handle(request, subject, cancellationToken);
7777
return _factory(await subject);
7878
}
@@ -97,7 +97,7 @@ public abstract class PartialResults<TParams, TResponse, TItem, TCapability, TRe
9797
private readonly TRegistrationOptions _registrationOptions;
9898
private readonly IProgressManager _progressManager;
9999
private readonly Func<IEnumerable<TItem>, TResponse> _factory;
100-
protected TCapability Capability { get; private set; }
100+
protected TCapability Capability { get; private set; } = default!;
101101

102102
protected PartialResults(
103103
TRegistrationOptions registrationOptions,
@@ -116,7 +116,7 @@ CancellationToken cancellationToken
116116
)
117117
{
118118
var observer = _progressManager.For(request, cancellationToken);
119-
if (observer != null)
119+
if (observer != ProgressObserver<TItem>.Noop)
120120
{
121121
Handle(request, observer, cancellationToken);
122122
await observer;
@@ -152,12 +152,9 @@ public abstract class Notification<TParams, TCapability, TRegistrationOptions> :
152152
where TCapability : ICapability
153153
{
154154
private readonly TRegistrationOptions _registrationOptions;
155-
protected TCapability Capability { get; private set; }
155+
protected TCapability Capability { get; private set; } = default!;
156156

157-
protected Notification(
158-
TRegistrationOptions registrationOptions
159-
) =>
160-
_registrationOptions = registrationOptions;
157+
protected Notification(TRegistrationOptions registrationOptions) => _registrationOptions = registrationOptions;
161158

162159
public Task<Unit> Handle(TParams request, CancellationToken cancellationToken)
163160
{

src/Protocol/CharCode.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace OmniSharp.Extensions.LanguageServer.Protocol
1+
// ReSharper disable InconsistentNaming
2+
namespace OmniSharp.Extensions.LanguageServer.Protocol
23
{
34
internal static class CharCode
45
{
@@ -118,14 +119,14 @@ internal static class CharCode
118119
public const int Semicolon = 59;
119120

120121
/// <summary>
121-
/// The `<` character.
122+
/// The `&lt;` character.
122123
/// </summary>
123124
public const int LessThan = 60;
124125

125126
/// <summary>
126127
/// The `=` character.
127128
/// </summary>
128-
public const int Equals = 61;
129+
public new const int Equals = 61;
129130

130131
/// <summary>
131132
/// The `>` character.

src/Protocol/DocumentUri.Internal.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private static void _validateUri(DocumentUri ret, bool? strict)
7171
}
7272
}
7373

74-
private static string SchemeFix(string scheme, bool? strict)
74+
private static string? SchemeFix(string? scheme, bool? strict)
7575
{
7676
if (string.IsNullOrWhiteSpace(scheme) && strict != true)
7777
{
@@ -88,7 +88,7 @@ private static string SchemeFix(string scheme, bool? strict)
8888
private static readonly Regex Regexp =
8989
new Regex(@"^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?");
9090

91-
private static string ReferenceResolution(string scheme, string path)
91+
private static string ReferenceResolution(string? scheme, string path)
9292
{
9393
// the slash-character is our "default base' as we don"t
9494
// support constructing URIs relative to other URIs. This
@@ -135,7 +135,7 @@ private static string ReferenceResolution(string scheme, string path)
135135

136136
private static string EncodeUriComponentFast(string uriComponent, bool allowSlash)
137137
{
138-
string res = null;
138+
string? res = null;
139139
var nativeEncodePos = -1;
140140

141141
for (var pos = 0; pos < uriComponent.Length; pos++)
@@ -207,12 +207,12 @@ private static string EncodeUriComponentFast(string uriComponent, bool allowSlas
207207
res += Uri.EscapeDataString(uriComponent.Substring(nativeEncodePos));
208208
}
209209

210-
return !string.IsNullOrWhiteSpace(res) ? res : uriComponent;
210+
return !string.IsNullOrWhiteSpace(res) ? res! : uriComponent;
211211
}
212212

213213
private static string EncodeUriComponentMinimal(string path)
214214
{
215-
string res = null;
215+
string? res = null;
216216
for (var pos = 0; pos < path.Length; pos++)
217217
{
218218
var code = path[pos];
@@ -306,13 +306,13 @@ string Encoder(string p, bool allowSlash)
306306

307307
if (!string.IsNullOrWhiteSpace(authority))
308308
{
309-
var idx = authority.IndexOf("@");
309+
var idx = authority.IndexOf("@", StringComparison.Ordinal);
310310
if (idx != -1)
311311
{
312312
// <user>@<auth>
313313
var userinfo = authority.Substring(0, idx);
314314
authority = authority.Substring(idx + 1);
315-
idx = userinfo.IndexOf(":");
315+
idx = userinfo.IndexOf(":", StringComparison.Ordinal);
316316
if (idx == -1)
317317
{
318318
res += Encoder(userinfo, false);

src/Protocol/DocumentUri.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Runtime.InteropServices;
44
using Newtonsoft.Json;
@@ -12,7 +12,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol
1212
/// This class is a simple parser which creates the basic component parts
1313
/// (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation
1414
/// and encoding.
15-
///
15+
///
1616
/// ```txt
1717
/// foo://example.com:8042/over/there?name=ferret#nose
1818
/// \_/ \______________/\_________/ \_________/ \__/
@@ -28,13 +28,13 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol
2828
/// </summary>
2929
/// <remarks>This exists because of some non-standard serialization in vscode around uris and .NET's behavior when deserializing those uris</remarks>
3030
[JsonConverter(typeof(DocumentUriConverter))]
31-
public partial class DocumentUri : IEquatable<DocumentUri>
31+
public partial class DocumentUri : IEquatable<DocumentUri?>
3232
{
3333
/// <summary>
3434
/// scheme is the "http' part of 'http://www.msft.com/some/path?query#fragment".
3535
/// The part before the first colon.
3636
/// </summary>
37-
public string Scheme { get; }
37+
public string? Scheme { get; }
3838

3939
/// <summary>
4040
/// authority is the "www.msft.com' part of 'http://www.msft.com/some/path?query#fragment".
@@ -64,7 +64,7 @@ public partial class DocumentUri : IEquatable<DocumentUri>
6464
/// <remarks>This will produce a uri where asian and cyrillic characters will be encoded</remarks>
6565
public Uri ToUri()
6666
{
67-
if (Authority.IndexOf(":") > -1)
67+
if (Authority.IndexOf(":", StringComparison.Ordinal) > -1)
6868
{
6969
var parts = Authority.Split(':');
7070
var host = parts[0];
@@ -113,9 +113,9 @@ public Uri ToUri()
113113
public string GetFileSystemPath() => UriToFsPath(this, false);
114114

115115
/// <inheritdoc />
116-
public bool Equals(DocumentUri other)
116+
public bool Equals(DocumentUri? other)
117117
{
118-
if (ReferenceEquals(null, other)) return false;
118+
if (other is null) return false;
119119
if (ReferenceEquals(this, other)) return true;
120120
// It's possible mac can have case insensitive file systems... we can always come back and change this.
121121
var comparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
@@ -129,9 +129,9 @@ public bool Equals(DocumentUri other)
129129
}
130130

131131
/// <inheritdoc />
132-
public override bool Equals(object obj)
132+
public override bool Equals(object? obj)
133133
{
134-
if (ReferenceEquals(null, obj)) return false;
134+
if (obj is null) return false;
135135
if (ReferenceEquals(this, obj)) return true;
136136
return obj.GetType() == GetType() && Equals((DocumentUri) obj);
137137
}
@@ -164,7 +164,7 @@ public override int GetHashCode()
164164
/// <param name="fragment"></param>
165165
/// <returns></returns>
166166
public void Deconstruct(
167-
out string scheme, out string authority, out string path, out string query,
167+
out string? scheme, out string authority, out string path, out string query,
168168
out string fragment
169169
)
170170
{
@@ -267,7 +267,7 @@ public static DocumentUri From(string url)
267267
/// <returns>
268268
/// The file-system path, or <c>null</c> if the URI does not represent a file-system path.
269269
/// </returns>
270-
public static string GetFileSystemPath(ITextDocumentIdentifierParams textDocumentIdentifierParams) =>
270+
public static string? GetFileSystemPath(ITextDocumentIdentifierParams textDocumentIdentifierParams) =>
271271
GetFileSystemPath(textDocumentIdentifierParams.TextDocument.Uri);
272272

273273
/// <summary>
@@ -279,7 +279,7 @@ public static string GetFileSystemPath(ITextDocumentIdentifierParams textDocumen
279279
/// <returns>
280280
/// The file-system path, or <c>null</c> if the URI does not represent a file-system path.
281281
/// </returns>
282-
public static string GetFileSystemPath(TextDocumentIdentifier textDocumentIdentifier) =>
282+
public static string? GetFileSystemPath(TextDocumentIdentifier textDocumentIdentifier) =>
283283
GetFileSystemPath(textDocumentIdentifier.Uri);
284284

285285
/// <summary>
@@ -291,10 +291,9 @@ public static string GetFileSystemPath(TextDocumentIdentifier textDocumentIdenti
291291
/// <returns>
292292
/// The file-system path, or <c>null</c> if the URI does not represent a file-system path.
293293
/// </returns>
294-
public static string GetFileSystemPath(DocumentUri documentUri)
294+
public static string? GetFileSystemPath(DocumentUri documentUri)
295295
{
296-
if (documentUri == null)
297-
throw new ArgumentNullException(nameof(documentUri));
296+
if (documentUri == null!) throw new ArgumentNullException(nameof(documentUri));
298297

299298
if (documentUri.Scheme != Uri.UriSchemeFile)
300299
return null;
@@ -315,11 +314,11 @@ public static string GetFileSystemPath(DocumentUri documentUri)
315314

316315
private sealed class DocumentUriEqualityComparer : IEqualityComparer<DocumentUri>
317316
{
318-
public bool Equals(DocumentUri x, DocumentUri y)
317+
public bool Equals(DocumentUri? x, DocumentUri? y)
319318
{
320319
if (ReferenceEquals(x, y)) return true;
321-
if (ReferenceEquals(x, null)) return false;
322-
if (ReferenceEquals(y, null)) return false;
320+
if (x is null) return false;
321+
if (y is null) return false;
323322
return x.GetType() == y.GetType() && x.Equals(y);
324323
}
325324

@@ -346,10 +345,7 @@ public bool Equals(DocumentUri x, DocumentUri y)
346345
/// <summary>
347346
/// @internal
348347
/// </summary>
349-
public DocumentUri(
350-
string scheme, string authority, string path, string query, string fragment,
351-
bool? strict = null
352-
)
348+
public DocumentUri(string? scheme, string? authority, string? path, string? query, string? fragment, bool? strict = null)
353349
{
354350
Scheme = SchemeFix(scheme, strict);
355351
Authority = authority ?? Empty;

src/Protocol/DocumentUriComponents.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
public struct DocumentUriComponents
44
{
5-
public string Scheme { get; set; }
6-
public string Authority { get; set; }
7-
public string Path { get; set; }
8-
public string Query { get; set; }
9-
public string Fragment { get; set; }
5+
public string? Scheme { get; set; }
6+
public string? Authority { get; set; }
7+
public string? Path { get; set; }
8+
public string? Query { get; set; }
9+
public string? Fragment { get; set; }
1010
}
1111
}

src/Protocol/IRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace OmniSharp.Extensions.LanguageServer.Protocol
22
{
33
public interface IRegistration<out TOptions>
4-
where TOptions : class, new()
4+
where TOptions : class?, new()
55
{
66
TOptions GetRegistrationOptions();
77
}

src/Protocol/IRegistrationOptions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
namespace OmniSharp.Extensions.LanguageServer.Protocol
22
{
3-
public interface IRegistrationOptions
4-
{
5-
6-
}
3+
public interface IRegistrationOptions { }
74
}

src/Protocol/IRegistrationOptionsConverter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
32

43
namespace OmniSharp.Extensions.LanguageServer.Protocol
54
{
@@ -8,12 +7,12 @@ public interface IRegistrationOptionsConverter
87
Type SourceType { get; }
98
Type DestinationType { get; }
109
string Key { get; }
11-
object Convert(object source);
10+
object? Convert(object source);
1211
}
1312

1413
public interface IRegistrationOptionsConverter<in TSource, out TDestination> : IRegistrationOptionsConverter
1514
where TSource : IRegistrationOptions
16-
where TDestination : class
15+
where TDestination : class?
1716
{
1817
TDestination Convert(TSource source);
1918
}
@@ -30,7 +29,7 @@ public RegistrationOptionsConverterBase(string key)
3029
public Type SourceType { get; } = typeof(TSource);
3130
public Type DestinationType { get; }= typeof(TDestination);
3231
public string Key { get; }
33-
public object Convert(object source) => source is TSource value ? Convert(value) : null;
32+
public object? Convert(object source) => source is TSource value ? Convert(value) : null;
3433
public abstract TDestination Convert(TSource source);
3534
}
3635
}

src/Protocol/ISupports.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public interface ISupports
66
{
77
bool IsSupported { get; }
88
Type ValueType { get; }
9-
object Value { get; }
9+
object? Value { get; }
1010
}
1111
}

0 commit comments

Comments
 (0)