From e3d1c35e12c9550d3195bf3fe18b83011bb23342 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 19 Jul 2022 16:00:35 -0700 Subject: [PATCH 01/13] Update Roslyn to 4.4.0-1.22369.1 --- build/Packages.props | 2 +- global.json | 3 +- src/OmniSharp.Abstractions/Configuration.cs | 2 +- src/OmniSharp.Http.Driver/app.config | 10 ++-- .../app.config | 10 ++-- .../Completion/CompletionListBuilder_Async.cs | 6 +-- .../Completion/CompletionListBuilder_Sync.cs | 17 ++++--- .../Services/Completion/CompletionService.cs | 14 +++--- .../Workers/Formatting/FormattingWorker.cs | 47 ++++++++++++------- .../HostServicesAggregator.cs | 43 +++++++++++++++-- .../Utilities/CodeActionOptionsFactory.cs | 8 ++-- .../ExtractClassWorkspaceService.cs | 16 ++++--- .../OmniSharpLineFormattingOptionsProvider.cs | 33 +++++++++++++ src/OmniSharp.Stdio.Driver/app.config | 10 ++-- .../EditorConfigFacts.cs | 4 +- tests/app.config | 10 ++-- 16 files changed, 162 insertions(+), 73 deletions(-) create mode 100644 src/OmniSharp.Roslyn/WorkspaceServices/OmniSharpLineFormattingOptionsProvider.cs diff --git a/build/Packages.props b/build/Packages.props index 12fca60087..b2b1ac5a66 100644 --- a/build/Packages.props +++ b/build/Packages.props @@ -7,7 +7,7 @@ 17.2.0 17.0.0 6.3.0-preview.1.32 - 4.3.0-2.22267.5 + 4.4.0-1.22369.1 2.4.1 diff --git a/global.json b/global.json index 586ef8d4d9..909d8a8f3c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,6 @@ { "sdk": { - "version": "7.0.100-preview.4.22252.9" + "version": "7.0.100-preview.4.22252.9", + "rollForward": "patch" } } diff --git a/src/OmniSharp.Abstractions/Configuration.cs b/src/OmniSharp.Abstractions/Configuration.cs index 6d5484c10c..9236ee4381 100644 --- a/src/OmniSharp.Abstractions/Configuration.cs +++ b/src/OmniSharp.Abstractions/Configuration.cs @@ -4,7 +4,7 @@ internal static class Configuration { public static bool ZeroBasedIndices = false; - public const string RoslynVersion = "4.3.0.0"; + public const string RoslynVersion = "4.4.0.0"; public const string RoslynPublicKeyToken = "31bf3856ad364e35"; public readonly static string RoslynFeatures = GetRoslynAssemblyFullName("Microsoft.CodeAnalysis.Features"); diff --git a/src/OmniSharp.Http.Driver/app.config b/src/OmniSharp.Http.Driver/app.config index 24ab3d4192..de37867718 100644 --- a/src/OmniSharp.Http.Driver/app.config +++ b/src/OmniSharp.Http.Driver/app.config @@ -7,23 +7,23 @@ - + - + - + - + - + diff --git a/src/OmniSharp.LanguageServerProtocol/app.config b/src/OmniSharp.LanguageServerProtocol/app.config index 991918fe41..b9268318f4 100644 --- a/src/OmniSharp.LanguageServerProtocol/app.config +++ b/src/OmniSharp.LanguageServerProtocol/app.config @@ -7,23 +7,23 @@ - + - + - + - + - + diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Async.cs b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Async.cs index 9e6814f7cd..1543c7267e 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Async.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Async.cs @@ -28,14 +28,14 @@ internal static partial class CompletionListBuilder TextSpan typedSpan, bool expectingImportedItems, bool isSuggestionMode) { - var completionsBuilder = new List(completions.Items.Length); + var completionsBuilder = new List(completions.ItemsList.Count); var seenUnimportedCompletions = false; var commitCharacterRuleCache = new Dictionary, IReadOnlyList>(); var commitCharacterRuleBuilder = new HashSet(); - for (int i = 0; i < completions.Items.Length; i++) + for (int i = 0; i < completions.ItemsList.Count; i++) { - var completion = completions.Items[i]; + var completion = completions.ItemsList[i]; string labelText = completion.DisplayTextPrefix + completion.DisplayText + completion.DisplayTextSuffix; string? insertText; string? filterText = null; diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs index 087f7e3870..7c4982bbee 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs @@ -35,29 +35,32 @@ internal static partial class CompletionListBuilder bool expectingImportedItems, bool isSuggestionMode) { - var completionsBuilder = new List(completions.Items.Length); + var completionsBuilder = new List(completions.ItemsList.Count); var seenUnimportedCompletions = false; var commitCharacterRuleCache = new Dictionary, IReadOnlyList>(); var commitCharacterRuleBuilder = new HashSet(); - var completionTasksAndProviderNames = completions.Items.SelectAsArray((document, completionService), (completion, arg) => + var completionTasksAndProviderNamesBuilder = ImmutableArray.CreateBuilder<(Task?, string? providerName)>(); + for (int i = 0; i < completions.ItemsList.Count; i++) { + var completion = completions.ItemsList[i]; var providerName = completion.GetProviderName(); if (providerName is TypeImportCompletionProvider or ExtensionMethodImportCompletionProvider) { - return (null, providerName); + completionTasksAndProviderNamesBuilder.Add((null, providerName)); } else { - return ((Task?)arg.completionService.GetChangeAsync(arg.document, completion), providerName); + completionTasksAndProviderNamesBuilder.Add(((Task?)completionService.GetChangeAsync(document, completion), providerName)); } - }); + } + var completionTasksAndProviderNames = completionTasksAndProviderNamesBuilder.ToImmutable(); - for (int i = 0; i < completions.Items.Length; i++) + for (int i = 0; i < completions.ItemsList.Count; i++) { TextSpan changeSpan = typedSpan; - var completion = completions.Items[i]; + var completion = completions.ItemsList[i]; var insertTextFormat = InsertTextFormat.PlainText; string labelText = completion.DisplayTextPrefix + completion.DisplayText + completion.DisplayTextSuffix; List? additionalTextEdits = null; diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionService.cs index 5b685685de..5ff3d57078 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionService.cs @@ -94,17 +94,17 @@ public async Task Handle(CompletionRequest request, bool for var completions = await OmniSharpCompletionService.GetCompletionsAsync(completionService, document, position, trigger, roles: null, options, CancellationToken.None); _logger.LogTrace("Found {0} completions for {1}:{2},{3}", - completions?.Items.IsDefaultOrEmpty != false ? 0 : completions.Items.Length, + completions.ItemsList.Count, request.FileName, request.Line, request.Column); - if (completions is null || completions.Items.Length == 0) + if (completions is null || completions.ItemsList.Count == 0) { return new CompletionResponse { Items = ImmutableArray.Empty }; } - if (request.TriggerCharacter == ' ' && !completions.Items.Any(c => + if (request.TriggerCharacter == ' ' && !completions.ItemsList.Any(c => { var providerName = c.GetProviderName(); return providerName is CompletionListBuilder.OverrideCompletionProvider or @@ -166,14 +166,14 @@ public async Task Handle(CompletionResolveRequest req var index = request.Item.Data.Index; if (request.Item is null - || index >= completions.Items.Length + || index >= completions.ItemsList.Count || index < 0) { _logger.LogError("Received invalid completion resolve!"); return new CompletionResolveResponse { Item = request.Item }; } - var lastCompletionItem = completions.Items[index]; + var lastCompletionItem = completions.ItemsList[index]; if (lastCompletionItem.DisplayTextPrefix + lastCompletionItem.DisplayText + lastCompletionItem.DisplayTextSuffix != request.Item.Label) { _logger.LogError("Inconsistent completion data. Requested data on {0}, but found completion item {1}", request.Item.Label, lastCompletionItem.DisplayText); @@ -234,7 +234,7 @@ public async Task Handle(CompletionAfterInsertReq var index = request.Item.Data.Index; if (request.Item is null - || index >= completions.Items.Length + || index >= completions.ItemsList.Count || index < 0 || request.Item.TextEdit is null) { @@ -242,7 +242,7 @@ public async Task Handle(CompletionAfterInsertReq return new CompletionAfterInsertResponse(); } - var lastCompletionItem = completions.Items[index]; + var lastCompletionItem = completions.ItemsList[index]; if (lastCompletionItem.DisplayTextPrefix + lastCompletionItem.DisplayText + lastCompletionItem.DisplayTextSuffix != request.Item.Label) { _logger.LogError("Inconsistent completion data. Requested data on {0}, but found completion item {1}", request.Item.Label, lastCompletionItem.DisplayText); diff --git a/src/OmniSharp.Roslyn.CSharp/Workers/Formatting/FormattingWorker.cs b/src/OmniSharp.Roslyn.CSharp/Workers/Formatting/FormattingWorker.cs index b35e7adeb8..eac20568b4 100644 --- a/src/OmniSharp.Roslyn.CSharp/Workers/Formatting/FormattingWorker.cs +++ b/src/OmniSharp.Roslyn.CSharp/Workers/Formatting/FormattingWorker.cs @@ -5,15 +5,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using ICSharpCode.Decompiler.Util; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CSharp.Formatting; using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.DocumentationComments; using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Formatting; -using Microsoft.CodeAnalysis.Formatting; +using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Options; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using OmniSharp.Extensions; using OmniSharp.Models; using OmniSharp.Options; @@ -105,7 +103,7 @@ private static async Task FormatDocument(Document document, OmniSharpO { var spans = (textSpan != null) ? new[] { textSpan.Value } : null; var formattingOtions = await GetFormattingOptionsAsync(document, omnisharpOptions); - var newDocument = await OmniSharpFormatter.FormatAsync(document, spans, formattingOtions, CancellationToken.None); + var newDocument = await OmniSharpFormatter.FormatAsync(document, spans, formattingOtions, CancellationToken.None); if (omnisharpOptions.FormattingOptions.OrganizeImports) { var organizeImportsOptions = await GetOrganizeImportsOptionsAsync(document, omnisharpOptions); @@ -117,21 +115,29 @@ private static async Task FormatDocument(Document document, OmniSharpO // If we are not using .editorconfig for formatting options then we can avoid any overhead of calculating document options. internal static async ValueTask GetOrganizeImportsOptionsAsync(Document document, OmniSharpOptions omnisharpOptions) - => omnisharpOptions.FormattingOptions.EnableEditorConfigSupport - ? await OmniSharpOrganizeImportsOptionsWrapper.FromDocumentAsync(document, CancellationToken.None) - : WrapOrganizeImportsOptions(omnisharpOptions.FormattingOptions); + { + var fallbackOptions = WrapOrganizeImportsOptions(omnisharpOptions.FormattingOptions); + return omnisharpOptions.FormattingOptions.EnableEditorConfigSupport + ? await OmniSharpOrganizeImportsOptionsWrapper.FromDocumentAsync(document, fallbackOptions, CancellationToken.None) + : fallbackOptions; + } // If we are not using .editorconfig for formatting options then we can avoid any overhead of calculating document options. internal static async ValueTask GetFormattingOptionsAsync(Document document, OmniSharpOptions omnisharpOptions) - => omnisharpOptions.FormattingOptions.EnableEditorConfigSupport - ? await OmniSharpSyntaxFormattingOptionsWrapper.FromDocumentAsync(document, CancellationToken.None) - : WrapFormattingOptions(omnisharpOptions.FormattingOptions); + { + var fallbackOptions = CreateLineFormattingOptions(omnisharpOptions.FormattingOptions); + return omnisharpOptions.FormattingOptions.EnableEditorConfigSupport + ? await OmniSharpSyntaxFormattingOptionsWrapper.FromDocumentAsync(document, fallbackOptions, CancellationToken.None) + : WrapFormattingOptions(omnisharpOptions.FormattingOptions); + } // If we are not using .editorconfig for formatting options then we can avoid any overhead of calculating document options. internal static async ValueTask GetDocumentationCommentOptionsAsync(Document document, OmniSharpOptions omnisharpOptions) - => omnisharpOptions.FormattingOptions.EnableEditorConfigSupport - ? await OmniSharpDocumentationCommentOptionsWrapper.FromDocumentAsync(document, autoXmlDocCommentGeneration: true, CancellationToken.None) - : WrapDocumentationCommentOptions(omnisharpOptions.FormattingOptions); + { + return omnisharpOptions.FormattingOptions.EnableEditorConfigSupport + ? await OmniSharpDocumentationCommentOptionsWrapper.FromDocumentAsync(document, autoXmlDocCommentGeneration: true, CancellationToken.None) + : WrapDocumentationCommentOptions(omnisharpOptions.FormattingOptions); + } private static OmniSharpOrganizeImportsOptionsWrapper WrapOrganizeImportsOptions(OmniSharp.Options.FormattingOptions options) => new( @@ -194,11 +200,16 @@ private static OmniSharpSyntaxFormattingOptionsWrapper WrapFormattingOptions(Omn newLineForClausesInQuery: options.NewLineForClausesInQuery); private static OmniSharpDocumentationCommentOptionsWrapper WrapDocumentationCommentOptions(OmniSharp.Options.FormattingOptions options) - => new( - autoXmlDocCommentGeneration: true, - tabSize: options.TabSize, - useTabs: options.UseTabs, - newLine: options.NewLine); + => new(autoXmlDocCommentGeneration: true, CreateLineFormattingOptions(options)); + + private static OmniSharpLineFormattingOptions CreateLineFormattingOptions(OmniSharp.Options.FormattingOptions options) + => new() + { + IndentationSize = options.IndentationSize, + TabSize = options.TabSize, + UseTabs = options.UseTabs, + NewLine = options.NewLine, + }; internal static OmniSharpLabelPositionOptions LabelPositionOptionForStringValue(string value) => value.ToUpper() switch diff --git a/src/OmniSharp.Roslyn/HostServicesAggregator.cs b/src/OmniSharp.Roslyn/HostServicesAggregator.cs index bf09d808cc..d699708216 100644 --- a/src/OmniSharp.Roslyn/HostServicesAggregator.cs +++ b/src/OmniSharp.Roslyn/HostServicesAggregator.cs @@ -2,10 +2,15 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; +using System.Composition.Hosting; +using System.Composition.Hosting.Core; +using System.Linq; using System.Reflection; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using OmniSharp.Options; using OmniSharp.Services; namespace OmniSharp @@ -13,11 +18,14 @@ namespace OmniSharp [Export] public class HostServicesAggregator { - private ImmutableArray _assemblies; + private readonly ImmutableArray _assemblies; + private readonly IOptionsMonitor _options; [ImportingConstructor] public HostServicesAggregator( - [ImportMany] IEnumerable hostServicesProviders, ILoggerFactory loggerFactory) + [ImportMany] IEnumerable hostServicesProviders, + ILoggerFactory loggerFactory, + IOptionsMonitor options = null) { var logger = loggerFactory.CreateLogger(); var builder = ImmutableHashSet.CreateBuilder(); @@ -54,11 +62,40 @@ public HostServicesAggregator( builder.Add(typeof(OmniSharpSymbolRenamedCodeActionOperationFactoryWorkspaceService).Assembly); _assemblies = builder.ToImmutableArray(); + _options = options; } public HostServices CreateHostServices() { - return MefHostServices.Create(_assemblies); + var config = new ContainerConfiguration() + .WithProvider(new MefValueProvider>(_options)) + .WithAssemblies(_assemblies.Distinct()); + return new MefHostServices(config.CreateContainer()); + } + + internal class MefValueProvider : ExportDescriptorProvider + { + private readonly T _item; + private readonly IDictionary _metadata; + + public MefValueProvider(T item, IDictionary metadata = null) + { + _item = item; + _metadata = metadata; + } + + public override IEnumerable GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor) + { + if (contract.ContractType == typeof(T)) + { + yield return new ExportDescriptorPromise( + contract, + origin: string.Empty, + isShared: true, + () => Enumerable.Empty(), + deps => ExportDescriptor.Create((context, operation) => _item, _metadata ?? new Dictionary())); + } + } } } } diff --git a/src/OmniSharp.Roslyn/Utilities/CodeActionOptionsFactory.cs b/src/OmniSharp.Roslyn/Utilities/CodeActionOptionsFactory.cs index 43a1ff2854..08887f1628 100644 --- a/src/OmniSharp.Roslyn/Utilities/CodeActionOptionsFactory.cs +++ b/src/OmniSharp.Roslyn/Utilities/CodeActionOptionsFactory.cs @@ -7,8 +7,10 @@ namespace OmniSharp.Roslyn.CodeActions internal static class CodeActionOptionsFactory { public static OmniSharpCodeActionOptions Create(OmniSharpOptions options) - => new(new OmniSharpImplementTypeOptions( - (OmniSharpImplementTypeInsertionBehavior)options.ImplementTypeOptions.InsertionBehavior, - (OmniSharpImplementTypePropertyGenerationBehavior)options.ImplementTypeOptions.PropertyGenerationBehavior)); + => new OmniSharpCodeActionOptions( + new OmniSharpImplementTypeOptions( + (OmniSharpImplementTypeInsertionBehavior)options.ImplementTypeOptions.InsertionBehavior, + (OmniSharpImplementTypePropertyGenerationBehavior)options.ImplementTypeOptions.PropertyGenerationBehavior), + OmniSharpLineFormattingOptionsProvider.CreateFromOptions(options)); } } diff --git a/src/OmniSharp.Roslyn/WorkspaceServices/ExtractClassWorkspaceService.cs b/src/OmniSharp.Roslyn/WorkspaceServices/ExtractClassWorkspaceService.cs index ecb60f5ee9..eed75d08ab 100644 --- a/src/OmniSharp.Roslyn/WorkspaceServices/ExtractClassWorkspaceService.cs +++ b/src/OmniSharp.Roslyn/WorkspaceServices/ExtractClassWorkspaceService.cs @@ -16,14 +16,16 @@ public ExtractClassWorkspaceService() { } - public Task GetExtractClassOptionsAsync(Document document, INamedTypeSymbol originalType, ISymbol selectedMember) + public Task GetExtractClassOptionsAsync(Document document, INamedTypeSymbol originalType, ImmutableArray selectedMembers) { - var symbolsToUse = selectedMember == null ? originalType.GetMembers().Where(member => member switch - { - IMethodSymbol methodSymbol => methodSymbol.MethodKind == MethodKind.Ordinary, - IFieldSymbol fieldSymbol => !fieldSymbol.IsImplicitlyDeclared, - _ => member.Kind == SymbolKind.Property || member.Kind == SymbolKind.Event - }) : new ISymbol[] { selectedMember }; + var symbolsToUse = selectedMembers.IsEmpty + ? originalType.GetMembers().Where(member => member switch + { + IMethodSymbol methodSymbol => methodSymbol.MethodKind == MethodKind.Ordinary, + IFieldSymbol fieldSymbol => !fieldSymbol.IsImplicitlyDeclared, + _ => member.Kind == SymbolKind.Property || member.Kind == SymbolKind.Event + }) + : selectedMembers; var memberAnalysisResults = symbolsToUse.Select(m => new OmniSharpExtractClassMemberAnalysisResult(m, makeAbstract: false)).ToImmutableArray(); const string name = "NewBaseType"; diff --git a/src/OmniSharp.Roslyn/WorkspaceServices/OmniSharpLineFormattingOptionsProvider.cs b/src/OmniSharp.Roslyn/WorkspaceServices/OmniSharpLineFormattingOptionsProvider.cs new file mode 100644 index 0000000000..f2442e65e9 --- /dev/null +++ b/src/OmniSharp.Roslyn/WorkspaceServices/OmniSharpLineFormattingOptionsProvider.cs @@ -0,0 +1,33 @@ +using System.Composition; +using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Options; +using Microsoft.Extensions.Options; +using OmniSharp.Options; + +namespace OmniSharp +{ + [Export(typeof(IOmniSharpLineFormattingOptionsProvider)), Shared] + public class OmniSharpLineFormattingOptionsProvider : IOmniSharpLineFormattingOptionsProvider + { + private readonly IOptionsMonitor _options; + + [ImportingConstructor] + public OmniSharpLineFormattingOptionsProvider(IOptionsMonitor options) + { + _options = options; + } + + OmniSharpLineFormattingOptions IOmniSharpLineFormattingOptionsProvider.GetLineFormattingOptions() + => _options is null + ? new OmniSharpLineFormattingOptions() + : CreateFromOptions(_options.CurrentValue); + + internal static OmniSharpLineFormattingOptions CreateFromOptions(OmniSharpOptions options) + => new() + { + IndentationSize = options.FormattingOptions.IndentationSize, + TabSize = options.FormattingOptions.TabSize, + UseTabs = options.FormattingOptions.UseTabs, + NewLine = options.FormattingOptions.NewLine, + }; + } +} diff --git a/src/OmniSharp.Stdio.Driver/app.config b/src/OmniSharp.Stdio.Driver/app.config index 24ab3d4192..de37867718 100644 --- a/src/OmniSharp.Stdio.Driver/app.config +++ b/src/OmniSharp.Stdio.Driver/app.config @@ -7,23 +7,23 @@ - + - + - + - + - + diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs index 11c2530901..39286de099 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs @@ -18,8 +18,8 @@ namespace OmniSharp.Roslyn.CSharp.Tests { public class EditorConfigFacts : AbstractTestFixture { - public EditorConfigFacts(ITestOutputHelper output) - : base(output) + public EditorConfigFacts(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/app.config b/tests/app.config index 71f57a112e..5b1948d89f 100644 --- a/tests/app.config +++ b/tests/app.config @@ -7,23 +7,23 @@ - + - + - + - + - + From 1de00dd47ab4ccf244fd2a14ae5207eb767ebace Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 29 Jun 2022 10:03:49 -0700 Subject: [PATCH 02/13] Update changelog --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebacaafdeb..8a951d6e8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,18 @@ All changes to the project will be documented in this file. ## [1.39.1] +* Update Roslyn to 4.3.0-3.22329.4 (PR: [#2416](https://github.com/OmniSharp/omnisharp-roslyn/pull/2416)) +* Return meaningful error when pinned SDK version is not found. ([[omnisharp-vscode#5128](https://github.com/OmniSharp/omnisharp-vscode/issues/5128), PR: [#2403](https://github.com/OmniSharp/omnisharp-roslyn/pull/2403)) * Added support for `nullable` ([#2292](https://github.com/OmniSharp/omnisharp-roslyn/issues/2292), PR: [#2406](https://github.com/OmniSharp/omnisharp-roslyn/pull/2406)) +* Removed nuget versioning reference from OmniSharp.Abstractions ([#2410](https://github.com/OmniSharp/omnisharp-roslyn/issues/2410), PR: [#2414](https://github.com/OmniSharp/omnisharp-roslyn/pull/2414)) +* Bump Newtonsoft.Json to 13.0.1 (PR: [#2415](https://github.com/OmniSharp/omnisharp-roslyn/pull/2415)) ## [1.39.0] - 2022-05-19 * Update Roslyn to 4.3.0-2.22267.5 (PR: [#2401](https://github.com/OmniSharp/omnisharp-roslyn/pull/2401)) -* Fixed run script for Mono ([OmniSharp/omnisharp-vscode#5181](https://github.com/OmniSharp/omnisharp-vscode/issues/5181), [OmniSharp/omnisharp-vscode#5179](https://github.com/OmniSharp/omnisharp-vscode/issues/5179), PR: [#2398](https://github.com/OmniSharp/omnisharp-roslyn/pull/2398)) +* Fixed run script for Mono ([omnisharp-vscode#5181](https://github.com/OmniSharp/omnisharp-vscode/issues/5181), [omnisharp-vscode#5179](https://github.com/OmniSharp/omnisharp-vscode/issues/5179), PR: [#2398](https://github.com/OmniSharp/omnisharp-roslyn/pull/2398)) * Fall back to /usr/lib/os-release if /etc/os-release doesn't exist (PR: [#2380](https://github.com/OmniSharp/omnisharp-roslyn/pull/2380)) * Added support for linux-musl-x64 and linux-musl-arm64 ([#2366](https://github.com/OmniSharp/omnisharp-roslyn/issues/2366), PR: [#2395](https://github.com/OmniSharp/omnisharp-roslyn/pull/2395)) -* Enable GoToDefinition for symbols in metadata documents ([OmniSharp/omnisharp-vscode#4818](https://github.com/OmniSharp/omnisharp-vscode/issues/4818), PR: [#2390](https://github.com/OmniSharp/omnisharp-roslyn/pull/2390)) +* Enable GoToDefinition for symbols in metadata documents ([omnisharp-vscode#4818](https://github.com/OmniSharp/omnisharp-vscode/issues/4818), PR: [#2390](https://github.com/OmniSharp/omnisharp-roslyn/pull/2390)) * Use human readable doc in lsp's signature help ([#2372](https://github.com/OmniSharp/omnisharp-roslyn/issues/2372), PR: [#2392](https://github.com/OmniSharp/omnisharp-roslyn/pull/2392)) * Add TextEdits support to InlayHints (PR: [#2385](https://github.com/OmniSharp/omnisharp-roslyn/pull/2385)) * Fix Equals of AutoCompleteResponse and simplify some code (PR: [#2362](https://github.com/OmniSharp/omnisharp-roslyn/pull/2362)) From fb1e841890797742859e98a074ad6b6788adcd83 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 19 Jul 2022 16:06:30 -0700 Subject: [PATCH 03/13] Add comment --- src/OmniSharp.Roslyn/HostServicesAggregator.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OmniSharp.Roslyn/HostServicesAggregator.cs b/src/OmniSharp.Roslyn/HostServicesAggregator.cs index d699708216..709510c6d0 100644 --- a/src/OmniSharp.Roslyn/HostServicesAggregator.cs +++ b/src/OmniSharp.Roslyn/HostServicesAggregator.cs @@ -68,6 +68,8 @@ public HostServicesAggregator( public HostServices CreateHostServices() { var config = new ContainerConfiguration() + // We smuggle the OmniSharpOptions from the Host container into the workspace services + // container so that we can provide global option fallbacks for LineFormattingOptions. .WithProvider(new MefValueProvider>(_options)) .WithAssemblies(_assemblies.Distinct()); return new MefHostServices(config.CreateContainer()); From 4b21028e5de2a759dd81a3832cbc7b203eef3bc6 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 19 Jul 2022 16:06:36 -0700 Subject: [PATCH 04/13] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a951d6e8d..d3377fa246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ All changes to the project will be documented in this file. ## [1.39.1] -* Update Roslyn to 4.3.0-3.22329.4 (PR: [#2416](https://github.com/OmniSharp/omnisharp-roslyn/pull/2416)) +* Update Roslyn to 4.4.0 1.22369.1 (PR: [#2420](https://github.com/OmniSharp/omnisharp-roslyn/pull/2420)) +* Simplify some code (PR: [#2370](https://github.com/OmniSharp/omnisharp-roslyn/pull/2370)) * Return meaningful error when pinned SDK version is not found. ([[omnisharp-vscode#5128](https://github.com/OmniSharp/omnisharp-vscode/issues/5128), PR: [#2403](https://github.com/OmniSharp/omnisharp-roslyn/pull/2403)) * Added support for `nullable` ([#2292](https://github.com/OmniSharp/omnisharp-roslyn/issues/2292), PR: [#2406](https://github.com/OmniSharp/omnisharp-roslyn/pull/2406)) * Removed nuget versioning reference from OmniSharp.Abstractions ([#2410](https://github.com/OmniSharp/omnisharp-roslyn/issues/2410), PR: [#2414](https://github.com/OmniSharp/omnisharp-roslyn/pull/2414)) From ea4f75b1bf2bbbd5570480fd5e898b6c2d72ada3 Mon Sep 17 00:00:00 2001 From: Filip W Date: Wed, 20 Jul 2022 09:42:56 +0200 Subject: [PATCH 05/13] updated test to csharp11 --- tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs b/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs index c9d10f2dda..c4fda182e3 100644 --- a/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs +++ b/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs @@ -17,7 +17,7 @@ public void DefaultLanguageVersionShouldBeLatest() var scriptProjectProvider = new ScriptProjectProvider(new ScriptOptions(), new OmniSharpEnvironment(), new LoggerFactory(), true, false); var scriptProjectInfo = scriptProjectProvider.CreateProject("test.csx", Enumerable.Empty(), Path.GetTempPath(), typeof(CommandLineScriptGlobals)); Assert.Equal(LanguageVersion.Latest, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).SpecifiedLanguageVersion); - Assert.Equal(LanguageVersion.CSharp10, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).LanguageVersion); + Assert.Equal(LanguageVersion.CSharp11, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).LanguageVersion); } } } From 65b3fb028d76d6ad48b5f54c58aaeefea4b3ac32 Mon Sep 17 00:00:00 2001 From: Filip W Date: Wed, 20 Jul 2022 09:43:08 +0200 Subject: [PATCH 06/13] Update src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs Co-authored-by: Fred Silberberg --- .../Services/Completion/CompletionListBuilder_Sync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs index 7c4982bbee..030fae68f8 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs @@ -55,7 +55,7 @@ internal static partial class CompletionListBuilder completionTasksAndProviderNamesBuilder.Add(((Task?)completionService.GetChangeAsync(document, completion), providerName)); } } - var completionTasksAndProviderNames = completionTasksAndProviderNamesBuilder.ToImmutable(); + var completionTasksAndProviderNames = completionTasksAndProviderNamesBuilder.MoveToImmutable(); for (int i = 0; i < completions.ItemsList.Count; i++) { From 02a47aaefa8ba20657c0d170e693d3b28449640f Mon Sep 17 00:00:00 2001 From: Filip W Date: Wed, 20 Jul 2022 10:35:36 +0200 Subject: [PATCH 07/13] Update CompletionListBuilder_Sync.cs --- .../Services/Completion/CompletionListBuilder_Sync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs index 030fae68f8..7c4982bbee 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs @@ -55,7 +55,7 @@ internal static partial class CompletionListBuilder completionTasksAndProviderNamesBuilder.Add(((Task?)completionService.GetChangeAsync(document, completion), providerName)); } } - var completionTasksAndProviderNames = completionTasksAndProviderNamesBuilder.MoveToImmutable(); + var completionTasksAndProviderNames = completionTasksAndProviderNamesBuilder.ToImmutable(); for (int i = 0; i < completions.ItemsList.Count; i++) { From eb26f159f248a33cf2ec33ceeb9ed4abaa0a0b7d Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Wed, 20 Jul 2022 22:32:35 -0700 Subject: [PATCH 08/13] Use a test fixture for async and import completion hosts. --- .../CompletionFacts.cs | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs index 9d2fc512b9..be2f09f55d 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs @@ -15,17 +15,21 @@ namespace OmniSharp.Roslyn.CSharp.Tests { - public class CompletionFacts : AbstractTestFixture + public class CompletionFacts : AbstractTestFixture, IClassFixture { private const int ImportCompletionTimeout = 2000; private readonly ILogger _logger; + private readonly CompletionFixture _completionFixture; private string EndpointName => OmniSharpEndpoints.Completion; - public CompletionFacts(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + public CompletionFacts(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture, CompletionFixture completionFixture) : base(output, sharedOmniSharpHostFixture) { this._logger = this.LoggerFactory.CreateLogger(); + completionFixture.ImportCompletionTestHost?.ClearWorkspace(); + completionFixture.ImportAndAsyncCompletionTestHost?.ClearWorkspace(); + this._completionFixture = completionFixture; } [Theory] @@ -145,7 +149,7 @@ public Class1() Assert.DoesNotContain("Guid", completions.Items.Select(c => c.TextEdit.NewText)); } - [Theory] + [Theory(Skip = "Test needs a fresh completion host, but there's a bug with host disposal causing resources not to be correctly freed and OOMs the test runners")] [InlineData("dummy.cs", true)] [InlineData("dummy.cs", false)] [InlineData("dummy.csx", true)] @@ -2289,19 +2293,35 @@ protected async Task ResolveCompletionAsync(Completio private OmniSharpTestHost GetImportCompletionHost() { - var testHost = CreateOmniSharpHost(configurationData: new[] { new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true") }); - testHost.AddFilesToWorkspace(); - return testHost; + if (_completionFixture.ImportCompletionTestHost != null) + { + return _completionFixture.ImportCompletionTestHost; + } + else + { + var testHost = CreateOmniSharpHost(configurationData: new[] { new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true") }); + testHost.AddFilesToWorkspace(); + _completionFixture.ImportCompletionTestHost = testHost; + return testHost; + } } private OmniSharpTestHost GetAsyncCompletionAndImportCompletionHost() { - var testHost = CreateOmniSharpHost(configurationData: new[] { - new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true"), - new KeyValuePair("RoslynExtensionsOptions:EnableAsyncCompletion", "true"), - }); - testHost.AddFilesToWorkspace(); - return testHost; + if (_completionFixture.ImportAndAsyncCompletionTestHost != null) + { + return _completionFixture.ImportAndAsyncCompletionTestHost; + } + else + { + var testHost = CreateOmniSharpHost(configurationData: new[] { + new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true"), + new KeyValuePair("RoslynExtensionsOptions:EnableAsyncCompletion", "true"), + }); + testHost.AddFilesToWorkspace(); + _completionFixture.ImportAndAsyncCompletionTestHost = testHost; + return testHost; + } } private Task AfterInsertResponse(CompletionItem completionItem, OmniSharpTestHost testHost) @@ -2328,4 +2348,17 @@ internal static class CompletionResponseExtensions { public static bool IsSuggestionMode(this CompletionItem item) => !item.CommitCharacters?.Contains(' ') ?? true; } + +#nullable enable + public sealed class CompletionFixture : IDisposable + { + public OmniSharpTestHost? ImportCompletionTestHost { get; set; } + public OmniSharpTestHost? ImportAndAsyncCompletionTestHost { get; set; } + + public void Dispose() + { + ImportCompletionTestHost?.Dispose(); + ImportAndAsyncCompletionTestHost?.Dispose(); + } + } } From 579814f9496cd460ea78cb926b9e5659cf91c7de Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Wed, 20 Jul 2022 23:22:58 -0700 Subject: [PATCH 09/13] Fix race condition with multithreaded tests. --- .../CompletionFacts.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs index be2f09f55d..6d4f33c7ea 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs @@ -2301,7 +2301,12 @@ private OmniSharpTestHost GetImportCompletionHost() { var testHost = CreateOmniSharpHost(configurationData: new[] { new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true") }); testHost.AddFilesToWorkspace(); - _completionFixture.ImportCompletionTestHost = testHost; + var result = Interlocked.CompareExchange(ref _completionFixture.ImportCompletionTestHost, testHost, null); + if (result != null) + { + testHost.Dispose(); + testHost = result; + } return testHost; } } @@ -2319,7 +2324,12 @@ private OmniSharpTestHost GetAsyncCompletionAndImportCompletionHost() new KeyValuePair("RoslynExtensionsOptions:EnableAsyncCompletion", "true"), }); testHost.AddFilesToWorkspace(); - _completionFixture.ImportAndAsyncCompletionTestHost = testHost; + var result = Interlocked.CompareExchange(ref _completionFixture.ImportCompletionTestHost, testHost, null); + if (result != null) + { + testHost.Dispose(); + testHost = result; + } return testHost; } } @@ -2352,8 +2362,8 @@ internal static class CompletionResponseExtensions #nullable enable public sealed class CompletionFixture : IDisposable { - public OmniSharpTestHost? ImportCompletionTestHost { get; set; } - public OmniSharpTestHost? ImportAndAsyncCompletionTestHost { get; set; } + public OmniSharpTestHost? ImportCompletionTestHost; + public OmniSharpTestHost? ImportAndAsyncCompletionTestHost; public void Dispose() { From 750a24462b1283111633110c7765561cda4bb570 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 21 Jul 2022 17:39:43 -0700 Subject: [PATCH 10/13] Cache References returned by TestUtility --- tests/TestUtility/TestHelpers.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/TestUtility/TestHelpers.cs b/tests/TestUtility/TestHelpers.cs index de7f6624b5..54bbd59ed9 100644 --- a/tests/TestUtility/TestHelpers.cs +++ b/tests/TestUtility/TestHelpers.cs @@ -97,8 +97,15 @@ public static IEnumerable AddProjectToWorkspace(OmniSharpWorkspace wo return projectsIds; } + private static ImmutableArray _references; + private static IEnumerable GetReferences() { + if (!_references.IsDefaultOrEmpty) + { + return _references; + } + // This is a bit messy. Essentially, we need to add all assemblies that type forwarders might point to. var assemblies = new[] { @@ -114,13 +121,14 @@ private static IEnumerable GetReferences() #endif }; - var references = assemblies + _references = assemblies .Where(a => a != null) .Select(a => a.Location) .Distinct() - .Select(l => MetadataReference.CreateFromFile(l)); + .Select(l => MetadataReference.CreateFromFile(l)) + .ToImmutableArray(); - return references; + return _references; } public static MSBuildInstance AddDotNetCoreToFakeInstance(this MSBuildInstance instance) From 2e0dbd9c86467da86511128ce5510f89729eaae9 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 21 Jul 2022 17:49:57 -0700 Subject: [PATCH 11/13] Revert "Fix race condition with multithreaded tests." This reverts commit 579814f9496cd460ea78cb926b9e5659cf91c7de. --- .../CompletionFacts.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs index 6d4f33c7ea..be2f09f55d 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs @@ -2301,12 +2301,7 @@ private OmniSharpTestHost GetImportCompletionHost() { var testHost = CreateOmniSharpHost(configurationData: new[] { new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true") }); testHost.AddFilesToWorkspace(); - var result = Interlocked.CompareExchange(ref _completionFixture.ImportCompletionTestHost, testHost, null); - if (result != null) - { - testHost.Dispose(); - testHost = result; - } + _completionFixture.ImportCompletionTestHost = testHost; return testHost; } } @@ -2324,12 +2319,7 @@ private OmniSharpTestHost GetAsyncCompletionAndImportCompletionHost() new KeyValuePair("RoslynExtensionsOptions:EnableAsyncCompletion", "true"), }); testHost.AddFilesToWorkspace(); - var result = Interlocked.CompareExchange(ref _completionFixture.ImportCompletionTestHost, testHost, null); - if (result != null) - { - testHost.Dispose(); - testHost = result; - } + _completionFixture.ImportAndAsyncCompletionTestHost = testHost; return testHost; } } @@ -2362,8 +2352,8 @@ internal static class CompletionResponseExtensions #nullable enable public sealed class CompletionFixture : IDisposable { - public OmniSharpTestHost? ImportCompletionTestHost; - public OmniSharpTestHost? ImportAndAsyncCompletionTestHost; + public OmniSharpTestHost? ImportCompletionTestHost { get; set; } + public OmniSharpTestHost? ImportAndAsyncCompletionTestHost { get; set; } public void Dispose() { From 75c6218eb42678600205c372db5f88e5f2992338 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 21 Jul 2022 17:50:38 -0700 Subject: [PATCH 12/13] Revert "Use a test fixture for async and import completion hosts." This reverts commit eb26f159f248a33cf2ec33ceeb9ed4abaa0a0b7d. --- .../CompletionFacts.cs | 57 ++++--------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs index be2f09f55d..9d2fc512b9 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs @@ -15,21 +15,17 @@ namespace OmniSharp.Roslyn.CSharp.Tests { - public class CompletionFacts : AbstractTestFixture, IClassFixture + public class CompletionFacts : AbstractTestFixture { private const int ImportCompletionTimeout = 2000; private readonly ILogger _logger; - private readonly CompletionFixture _completionFixture; private string EndpointName => OmniSharpEndpoints.Completion; - public CompletionFacts(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture, CompletionFixture completionFixture) + public CompletionFacts(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) : base(output, sharedOmniSharpHostFixture) { this._logger = this.LoggerFactory.CreateLogger(); - completionFixture.ImportCompletionTestHost?.ClearWorkspace(); - completionFixture.ImportAndAsyncCompletionTestHost?.ClearWorkspace(); - this._completionFixture = completionFixture; } [Theory] @@ -149,7 +145,7 @@ public Class1() Assert.DoesNotContain("Guid", completions.Items.Select(c => c.TextEdit.NewText)); } - [Theory(Skip = "Test needs a fresh completion host, but there's a bug with host disposal causing resources not to be correctly freed and OOMs the test runners")] + [Theory] [InlineData("dummy.cs", true)] [InlineData("dummy.cs", false)] [InlineData("dummy.csx", true)] @@ -2293,35 +2289,19 @@ protected async Task ResolveCompletionAsync(Completio private OmniSharpTestHost GetImportCompletionHost() { - if (_completionFixture.ImportCompletionTestHost != null) - { - return _completionFixture.ImportCompletionTestHost; - } - else - { - var testHost = CreateOmniSharpHost(configurationData: new[] { new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true") }); - testHost.AddFilesToWorkspace(); - _completionFixture.ImportCompletionTestHost = testHost; - return testHost; - } + var testHost = CreateOmniSharpHost(configurationData: new[] { new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true") }); + testHost.AddFilesToWorkspace(); + return testHost; } private OmniSharpTestHost GetAsyncCompletionAndImportCompletionHost() { - if (_completionFixture.ImportAndAsyncCompletionTestHost != null) - { - return _completionFixture.ImportAndAsyncCompletionTestHost; - } - else - { - var testHost = CreateOmniSharpHost(configurationData: new[] { - new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true"), - new KeyValuePair("RoslynExtensionsOptions:EnableAsyncCompletion", "true"), - }); - testHost.AddFilesToWorkspace(); - _completionFixture.ImportAndAsyncCompletionTestHost = testHost; - return testHost; - } + var testHost = CreateOmniSharpHost(configurationData: new[] { + new KeyValuePair("RoslynExtensionsOptions:EnableImportCompletion", "true"), + new KeyValuePair("RoslynExtensionsOptions:EnableAsyncCompletion", "true"), + }); + testHost.AddFilesToWorkspace(); + return testHost; } private Task AfterInsertResponse(CompletionItem completionItem, OmniSharpTestHost testHost) @@ -2348,17 +2328,4 @@ internal static class CompletionResponseExtensions { public static bool IsSuggestionMode(this CompletionItem item) => !item.CommitCharacters?.Contains(' ') ?? true; } - -#nullable enable - public sealed class CompletionFixture : IDisposable - { - public OmniSharpTestHost? ImportCompletionTestHost { get; set; } - public OmniSharpTestHost? ImportAndAsyncCompletionTestHost { get; set; } - - public void Dispose() - { - ImportCompletionTestHost?.Dispose(); - ImportAndAsyncCompletionTestHost?.Dispose(); - } - } } From 1a517f173f49c0e96cc9a26c980537db7ccce001 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Mon, 25 Jul 2022 13:19:06 -0700 Subject: [PATCH 13/13] Create CodeRefactoringContext with Options. --- .../Services/Refactoring/V2/BaseCodeActionService.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs index 6801c82b9c..f2f072a128 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/V2/BaseCodeActionService.cs @@ -184,13 +184,20 @@ private bool HasFix(CodeFixProvider codeFixProvider, string diagnosticId) private async Task CollectRefactoringActions(Document document, TextSpan span, List codeActions) { + var codeActionOptions = CodeActionOptionsFactory.Create(Options); var availableRefactorings = OrderedCodeRefactoringProviders.Value; foreach (var codeRefactoringProvider in availableRefactorings) { try { - var context = new CodeRefactoringContext(document, span, a => codeActions.Add(a), CancellationToken.None); + var context = OmniSharpCodeFixContextFactory.CreateCodeRefactoringContext( + document, + span, + (a, _) => codeActions.Add(a), + codeActionOptions, + CancellationToken.None); + await codeRefactoringProvider.ComputeRefactoringsAsync(context); } catch (Exception ex)