diff --git a/.editorconfig b/.editorconfig index 2bbdd48250..0aff6e75ca 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,12 @@ insert_final_newline = true indent_style = space indent_size = 4 +dotnet_diagnostic.VSTHRD002.severity = none +dotnet_diagnostic.VSTHRD003.severity = none +dotnet_diagnostic.VSTHRD105.severity = none +dotnet_diagnostic.VSTHRD110.severity = none +dotnet_diagnostic.VSTHRD200.severity = none + [*.cs] indent_size = 4 diff --git a/build/Packages.props b/build/Packages.props index 3046dae4dc..88cec7fc18 100644 --- a/build/Packages.props +++ b/build/Packages.props @@ -62,8 +62,8 @@ - - + + diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 872a17758d..24c2435a2c 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -36,7 +36,11 @@ protected override void DisposeCore(bool disposing) { if (RegisteredInstance != null) { - AppDomain.CurrentDomain.AssemblyResolve -= Resolve; + try + { + AppDomain.CurrentDomain.AssemblyResolve -= Resolve; + } + catch (AppDomainUnloadedException){ } // Ignore if the AppDomain is going away (like during a test in xunit) RegisteredInstance = null; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs index 793c32aa61..bfe2dc049a 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs @@ -19,7 +19,7 @@ namespace OmniSharp.LanguageServerProtocol.Handlers { - internal sealed class OmniSharpCodeActionHandler : CodeActionHandler, IExecuteCommandHandler + internal sealed class OmniSharpCodeActionHandler : CodeActionHandlerBase, IExecuteCommandHandler { public static IEnumerable Enumerate( RequestHandlers handlers, @@ -116,6 +116,11 @@ public override async Task Handle(CodeActionParams codeActions.Select(ca => new CommandOrCodeAction(ca))); } + public override Task Handle(CodeAction request, CancellationToken cancellationToken) + { + return Task.FromResult(request); + } + public async Task Handle(ExecuteCommandParams request, CancellationToken cancellationToken) { Debug.Assert(request.Command == "omnisharp/executeCodeAction"); diff --git a/src/OmniSharp.LanguageServerProtocol/LanguageProtocolInteropHandler.cs b/src/OmniSharp.LanguageServerProtocol/LanguageProtocolInteropHandler.cs index d211d9326f..cb61d19265 100644 --- a/src/OmniSharp.LanguageServerProtocol/LanguageProtocolInteropHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/LanguageProtocolInteropHandler.cs @@ -41,7 +41,7 @@ public static LanguageProtocolInteropHandler Factory( public class LanguageProtocolInteropHandler : LanguageProtocolInteropHandler { private readonly IPredicateHandler _languagePredicateHandler; - private readonly Lazy[]>>> _exports; + private readonly Lazy[]>> _exports; private readonly bool _hasLanguageProperty; private readonly bool _hasFileNameProperty; private readonly bool _canBeAggregated; @@ -60,11 +60,10 @@ public LanguageProtocolInteropHandler(IPredicateHandler languagePredicateHandler _canBeAggregated = typeof(IAggregateResponse).IsAssignableFrom(metadata.ResponseType); _updateBufferHandler = updateBufferHandler; - _exports = new Lazy[]>>>(() => - LoadExportHandlers(handlers)); + _exports = new Lazy[]>>(() =>LoadExportHandlers(handlers)); } - private Task[]>> LoadExportHandlers( + private Dictionary[]> LoadExportHandlers( IEnumerable> handlers) { var interfaceHandlers = handlers @@ -76,12 +75,12 @@ private Task[]>> LoadExp // .Select(plugin => (plugin.Config.Language, plugin)); // Group handlers by language and sort each group for consistency - return Task.FromResult(interfaceHandlers + return interfaceHandlers // .Concat(plugins) .GroupBy(export => export.Language, StringComparer.OrdinalIgnoreCase) .ToDictionary( group => group.Key, - group => group.OrderBy(g => g.Handler).Select(z => z.Handler).ToArray())); + group => group.OrderBy(g => g.Handler).Select(z => z.Handler).ToArray()); } public string EndpointName { get; } @@ -207,7 +206,7 @@ private async Task GetFirstNotEmptyResponseFromHandlers(IRequestHandler< private async Task HandleRequestForLanguage(string language, TRequest request) { - var exports = await _exports.Value; + var exports = _exports.Value; if (exports.TryGetValue(language, out var handlers)) { if (_canBeAggregated) @@ -229,7 +228,7 @@ private async Task HandleAllRequest(TRequest request) $"Must be able to aggregate the response to spread them out across all plugins for {EndpointName}"); } - var exports = await _exports.Value; + var exports = _exports.Value; IAggregateResponse aggregateResponse = null; var responses = new List>(); diff --git a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs index b7b4f04549..8a12a9d667 100644 --- a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs +++ b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs @@ -113,10 +113,18 @@ public void Dispose() _cancellationTokenSource?.Dispose(); } + private void Cancel() + { + try + { + _cancellationTokenSource.Cancel(); + } catch (ObjectDisposedException){} + } + public async Task Start() { var server = Server = await LanguageServer.From(_options); - server.Exit.Subscribe(Observer.Create(i => _cancellationTokenSource.Cancel())); + server.Exit.Subscribe(Observer.Create(i => Cancel())); var environment = _compositionHost.GetExport(); var logger = _compositionHost.GetExport().CreateLogger(); @@ -125,7 +133,7 @@ public async Task Start() Console.CancelKeyPress += (sender, e) => { - _cancellationTokenSource.Cancel(); + Cancel(); e.Cancel = true; }; @@ -135,13 +143,13 @@ public async Task Start() { var hostProcess = Process.GetProcessById(environment.HostProcessId); hostProcess.EnableRaisingEvents = true; - hostProcess.OnExit(() => _cancellationTokenSource.Cancel()); + hostProcess.OnExit(Cancel); } catch { // If the process dies before we get here then request shutdown // immediately - _cancellationTokenSource.Cancel(); + Cancel(); } } }