diff --git a/README.md b/README.md index 7ad40ab94..33100a9de 100644 --- a/README.md +++ b/README.md @@ -43,27 +43,27 @@ For more information about using the `DebugAdapterClient` / `DebugAdapterServer` -| Azure Pipelines | GitHub Actions | -| --------------------------------------------------------- | --------------------------------- | -| [![azurepipelines-badge]][azurepipelines] | [![github-badge]][github] | +| Azure Pipelines | GitHub Actions | +| --------------- | -------------- | +| [![azurepipelines-badge]][azurepipelines] | [![github-badge]][github] | | [![azurepipelines-history-badge]][azurepipelines-history] | [![github-history-badge]][github] | -| Package | NuGet | -| --------------------------------------------- | ---------------------------------------------------------------------------------------------- | -| OmniSharp.Extensions.DebugAdapter | [![nuget-version-hefb6om79mfg-badge]![nuget-downloads-hefb6om79mfg-badge]][nuget-hefb6om79mfg] | -| OmniSharp.Extensions.DebugAdapter.Client | [![nuget-version-94qjnkon/cda-badge]![nuget-downloads-94qjnkon/cda-badge]][nuget-94qjnkon/cda] | -| OmniSharp.Extensions.DebugAdapter.Server | [![nuget-version-f/4jrt4grmdg-badge]![nuget-downloads-f/4jrt4grmdg-badge]][nuget-f/4jrt4grmdg] | -| OmniSharp.Extensions.DebugAdapter.Shared | [![nuget-version-2fkn0yzdbhmg-badge]![nuget-downloads-2fkn0yzdbhmg-badge]][nuget-2fkn0yzdbhmg] | -| OmniSharp.Extensions.DebugAdapter.Testing | [![nuget-version-jppuysmkpfcw-badge]![nuget-downloads-jppuysmkpfcw-badge]][nuget-jppuysmkpfcw] | -| OmniSharp.Extensions.JsonRpc | [![nuget-version-a1bmkwyotvkg-badge]![nuget-downloads-a1bmkwyotvkg-badge]][nuget-a1bmkwyotvkg] | -| OmniSharp.Extensions.JsonRpc.Testing | [![nuget-version-punkj7/efvjq-badge]![nuget-downloads-punkj7/efvjq-badge]][nuget-punkj7/efvjq] | -| OmniSharp.Extensions.LanguageClient | [![nuget-version-fclou9t/p2ba-badge]![nuget-downloads-fclou9t/p2ba-badge]][nuget-fclou9t/p2ba] | -| OmniSharp.Extensions.LanguageProtocol | [![nuget-version-vddj9t6jnirq-badge]![nuget-downloads-vddj9t6jnirq-badge]][nuget-vddj9t6jnirq] | +| Package | NuGet | +| ------- | ----- | +| OmniSharp.Extensions.DebugAdapter | [![nuget-version-hefb6om79mfg-badge]![nuget-downloads-hefb6om79mfg-badge]][nuget-hefb6om79mfg] | +| OmniSharp.Extensions.DebugAdapter.Client | [![nuget-version-94qjnkon/cda-badge]![nuget-downloads-94qjnkon/cda-badge]][nuget-94qjnkon/cda] | +| OmniSharp.Extensions.DebugAdapter.Server | [![nuget-version-f/4jrt4grmdg-badge]![nuget-downloads-f/4jrt4grmdg-badge]][nuget-f/4jrt4grmdg] | +| OmniSharp.Extensions.DebugAdapter.Shared | [![nuget-version-2fkn0yzdbhmg-badge]![nuget-downloads-2fkn0yzdbhmg-badge]][nuget-2fkn0yzdbhmg] | +| OmniSharp.Extensions.DebugAdapter.Testing | [![nuget-version-jppuysmkpfcw-badge]![nuget-downloads-jppuysmkpfcw-badge]][nuget-jppuysmkpfcw] | +| OmniSharp.Extensions.JsonRpc | [![nuget-version-a1bmkwyotvkg-badge]![nuget-downloads-a1bmkwyotvkg-badge]][nuget-a1bmkwyotvkg] | +| OmniSharp.Extensions.JsonRpc.Testing | [![nuget-version-punkj7/efvjq-badge]![nuget-downloads-punkj7/efvjq-badge]][nuget-punkj7/efvjq] | +| OmniSharp.Extensions.LanguageClient | [![nuget-version-fclou9t/p2ba-badge]![nuget-downloads-fclou9t/p2ba-badge]][nuget-fclou9t/p2ba] | +| OmniSharp.Extensions.LanguageProtocol | [![nuget-version-vddj9t6jnirq-badge]![nuget-downloads-vddj9t6jnirq-badge]][nuget-vddj9t6jnirq] | | OmniSharp.Extensions.LanguageProtocol.Testing | [![nuget-version-md8c3c/bo/8g-badge]![nuget-downloads-md8c3c/bo/8g-badge]][nuget-md8c3c/bo/8g] | -| OmniSharp.Extensions.LanguageServer | [![nuget-version-fkxlzvrmzpbw-badge]![nuget-downloads-fkxlzvrmzpbw-badge]][nuget-fkxlzvrmzpbw] | -| OmniSharp.Extensions.LanguageServer.Shared | [![nuget-version-4htmykprzq1a-badge]![nuget-downloads-4htmykprzq1a-badge]][nuget-4htmykprzq1a] | +| OmniSharp.Extensions.LanguageServer | [![nuget-version-fkxlzvrmzpbw-badge]![nuget-downloads-fkxlzvrmzpbw-badge]][nuget-fkxlzvrmzpbw] | +| OmniSharp.Extensions.LanguageServer.Shared | [![nuget-version-4htmykprzq1a-badge]![nuget-downloads-4htmykprzq1a-badge]][nuget-4htmykprzq1a] | ## License @@ -93,10 +93,10 @@ This project is supported by the [.NET Foundation](http://www.dotnetfoundation.o [github-license-badge]: https://img.shields.io/github/license/OmniSharp/csharp-language-server-protocol.svg?style=flat "License" [codecov]: https://codecov.io/gh/OmniSharp/csharp-language-server-protocol [codecov-badge]: https://img.shields.io/codecov/c/github/OmniSharp/csharp-language-server-protocol.svg?color=E03997&label=codecov&logo=codecov&logoColor=E03997&style=flat "Code Coverage" -[azurepipelines]: https://dev.azure.com/omnisharp/Build/_build/latest?definitionId=1&branchName=master -[azurepipelines-badge]: https://img.shields.io/azure-devops/build/omnisharp/Build/1.svg?color=98C6FF&label=azure%20pipelines&logo=azuredevops&logoColor=98C6FF&style=flat "Azure Pipelines Status" -[azurepipelines-history]: https://dev.azure.com/omnisharp/Build/_build?definitionId=1&branchName=master -[azurepipelines-history-badge]: https://buildstats.info/azurepipelines/chart/omnisharp/Build/1?includeBuildsFromPullRequest=false "Azure Pipelines History" +[azurepipelines]: https://dev.azure.com/omnisharp/Builds/_build/latest?definitionId=1&branchName=master +[azurepipelines-badge]: https://img.shields.io/azure-devops/build/omnisharp/Builds/1.svg?color=98C6FF&label=azure%20pipelines&logo=azuredevops&logoColor=98C6FF&style=flat "Azure Pipelines Status" +[azurepipelines-history]: https://dev.azure.com/omnisharp/Builds/_build?definitionId=1&branchName=master +[azurepipelines-history-badge]: https://buildstats.info/azurepipelines/chart/omnisharp/Builds/1?includeBuildsFromPullRequest=false "Azure Pipelines History" [github]: https://github.com/OmniSharp/csharp-language-server-protocol/actions?query=workflow%3Aci [github-badge]: https://img.shields.io/github/workflow/status/OmniSharp/csharp-language-server-protocol/ci.svg?label=github&logo=github&color=b845fc&logoColor=b845fc&style=flat "GitHub Actions Status" [github-history-badge]: https://buildstats.info/github/chart/OmniSharp/csharp-language-server-protocol?includeBuildsFromPullRequest=false "GitHub Actions History" diff --git a/src/Client/Configuration/ChainedConfigurationProvider.cs b/src/Client/Configuration/ChainedConfigurationProvider.cs index 1a310f5e2..609276795 100644 --- a/src/Client/Configuration/ChainedConfigurationProvider.cs +++ b/src/Client/Configuration/ChainedConfigurationProvider.cs @@ -72,7 +72,7 @@ public void Load() { } /// The child keys. public IEnumerable GetChildKeys( IEnumerable earlierKeys, - string parentPath) + string? parentPath) { IConfiguration section = parentPath == null ? _config : _config.GetSection(parentPath); var children = section.GetChildren(); diff --git a/src/Client/Configuration/ChainedConfigurationSource.cs b/src/Client/Configuration/ChainedConfigurationSource.cs index 9e553c651..c247a8f94 100644 --- a/src/Client/Configuration/ChainedConfigurationSource.cs +++ b/src/Client/Configuration/ChainedConfigurationSource.cs @@ -13,7 +13,7 @@ internal class ChainedConfigurationSource : IConfigurationSource /// /// The chained configuration. /// - public IConfiguration Configuration { get; set; } + public IConfiguration Configuration { get; set; } = null!; /// /// Whether the chained configuration should be disposed when the diff --git a/src/Client/DefaultLanguageClientFacade.cs b/src/Client/DefaultLanguageClientFacade.cs index 8edee7461..d5ae45489 100644 --- a/src/Client/DefaultLanguageClientFacade.cs +++ b/src/Client/DefaultLanguageClientFacade.cs @@ -19,8 +19,8 @@ internal class DefaultLanguageClientFacade : LanguageProtocolProxy, ILanguageCli private readonly Lazy _workspace; private readonly Lazy _handlersManager; private readonly TextDocumentIdentifiers _textDocumentIdentifiers; - private readonly IInsanceHasStarted _insanceHasStarted; - private ILanguageClient _languageClient; + private readonly IInsanceHasStarted _instanceHasStarted; + private ILanguageClient? _languageClient; public DefaultLanguageClientFacade( IResponseRouter requestRouter, @@ -34,7 +34,7 @@ public DefaultLanguageClientFacade( Lazy workspace, Lazy handlersManager, TextDocumentIdentifiers textDocumentIdentifiers, - IInsanceHasStarted insanceHasStarted + IInsanceHasStarted instanceHasStarted ) : base(requestRouter, resolverContext, progressManager, languageProtocolSettings) { _textDocument = textDocument; @@ -44,7 +44,7 @@ IInsanceHasStarted insanceHasStarted _workspace = workspace; _handlersManager = handlersManager; _textDocumentIdentifiers = textDocumentIdentifiers; - _insanceHasStarted = insanceHasStarted; + _instanceHasStarted = instanceHasStarted; } public ITextDocumentLanguageClient TextDocument => _textDocument.Value; @@ -58,7 +58,7 @@ public IDisposable Register(Action registryAction) var manager = new CompositeHandlersManager(_handlersManager.Value); registryAction(new LangaugeClientRegistry(ResolverContext, manager, _textDocumentIdentifiers)); var result = manager.GetDisposable(); - if (_insanceHasStarted.Started) + if (_instanceHasStarted.Started) { if (_languageClient == null) throw new NotSupportedException("Language client has not yet started... you shouldn't be here."); LanguageClientHelpers.InitHandlers(_languageClient, result); diff --git a/src/Client/LanguageClientServiceCollectionExtensions.cs b/src/Client/LanguageClientServiceCollectionExtensions.cs index daf059df2..893852922 100644 --- a/src/Client/LanguageClientServiceCollectionExtensions.cs +++ b/src/Client/LanguageClientServiceCollectionExtensions.cs @@ -80,7 +80,7 @@ internal static IContainer AddLanguageClientInternals(this IContainer container, if (providedConfiguration != null) { - builder.CustomAddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration); + builder.CustomAddConfiguration((providedConfiguration.ImplementationInstance as IConfiguration)!); } //var didChangeConfigurationProvider = _.GetRequiredService(); diff --git a/src/Dap.Client/Configuration/ChainedConfigurationProvider.cs b/src/Dap.Client/Configuration/ChainedConfigurationProvider.cs index 2afad36c9..c454a2b32 100644 --- a/src/Dap.Client/Configuration/ChainedConfigurationProvider.cs +++ b/src/Dap.Client/Configuration/ChainedConfigurationProvider.cs @@ -72,7 +72,7 @@ public void Load() { } /// The child keys. public IEnumerable GetChildKeys( IEnumerable earlierKeys, - string parentPath) + string? parentPath) { IConfiguration section = parentPath == null ? _config : _config.GetSection(parentPath); var children = section.GetChildren(); diff --git a/src/Dap.Client/Configuration/ChainedConfigurationSource.cs b/src/Dap.Client/Configuration/ChainedConfigurationSource.cs index 61b55434e..6fca77a5d 100644 --- a/src/Dap.Client/Configuration/ChainedConfigurationSource.cs +++ b/src/Dap.Client/Configuration/ChainedConfigurationSource.cs @@ -13,7 +13,7 @@ internal class ChainedConfigurationSource : IConfigurationSource /// /// The chained configuration. /// - public IConfiguration Configuration { get; set; } + public IConfiguration Configuration { get; set; } = null!; /// /// Whether the chained configuration should be disposed when the diff --git a/src/Dap.Client/DebugAdapterClientServiceCollectionExtensions.cs b/src/Dap.Client/DebugAdapterClientServiceCollectionExtensions.cs index 25f05e796..236df4a24 100644 --- a/src/Dap.Client/DebugAdapterClientServiceCollectionExtensions.cs +++ b/src/Dap.Client/DebugAdapterClientServiceCollectionExtensions.cs @@ -75,7 +75,7 @@ internal static IContainer AddDebugAdapterClientInternals(this IContainer contai if (providedConfiguration != null) { - builder.CustomAddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration); + builder.CustomAddConfiguration((providedConfiguration.ImplementationInstance as IConfiguration)!); } return builder.Build(); diff --git a/src/Dap.Server/Configuration/ChainedConfigurationProvider.cs b/src/Dap.Server/Configuration/ChainedConfigurationProvider.cs index 6d964548b..8ea4d5126 100644 --- a/src/Dap.Server/Configuration/ChainedConfigurationProvider.cs +++ b/src/Dap.Server/Configuration/ChainedConfigurationProvider.cs @@ -72,7 +72,7 @@ public void Load() { } /// The child keys. public IEnumerable GetChildKeys( IEnumerable earlierKeys, - string parentPath) + string? parentPath) { IConfiguration section = parentPath == null ? _config : _config.GetSection(parentPath); var children = section.GetChildren(); diff --git a/src/Dap.Server/Configuration/ChainedConfigurationSource.cs b/src/Dap.Server/Configuration/ChainedConfigurationSource.cs index 51616c81b..23f5aa2d1 100644 --- a/src/Dap.Server/Configuration/ChainedConfigurationSource.cs +++ b/src/Dap.Server/Configuration/ChainedConfigurationSource.cs @@ -13,7 +13,7 @@ internal class ChainedConfigurationSource : IConfigurationSource /// /// The chained configuration. /// - public IConfiguration Configuration { get; set; } + public IConfiguration Configuration { get; set; } = null!; /// /// Whether the chained configuration should be disposed when the diff --git a/src/Dap.Server/DebugAdapterServerServiceCollectionExtensions.cs b/src/Dap.Server/DebugAdapterServerServiceCollectionExtensions.cs index 20e8b390c..3d2d6a533 100644 --- a/src/Dap.Server/DebugAdapterServerServiceCollectionExtensions.cs +++ b/src/Dap.Server/DebugAdapterServerServiceCollectionExtensions.cs @@ -59,7 +59,7 @@ internal static IContainer AddDebugAdapterServerInternals(this IContainer contai if (providedConfiguration != null) { - builder.CustomAddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration); + builder.CustomAddConfiguration((providedConfiguration.ImplementationInstance as IConfiguration)!); } return builder.Build(); diff --git a/src/JsonRpc.Generators/GenerateHandlerMethodsGenerator.cs b/src/JsonRpc.Generators/GenerateHandlerMethodsGenerator.cs index 85ead03b7..b5075b059 100644 --- a/src/JsonRpc.Generators/GenerateHandlerMethodsGenerator.cs +++ b/src/JsonRpc.Generators/GenerateHandlerMethodsGenerator.cs @@ -49,7 +49,7 @@ public Task GenerateRichAsync(TransformationContext contex { var requestType = GetRequestType(symbol); var responseType = GetResponseType(handlerInterface); - methods.AddRange(HandleRequest(handlerInterface, symbol, requestType, responseType, registry, additionalUsings)); + methods.AddRange(HandleRequest(handlerInterface, symbol, requestType, responseType!, registry, additionalUsings)); } } diff --git a/src/JsonRpc/NoopResponseRouter.cs b/src/JsonRpc/NoopResponseRouter.cs index 4363ec732..0c6b584b3 100644 --- a/src/JsonRpc/NoopResponseRouter.cs +++ b/src/JsonRpc/NoopResponseRouter.cs @@ -33,12 +33,12 @@ public void SendNotification(IRequest request) public IResponseRouterReturns SendRequest(string method) => new Impl(); - public Task SendRequest(IRequest request, CancellationToken cancellationToken) => Task.FromResult(default); + public Task SendRequest(IRequest request, CancellationToken cancellationToken) => Task.FromResult(default!); bool IResponseRouter.TryGetRequest(long id, [NotNullWhen(true)] out string method, [NotNullWhen(true)] out TaskCompletionSource pendingTask) { - method = default; - pendingTask = default; + method = default!; + pendingTask = default!; return false; } diff --git a/src/JsonRpc/RequestRouterBase.cs b/src/JsonRpc/RequestRouterBase.cs index ae7a0b207..6bdc5c661 100644 --- a/src/JsonRpc/RequestRouterBase.cs +++ b/src/JsonRpc/RequestRouterBase.cs @@ -64,7 +64,7 @@ static async Task InnerRoute(IServiceScopeFactory serviceScopeFactory, TDescript context.Descriptor = descriptor; var mediator = scope.ServiceProvider.GetRequiredService(); - await HandleNotification(mediator, descriptor, @params ?? Activator.CreateInstance(descriptor.Params), token).ConfigureAwait(false); + await HandleNotification(mediator, descriptor, @params ?? Activator.CreateInstance(descriptor.Params!), token).ConfigureAwait(false); } } diff --git a/src/Protocol/DocumentUri.Internal.cs b/src/Protocol/DocumentUri.Internal.cs index 862370a94..a841a3649 100644 --- a/src/Protocol/DocumentUri.Internal.cs +++ b/src/Protocol/DocumentUri.Internal.cs @@ -39,7 +39,7 @@ private static void _validateUri(DocumentUri ret, bool? strict) // scheme, https://tools.ietf.org/html/rfc3986#section-3.1 // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) - if (!string.IsNullOrWhiteSpace(ret.Scheme) && !SchemePattern.IsMatch(ret.Scheme)) + if (!string.IsNullOrWhiteSpace(ret.Scheme) && !SchemePattern.IsMatch(ret.Scheme!)) { throw new UriFormatException("Scheme contains illegal characters."); } @@ -170,11 +170,7 @@ private static string EncodeUriComponentFast(string uriComponent, bool allowSlas } // check if we write into a new string (by default we try to return the param) - if (res != null) - { - res ??= new StringBuilder(); - res.Append(uriComponent[pos]); - } + res?.Append(uriComponent[pos]); } else { diff --git a/src/Protocol/LanguageProtocolDelegatingHandlers.cs b/src/Protocol/LanguageProtocolDelegatingHandlers.cs index e2d439873..2136ca6ee 100644 --- a/src/Protocol/LanguageProtocolDelegatingHandlers.cs +++ b/src/Protocol/LanguageProtocolDelegatingHandlers.cs @@ -401,7 +401,7 @@ CancellationToken cancellationToken var subject = new AsyncSubject(); // in the event nothing is emitted... - subject.OnNext(default); + subject.OnNext(default!); _handler(request, subject, _capability, cancellationToken); return await subject.Select(_factory).ToTask(cancellationToken).ConfigureAwait(false); } @@ -471,7 +471,7 @@ async Task IRequestHandler.Handle(TParams request var subject = new AsyncSubject(); // in the event nothing is emitted... - subject.OnNext(default); + subject.OnNext(default!); _handler(request, subject, cancellationToken); return await subject.Select(_factory).ToTask(cancellationToken).ConfigureAwait(false); } @@ -533,7 +533,7 @@ async Task IRequestHandler.Handle(TParams request var subject = new AsyncSubject(); // in the event nothing is emitted... - subject.OnNext(default); + subject.OnNext(default!); _handler(request, _capability, subject, cancellationToken); return await subject.Select(_factory).ToTask(cancellationToken).ConfigureAwait(false); } @@ -591,7 +591,7 @@ async Task IRequestHandler.Handle(TParams request var subject = new AsyncSubject(); // in the event nothing is emitted... - subject.OnNext(default); + subject.OnNext(default!); _handler(request, subject, cancellationToken); return await subject.Select(_factory).ToTask(cancellationToken).ConfigureAwait(false); } diff --git a/src/Protocol/LanguageProtocolRpcOptionsBase.cs b/src/Protocol/LanguageProtocolRpcOptionsBase.cs index c180982a7..2ebb65cc0 100644 --- a/src/Protocol/LanguageProtocolRpcOptionsBase.cs +++ b/src/Protocol/LanguageProtocolRpcOptionsBase.cs @@ -35,7 +35,7 @@ public T AddTextDocumentIdentifier() where TI : ITextDocumentIdentifier public ISerializer Serializer { get; set; } = new Serializer(ClientVersion.Lsp3); internal bool AddDefaultLoggingProvider { get; set; } - internal Action LoggingBuilderAction { get; set; } = _ => { }; - internal Action ConfigurationBuilderAction { get; set; } = _ => { }; + internal Action? LoggingBuilderAction { get; set; } = _ => { }; + internal Action? ConfigurationBuilderAction { get; set; } = _ => { }; } } diff --git a/src/Protocol/Models/DocumentSelector.cs b/src/Protocol/Models/DocumentSelector.cs index eb9fd7ba7..761c54739 100644 --- a/src/Protocol/Models/DocumentSelector.cs +++ b/src/Protocol/Models/DocumentSelector.cs @@ -30,7 +30,7 @@ public DocumentSelector(params DocumentFilter[] items) : base(items) public static implicit operator DocumentSelector(List items) => new DocumentSelector(items); - public static implicit operator string(DocumentSelector documentSelector) => + public static implicit operator string(DocumentSelector? documentSelector) => documentSelector is not null ? string.Join(", ", documentSelector.Select(x => (string) x)) : string.Empty; public bool IsMatch(TextDocumentAttributes attributes) => this.Any(z => z.IsMatch(attributes)); diff --git a/src/Protocol/Models/Position.cs b/src/Protocol/Models/Position.cs index b07f31e21..924d72def 100644 --- a/src/Protocol/Models/Position.cs +++ b/src/Protocol/Models/Position.cs @@ -34,7 +34,7 @@ other is not null && Line == other.Line && Character == other.Character; - public int CompareTo(Position other) + public int CompareTo(Position? other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; @@ -42,7 +42,7 @@ public int CompareTo(Position other) return lineComparison != 0 ? lineComparison : Character.CompareTo(other.Character); } - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (ReferenceEquals(null, obj)) return 1; if (ReferenceEquals(this, obj)) return 0; diff --git a/src/Protocol/Models/Proposals/ISemanticTokenResult.cs b/src/Protocol/Models/Proposals/ISemanticTokenResult.cs index b4d57330e..32bd39062 100644 --- a/src/Protocol/Models/Proposals/ISemanticTokenResult.cs +++ b/src/Protocol/Models/Proposals/ISemanticTokenResult.cs @@ -13,6 +13,6 @@ public interface ISemanticTokenResult /// send a delta. /// [Optional] - public string ResultId { get; set; } + public string? ResultId { get; set; } } } diff --git a/src/Protocol/Models/Proposals/SemanticTokensFullOrDelta.cs b/src/Protocol/Models/Proposals/SemanticTokensFullOrDelta.cs index 1d43574bf..28effe4cb 100644 --- a/src/Protocol/Models/Proposals/SemanticTokensFullOrDelta.cs +++ b/src/Protocol/Models/Proposals/SemanticTokensFullOrDelta.cs @@ -27,14 +27,14 @@ public SemanticTokensFullOrDelta(SemanticTokensFullOrDeltaPartialResult partialR if (partialResult.IsDelta) { - Delta = new SemanticTokensDelta(partialResult.Delta) { - Edits = partialResult.Delta.Edits + Delta = new SemanticTokensDelta(partialResult.Delta!) { + Edits = partialResult.Delta!.Edits }; } if (partialResult.IsFull) { - Full = new SemanticTokens(partialResult.Full); + Full = new SemanticTokens(partialResult.Full!); } } diff --git a/src/Protocol/Models/Proposals/SemanticTokensFullOrDeltaPartialResult.cs b/src/Protocol/Models/Proposals/SemanticTokensFullOrDeltaPartialResult.cs index b4313ca02..400f3c7be 100644 --- a/src/Protocol/Models/Proposals/SemanticTokensFullOrDeltaPartialResult.cs +++ b/src/Protocol/Models/Proposals/SemanticTokensFullOrDeltaPartialResult.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters; diff --git a/src/Protocol/Models/TextDocumentIdentifier.cs b/src/Protocol/Models/TextDocumentIdentifier.cs index aadc30a6a..b4b7d50b9 100644 --- a/src/Protocol/Models/TextDocumentIdentifier.cs +++ b/src/Protocol/Models/TextDocumentIdentifier.cs @@ -32,7 +32,7 @@ public override bool Equals(object? obj) return Equals((TextDocumentIdentifier) obj); } - public override int GetHashCode() => Uri.GetHashCode(); + public override int GetHashCode() => Uri?.GetHashCode() ?? 0; public static bool operator ==(TextDocumentIdentifier left, TextDocumentIdentifier right) => Equals(left, right); @@ -42,7 +42,7 @@ public override bool Equals(object? obj) public static implicit operator TextDocumentIdentifier(string uri) => new TextDocumentIdentifier { Uri = uri }; - private string DebuggerDisplay => Uri?.ToString()!; + private string DebuggerDisplay => Uri?.ToString() ?? string.Empty; /// public override string ToString() => DebuggerDisplay; diff --git a/src/Protocol/Progress/IProgressManager.cs b/src/Protocol/Progress/IProgressManager.cs index da71c4e86..c445cd95b 100644 --- a/src/Protocol/Progress/IProgressManager.cs +++ b/src/Protocol/Progress/IProgressManager.cs @@ -22,7 +22,7 @@ IRequestProgressObservable MonitorUntil( IRequestProgressObservable, TResponse> MonitorUntil( IPartialItemsRequest request, Func, TResponse> factory, CancellationToken cancellationToken ) - where TResponse : IEnumerable; + where TResponse : IEnumerable?; IRequestProgressObservable MonitorUntil(IPartialItemsRequest, TItem> request, CancellationToken cancellationToken); @@ -30,6 +30,6 @@ IRequestProgressObservable, TResponse> MonitorUntil For(IPartialItemRequest request, CancellationToken cancellationToken); IProgressObserver> For(IPartialItemsRequest request, CancellationToken cancellationToken) - where TResponse : IEnumerable; + where TResponse : IEnumerable?; } } diff --git a/src/Protocol/Progress/ProgressManager.cs b/src/Protocol/Progress/ProgressManager.cs index e895bf679..a85887706 100644 --- a/src/Protocol/Progress/ProgressManager.cs +++ b/src/Protocol/Progress/ProgressManager.cs @@ -179,7 +179,7 @@ public IProgressObserver For(IPartialItemRequest> For(IPartialItemsRequest request, CancellationToken cancellationToken) - where TResponse : IEnumerable + where TResponse : IEnumerable? { if (request.PartialResultToken == null) return ProgressObserver>.Noop; if (_activeObservers.TryGetValue(request.PartialResultToken, out var o) && o is IProgressObserver> observer) diff --git a/src/Protocol/Serialization/Converters/ProgressTokenConverter.cs b/src/Protocol/Serialization/Converters/ProgressTokenConverter.cs index 35de548f6..60bafc9a1 100644 --- a/src/Protocol/Serialization/Converters/ProgressTokenConverter.cs +++ b/src/Protocol/Serialization/Converters/ProgressTokenConverter.cs @@ -4,16 +4,16 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters { - internal class ProgressTokenConverter : JsonConverter + internal class ProgressTokenConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, ProgressToken value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, ProgressToken? value, JsonSerializer serializer) { if (value.IsLong) serializer.Serialize(writer, value.Long); else if (value.IsString) serializer.Serialize(writer, value.String); else writer.WriteNull(); } - public override ProgressToken ReadJson(JsonReader reader, Type objectType, ProgressToken existingValue, bool hasExistingValue, JsonSerializer serializer) + public override ProgressToken? ReadJson(JsonReader reader, Type objectType, ProgressToken? existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Integer) { diff --git a/src/Protocol/Serialization/Converters/RangeOrPlaceholderRangeConverter.cs b/src/Protocol/Serialization/Converters/RangeOrPlaceholderRangeConverter.cs index f0d1e2504..89d10383e 100644 --- a/src/Protocol/Serialization/Converters/RangeOrPlaceholderRangeConverter.cs +++ b/src/Protocol/Serialization/Converters/RangeOrPlaceholderRangeConverter.cs @@ -6,15 +6,15 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters { - internal class RangeOrPlaceholderRangeConverter : JsonConverter + internal class RangeOrPlaceholderRangeConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, RangeOrPlaceholderRange value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, RangeOrPlaceholderRange? value, JsonSerializer serializer) { - if (value.IsRange) + if (value?.IsRange == true) { serializer.Serialize(writer, value.Range); } - else if (value.IsPlaceholderRange) + else if (value?.IsPlaceholderRange == true) { serializer.Serialize(writer, value.PlaceholderRange); } @@ -24,13 +24,13 @@ public override void WriteJson(JsonWriter writer, RangeOrPlaceholderRange value, } } - public override RangeOrPlaceholderRange ReadJson( - JsonReader reader, Type objectType, RangeOrPlaceholderRange existingValue, bool hasExistingValue, JsonSerializer serializer + public override RangeOrPlaceholderRange? ReadJson( + JsonReader reader, Type objectType, RangeOrPlaceholderRange? existingValue, bool hasExistingValue, JsonSerializer serializer ) { if (reader.TokenType is JsonToken.StartObject) { - var obj = JToken.ReadFrom(reader) as JObject; + var obj = (JToken.ReadFrom(reader) as JObject)!; return obj.ContainsKey("placeholder") ? new RangeOrPlaceholderRange(obj.ToObject()) : new RangeOrPlaceholderRange(obj.ToObject()); diff --git a/src/Protocol/Serialization/Converters/TextDocumentSyncConverter.cs b/src/Protocol/Serialization/Converters/TextDocumentSyncConverter.cs index 2aa25e1e2..22783b5d7 100644 --- a/src/Protocol/Serialization/Converters/TextDocumentSyncConverter.cs +++ b/src/Protocol/Serialization/Converters/TextDocumentSyncConverter.cs @@ -5,13 +5,13 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters { - internal class TextDocumentSyncConverter : JsonConverter + internal class TextDocumentSyncConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, TextDocumentSync value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, TextDocumentSync? value, JsonSerializer serializer) { if (value == null) { - writer.WriteNull(); + writer.WriteValue(TextDocumentSyncKind.None); return; } if (value.HasOptions) @@ -24,7 +24,7 @@ public override void WriteJson(JsonWriter writer, TextDocumentSync value, JsonSe } } - public override TextDocumentSync ReadJson(JsonReader reader, Type objectType, TextDocumentSync existingValue, bool hasExistingValue, JsonSerializer serializer) + public override TextDocumentSync ReadJson(JsonReader reader, Type objectType, TextDocumentSync? existingValue, bool hasExistingValue, JsonSerializer serializer) { switch (reader.TokenType) { diff --git a/src/Protocol/Shared/LspHandlerTypeDescriptor.cs b/src/Protocol/Shared/LspHandlerTypeDescriptor.cs index 70bb30552..c46721321 100644 --- a/src/Protocol/Shared/LspHandlerTypeDescriptor.cs +++ b/src/Protocol/Shared/LspHandlerTypeDescriptor.cs @@ -13,20 +13,28 @@ internal class LspHandlerTypeDescriptor : HandlerTypeDescriptor, ILspHandlerType { public LspHandlerTypeDescriptor(Type handlerType) : base(handlerType) { - PartialItemsType = ParamsType.GetInterfaces() - .FirstOrDefault(z => z.IsGenericType && typeof(IPartialItems<>).IsAssignableFrom(z.GetGenericTypeDefinition())) - ?.GetGenericArguments()[0]; + if (HasParamsType) + { + PartialItemsType = ParamsType!.GetInterfaces() + .FirstOrDefault(z => z.IsGenericType && typeof(IPartialItems<>).IsAssignableFrom(z.GetGenericTypeDefinition())) + ?.GetGenericArguments()[0]; + + PartialItemType = ParamsType.GetInterfaces() + .FirstOrDefault(z => z.IsGenericType && typeof(IPartialItem<>).IsAssignableFrom(z.GetGenericTypeDefinition())) + ?.GetGenericArguments()[0]; + } + HasPartialItems = PartialItemsType != null; - PartialItemType = ParamsType.GetInterfaces() - .FirstOrDefault(z => z.IsGenericType && typeof(IPartialItem<>).IsAssignableFrom(z.GetGenericTypeDefinition())) - ?.GetGenericArguments()[0]; HasPartialItem = PartialItemType != null; + RegistrationType = HandlerTypeDescriptorHelper.UnwrapGenericType(typeof(IRegistration<>), handlerType); HasRegistration = RegistrationType != null && RegistrationType != typeof(object); if (!HasRegistration) RegistrationType = null; + CapabilityType = HandlerTypeDescriptorHelper.UnwrapGenericType(typeof(ICapability<>), handlerType); HasCapability = CapabilityType != null; if (!HasCapability) CapabilityType = null; + if (HasCapability) IsDynamicCapability = typeof(IDynamicCapability).GetTypeInfo().IsAssignableFrom(CapabilityType); } diff --git a/src/Protocol/Workspace/Proposals/ISemanticTokensRefreshHandler.cs b/src/Protocol/Workspace/Proposals/ISemanticTokensRefreshHandler.cs index 003b39a55..e45700a23 100644 --- a/src/Protocol/Workspace/Proposals/ISemanticTokensRefreshHandler.cs +++ b/src/Protocol/Workspace/Proposals/ISemanticTokensRefreshHandler.cs @@ -20,9 +20,9 @@ public interface ISemanticTokensRefreshHandler : IJsonRpcRequestHandler Handle(SemanticTokensRefreshParams request, CancellationToken cancellationToken); - public void SetCapability(SemanticTokensCapability capability) => _capability = capability; + public void SetCapability(SemanticTokensCapability capability) => Capability = capability; } } diff --git a/src/Server/Configuration/ChainedConfigurationProvider.cs b/src/Server/Configuration/ChainedConfigurationProvider.cs index 3e5f17d96..538e96252 100644 --- a/src/Server/Configuration/ChainedConfigurationProvider.cs +++ b/src/Server/Configuration/ChainedConfigurationProvider.cs @@ -72,7 +72,7 @@ public void Load() { } /// The child keys. public IEnumerable GetChildKeys( IEnumerable earlierKeys, - string parentPath) + string? parentPath) { IConfiguration section = parentPath == null ? _config : _config.GetSection(parentPath); var children = section.GetChildren(); diff --git a/src/Server/Configuration/ChainedConfigurationSource.cs b/src/Server/Configuration/ChainedConfigurationSource.cs index 0c11fd844..d58949583 100644 --- a/src/Server/Configuration/ChainedConfigurationSource.cs +++ b/src/Server/Configuration/ChainedConfigurationSource.cs @@ -13,7 +13,7 @@ internal class ChainedConfigurationSource : IConfigurationSource /// /// The chained configuration. /// - public IConfiguration Configuration { get; set; } + public IConfiguration Configuration { get; set; } = null!; /// /// Whether the chained configuration should be disposed when the diff --git a/src/Server/LanguageServerServiceCollectionExtensions.cs b/src/Server/LanguageServerServiceCollectionExtensions.cs index fd6c0b305..07fde55cb 100644 --- a/src/Server/LanguageServerServiceCollectionExtensions.cs +++ b/src/Server/LanguageServerServiceCollectionExtensions.cs @@ -83,7 +83,7 @@ internal static IContainer AddLanguageServerInternals(this IContainer container, if (providedConfiguration != null) { - builder.CustomAddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration); + builder.CustomAddConfiguration((providedConfiguration.ImplementationInstance as IConfiguration)!); } return builder.CustomAddConfiguration(didChangeConfigurationProvider).Build(); diff --git a/src/Server/LanguageServerWorkspaceFolderManager.cs b/src/Server/LanguageServerWorkspaceFolderManager.cs index f68bcc55b..52214559f 100644 --- a/src/Server/LanguageServerWorkspaceFolderManager.cs +++ b/src/Server/LanguageServerWorkspaceFolderManager.cs @@ -50,17 +50,18 @@ Task IRequestHandler.Handle(DidChan return Unit.Task; } - async Task IOnLanguageServerStarted.OnStarted(ILanguageServer server, CancellationToken cancellationToken) + Task IOnLanguageServerStarted.OnStarted(ILanguageServer server, CancellationToken cancellationToken) { IsSupported = server.ClientSettings.Capabilities?.Workspace?.WorkspaceFolders.IsSupported == true; if (IsSupported) { - foreach (var folder in server.ClientSettings?.WorkspaceFolders ?? Enumerable.Empty()) + foreach (var folder in server.ClientSettings.WorkspaceFolders ?? Enumerable.Empty()) { _workspaceFolders.AddOrUpdate(folder.Uri, folder, (a, b) => folder); _workspaceFoldersChangedSubject.OnNext(new WorkspaceFolderChange(WorkspaceFolderEvent.Add, folder)); } } + return Task.CompletedTask; } public IObservable Refresh() => Observable.Create( diff --git a/src/Server/Pipelines/SemanticTokensDeltaPipeline.cs b/src/Server/Pipelines/SemanticTokensDeltaPipeline.cs index 84d3af053..a096b89dd 100644 --- a/src/Server/Pipelines/SemanticTokensDeltaPipeline.cs +++ b/src/Server/Pipelines/SemanticTokensDeltaPipeline.cs @@ -1,12 +1,16 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using MediatR; +using OmniSharp.Extensions.LanguageServer.Protocol; using OmniSharp.Extensions.LanguageServer.Protocol.Models.Proposals; namespace OmniSharp.Extensions.LanguageServer.Server.Pipelines { + [Obsolete(Constants.Proposal)] class SemanticTokensDeltaPipeline : IPipelineBehavior + where TRequest : notnull { public async Task Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate next) { @@ -25,12 +29,12 @@ public async Task Handle(TRequest request, CancellationToken cancella var response = await next().ConfigureAwait(false); if (GetResponse(semanticTokensDeltaParams, response, out var result)) { - if (result?.IsFull == true && string.IsNullOrEmpty(result.Value.Full.ResultId)) + if (result.Value.IsFull && string.IsNullOrEmpty(result.Value.Full!.ResultId)) { result.Value.Full.ResultId = semanticTokensDeltaParams.PreviousResultId; } - if (result?.IsDelta == true && string.IsNullOrEmpty(result.Value.Delta.ResultId)) + if (result.Value.IsDelta && string.IsNullOrEmpty(result.Value.Delta!.ResultId)) { result.Value.Delta.ResultId = semanticTokensDeltaParams.PreviousResultId; } @@ -41,7 +45,7 @@ public async Task Handle(TRequest request, CancellationToken cancella return await next().ConfigureAwait(false); } - private bool GetResponse(IRequest request, object response, out TR result) + private bool GetResponse(IRequest request, object? response, [NotNullWhen(true)] out TR result) { if (response is TR r) { @@ -49,7 +53,7 @@ private bool GetResponse(IRequest request, object response, out TR resul return true; } - result = default; + result = default!; return false; } } diff --git a/src/Shared/SharedHandlerCollection.cs b/src/Shared/SharedHandlerCollection.cs index 5f3d6df33..07919ccf4 100644 --- a/src/Shared/SharedHandlerCollection.cs +++ b/src/Shared/SharedHandlerCollection.cs @@ -61,7 +61,7 @@ public SharedHandlerCollection( IDisposable IHandlersManager.AddLink(string fromMethod, string toMethod) { var source = _descriptors.FirstOrDefault(z => z.Method == fromMethod); - if (source == null) + if (source is null) { if (_descriptors.Any(z => z.Method == toMethod)) { diff --git a/src/Testing/LanguageProtocolTestBase.cs b/src/Testing/LanguageProtocolTestBase.cs index 35a03d74d..77f5ae0a2 100644 --- a/src/Testing/LanguageProtocolTestBase.cs +++ b/src/Testing/LanguageProtocolTestBase.cs @@ -78,17 +78,16 @@ Action serverOptionsAction return ( _client, _server ); } - protected internal virtual async Task<(ILanguageClient client, ILanguageServer server)> Initialize( + protected internal virtual Task<(ILanguageClient client, ILanguageServer server)> Initialize( Action clientOptionsAction, Action serverOptionsAction ) { ( _client, _server ) = Create(clientOptionsAction, serverOptionsAction); - return await Observable.FromAsync(_client.Initialize).ForkJoin( - Observable.FromAsync(_server.Initialize), - (a, b) => ( _client, _server ) - ).ToTask(CancellationToken).ConfigureAwait(false); + return Observable.FromAsync(_client.Initialize) + .ForkJoin(Observable.FromAsync(_server.Initialize), (a, b) => ( client: _client!, server: _server! )) + .ToTask(CancellationToken); } protected virtual async Task<(ILanguageClient client, ILanguageServer server, TestConfigurationProvider configurationProvider)> InitializeWithConfiguration( diff --git a/test/Lsp.Tests/Matchers/ResolveCommandMatcherTests.cs b/test/Lsp.Tests/Matchers/ResolveCommandMatcherTests.cs index 03c6b3918..2d783b471 100644 --- a/test/Lsp.Tests/Matchers/ResolveCommandMatcherTests.cs +++ b/test/Lsp.Tests/Matchers/ResolveCommandMatcherTests.cs @@ -104,7 +104,7 @@ public void Should_Return_CodeLensResolve_Descriptor() new LspHandlerDescriptor( TextDocumentNames.CodeLensResolve, "Key", - resolveHandler, + resolveHandler!, resolveHandler.GetType(), typeof(CodeLens), null, @@ -118,7 +118,7 @@ public void Should_Return_CodeLensResolve_Descriptor() new LspHandlerDescriptor( TextDocumentNames.CodeLensResolve, "Key2", - resolveHandler2, + resolveHandler2!, typeof(ICodeLensResolveHandler), typeof(CodeLens), null, @@ -190,7 +190,7 @@ public void Should_Return_CompletionResolve_Descriptor() new LspHandlerDescriptor( TextDocumentNames.CompletionResolve, "Key", - resolveHandler, + resolveHandler!, resolveHandler.GetType(), typeof(CompletionItem), null, @@ -204,7 +204,7 @@ public void Should_Return_CompletionResolve_Descriptor() new LspHandlerDescriptor( TextDocumentNames.CompletionResolve, "Key2", - resolveHandler2, + resolveHandler2!, typeof(ICompletionResolveHandler), typeof(CompletionItem), null, @@ -239,7 +239,7 @@ public async Task Should_Update_CompletionItems_With_HandlerType() var descriptor = new LspHandlerDescriptor( TextDocumentNames.Completion, "Key", - resolveHandler as IJsonRpcHandler, + (resolveHandler as IJsonRpcHandler)!, resolveHandler.GetType(), typeof(CompletionParams), null, @@ -288,7 +288,7 @@ public async Task Should_Update_CodeLensContainer_With_HandlerType() var descriptor = new LspHandlerDescriptor( TextDocumentNames.CodeLens, "Key", - resolveHandler as IJsonRpcHandler, + (resolveHandler as IJsonRpcHandler)!, resolveHandler.GetType(), typeof(CodeLensParams), null, diff --git a/test/Lsp.Tests/SemanticTokensDocumentTests.cs b/test/Lsp.Tests/SemanticTokensDocumentTests.cs index f777de78c..0a6a8dc26 100644 --- a/test/Lsp.Tests/SemanticTokensDocumentTests.cs +++ b/test/Lsp.Tests/SemanticTokensDocumentTests.cs @@ -22,15 +22,14 @@ namespace Lsp.Tests public class SemanticTokensDocumentTests { private readonly ITestOutputHelper _testOutputHelper; - private readonly TestLoggerFactory _loggerFactory; private readonly ILogger _logger; private readonly SemanticTokensLegend _legend; public SemanticTokensDocumentTests(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; - _loggerFactory = new TestLoggerFactory(testOutputHelper); - _logger = _loggerFactory.CreateLogger(); + var loggerFactory = new TestLoggerFactory(testOutputHelper); + _logger = loggerFactory.CreateLogger(); _legend = new SemanticTokensLegend { // specify a specific set so that additions to the default list do not cause breaks in the tests. TokenModifiers = new[] { diff --git a/test/TestingUtils/AutoNSubstitute/TestLoggerFactory.cs b/test/TestingUtils/AutoNSubstitute/TestLoggerFactory.cs index 26e8b56ec..12a2f0b3b 100644 --- a/test/TestingUtils/AutoNSubstitute/TestLoggerFactory.cs +++ b/test/TestingUtils/AutoNSubstitute/TestLoggerFactory.cs @@ -27,7 +27,7 @@ public TestLoggerFactory( _loggerProvider = new SerilogLoggerProvider( new LoggerConfiguration() .MinimumLevel.Is(logEventLevel) - .WriteTo.TestOutput(_testOutputHelper) + .WriteTo.TestOutput(_testOutputHelper, outputTemplate: outputTemplate) .CreateLogger() ); }