Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,46 @@
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;

public abstract partial class AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest_NoEditor
{
public abstract partial class AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest_NoEditor
{
internal static (OptionKey2, object) SingleOption<T>(Option2<T> option, T enabled)
=> (new OptionKey2(option), enabled);
internal static (OptionKey2, object) SingleOption<T>(Option2<T> option, T enabled)
=> (new OptionKey2(option), enabled);

internal (OptionKey2, object) SingleOption<T>(PerLanguageOption2<T> option, T value)
=> (new OptionKey2(option, this.GetLanguage()), value);
internal (OptionKey2, object) SingleOption<T>(PerLanguageOption2<T> option, T value)
=> (new OptionKey2(option, this.GetLanguage()), value);

internal static (OptionKey2, object) SingleOption<T>(Option2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> SingleOption(option, new CodeStyleOption2<T>(enabled, notification));
internal static (OptionKey2, object) SingleOption<T>(Option2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> SingleOption(option, new CodeStyleOption2<T>(enabled, notification));

internal static (OptionKey2, object) SingleOption<T>(Option2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> (new OptionKey2(option), codeStyle);
internal static (OptionKey2, object) SingleOption<T>(Option2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> (new OptionKey2(option), codeStyle);

internal (OptionKey2, object) SingleOption<T>(PerLanguageOption2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> SingleOption(option, new CodeStyleOption2<T>(enabled, notification));
internal (OptionKey2, object) SingleOption<T>(PerLanguageOption2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> SingleOption(option, new CodeStyleOption2<T>(enabled, notification));

internal (OptionKey2, object) SingleOption<T>(PerLanguageOption2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> SingleOption(option, codeStyle, language: GetLanguage());
internal (OptionKey2, object) SingleOption<T>(PerLanguageOption2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> SingleOption(option, codeStyle, language: GetLanguage());

internal static (OptionKey2, object) SingleOption<T>(PerLanguageOption2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle, string language)
=> (new OptionKey2(option, language), codeStyle);
internal static (OptionKey2, object) SingleOption<T>(PerLanguageOption2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle, string language)
=> (new OptionKey2(option, language), codeStyle);

internal OptionsCollection Option<T>(Option2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> new OptionsCollection(GetLanguage()) { { option, enabled, notification } };
internal OptionsCollection Option<T>(Option2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> new OptionsCollection(GetLanguage()) { { option, enabled, notification } };

internal OptionsCollection Option<T>(Option2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> new OptionsCollection(GetLanguage()) { { option, codeStyle } };
internal OptionsCollection Option<T>(Option2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> new OptionsCollection(GetLanguage()) { { option, codeStyle } };

internal OptionsCollection Option<T>(PerLanguageOption2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> new OptionsCollection(GetLanguage()) { { option, enabled, notification } };
internal OptionsCollection Option<T>(PerLanguageOption2<CodeStyleOption2<T>> option, T enabled, NotificationOption2 notification)
=> new OptionsCollection(GetLanguage()) { { option, enabled, notification } };

internal OptionsCollection Option<T>(PerLanguageOption2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> new OptionsCollection(GetLanguage()) { { option, codeStyle } };
internal OptionsCollection Option<T>(PerLanguageOption2<CodeStyleOption2<T>> option, CodeStyleOption2<T> codeStyle)
=> new OptionsCollection(GetLanguage()) { { option, codeStyle } };

internal OptionsCollection Option<T>(Option2<T> option, T value)
=> new OptionsCollection(GetLanguage()) { { option, value } };
internal OptionsCollection Option<T>(Option2<T> option, T value)
=> new OptionsCollection(GetLanguage()) { { option, value } };

internal OptionsCollection Option<T>(PerLanguageOption2<T> option, T value)
=> new OptionsCollection(GetLanguage()) { { option, value } };
}
internal OptionsCollection Option<T>(PerLanguageOption2<T> option, T value)
=> new OptionsCollection(GetLanguage()) { { option, value } };
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,42 @@
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.Host
namespace Microsoft.CodeAnalysis.Host;

internal sealed partial class CodeStyleHostLanguageServices : HostLanguageServices
{
internal sealed partial class CodeStyleHostLanguageServices : HostLanguageServices
{
private static readonly ConditionalWeakTable<HostLanguageServices, CodeStyleHostLanguageServices> s_mappedLanguageServices =
new ConditionalWeakTable<HostLanguageServices, CodeStyleHostLanguageServices>();
private static readonly ConditionalWeakTable<string, MefHostExportProvider> s_exportProvidersByLanguageCache =
new ConditionalWeakTable<string, MefHostExportProvider>();
private static readonly ConditionalWeakTable<HostLanguageServices, CodeStyleHostLanguageServices> s_mappedLanguageServices =
new ConditionalWeakTable<HostLanguageServices, CodeStyleHostLanguageServices>();
private static readonly ConditionalWeakTable<string, MefHostExportProvider> s_exportProvidersByLanguageCache =
new ConditionalWeakTable<string, MefHostExportProvider>();

private readonly HostLanguageServices _hostLanguageServices;
private readonly HostLanguageServices _codeStyleLanguageServices;
private readonly HostLanguageServices _hostLanguageServices;
private readonly HostLanguageServices _codeStyleLanguageServices;

[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "This is the replacement API")]
private CodeStyleHostLanguageServices(HostLanguageServices hostLanguageServices)
{
_hostLanguageServices = hostLanguageServices;
[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "This is the replacement API")]
private CodeStyleHostLanguageServices(HostLanguageServices hostLanguageServices)
{
_hostLanguageServices = hostLanguageServices;

var exportProvider = s_exportProvidersByLanguageCache.GetValue(hostLanguageServices.Language, MefHostExportProvider.Create);
_codeStyleLanguageServices = new MefWorkspaceServices(exportProvider, hostLanguageServices.WorkspaceServices.Workspace)
.GetLanguageServices(hostLanguageServices.Language);
}
var exportProvider = s_exportProvidersByLanguageCache.GetValue(hostLanguageServices.Language, MefHostExportProvider.Create);
_codeStyleLanguageServices = new MefWorkspaceServices(exportProvider, hostLanguageServices.WorkspaceServices.Workspace)
.GetLanguageServices(hostLanguageServices.Language);
}

public static CodeStyleHostLanguageServices? GetMappedCodeStyleLanguageServices(HostLanguageServices? hostLanguageServices)
=> hostLanguageServices != null ? s_mappedLanguageServices.GetValue(hostLanguageServices, Create) : null;
public static CodeStyleHostLanguageServices? GetMappedCodeStyleLanguageServices(HostLanguageServices? hostLanguageServices)
=> hostLanguageServices != null ? s_mappedLanguageServices.GetValue(hostLanguageServices, Create) : null;

public static CodeStyleHostLanguageServices GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices)
=> s_mappedLanguageServices.GetValue(hostLanguageServices, Create);
public static CodeStyleHostLanguageServices GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices)
=> s_mappedLanguageServices.GetValue(hostLanguageServices, Create);

private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices)
=> new CodeStyleHostLanguageServices(hostLanguageServices);
private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices)
=> new CodeStyleHostLanguageServices(hostLanguageServices);

public override HostWorkspaceServices WorkspaceServices => _hostLanguageServices.WorkspaceServices;
public override HostWorkspaceServices WorkspaceServices => _hostLanguageServices.WorkspaceServices;

public override string Language => _hostLanguageServices.Language;
public override string Language => _hostLanguageServices.Language;

public override TLanguageService? GetService<TLanguageService>()
where TLanguageService : default
=> _codeStyleLanguageServices.GetService<TLanguageService>() ?? _hostLanguageServices.GetService<TLanguageService>();
}
public override TLanguageService? GetService<TLanguageService>()
where TLanguageService : default
=> _codeStyleLanguageServices.GetService<TLanguageService>() ?? _hostLanguageServices.GetService<TLanguageService>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,58 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.Host
namespace Microsoft.CodeAnalysis.Host;

internal sealed partial class CodeStyleHostLanguageServices : HostLanguageServices
{
internal sealed partial class CodeStyleHostLanguageServices : HostLanguageServices
private sealed class MefHostExportProvider : IMefHostExportProvider
{
private sealed class MefHostExportProvider : IMefHostExportProvider
{
private readonly CompositionHost _compositionContext;

private MefHostExportProvider(CompositionHost compositionContext)
=> _compositionContext = compositionContext;
private readonly CompositionHost _compositionContext;

public static MefHostExportProvider Create(string languageName)
{
var assemblies = CreateAssemblies(languageName);
var compositionConfiguration = new ContainerConfiguration().WithAssemblies(assemblies);
return new MefHostExportProvider(compositionConfiguration.CreateContainer());
}
private MefHostExportProvider(CompositionHost compositionContext)
=> _compositionContext = compositionContext;

private static ImmutableArray<Assembly> CreateAssemblies(string languageName)
{
using var disposer = ArrayBuilder<string>.GetInstance(out var assemblyNames);
public static MefHostExportProvider Create(string languageName)
{
var assemblies = CreateAssemblies(languageName);
var compositionConfiguration = new ContainerConfiguration().WithAssemblies(assemblies);
return new MefHostExportProvider(compositionConfiguration.CreateContainer());
}

assemblyNames.Add("Microsoft.CodeAnalysis.CodeStyle.Fixes");
switch (languageName)
{
case LanguageNames.CSharp:
assemblyNames.Add("Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes");
break;
private static ImmutableArray<Assembly> CreateAssemblies(string languageName)
{
using var disposer = ArrayBuilder<string>.GetInstance(out var assemblyNames);

case LanguageNames.VisualBasic:
assemblyNames.Add("Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes");
break;
}
assemblyNames.Add("Microsoft.CodeAnalysis.CodeStyle.Fixes");
switch (languageName)
{
case LanguageNames.CSharp:
assemblyNames.Add("Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes");
break;

return MefHostServices.DefaultAssemblies.Concat(
MefHostServicesHelpers.LoadNearbyAssemblies(assemblyNames));
case LanguageNames.VisualBasic:
assemblyNames.Add("Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes");
break;
}

IEnumerable<Lazy<TExtension>> IMefHostExportProvider.GetExports<TExtension>()
=> _compositionContext.GetExports<TExtension>().Select(e => new Lazy<TExtension>(() => e));
return MefHostServices.DefaultAssemblies.Concat(
MefHostServicesHelpers.LoadNearbyAssemblies(assemblyNames));
}

IEnumerable<Lazy<TExtension, TMetadata>> IMefHostExportProvider.GetExports<TExtension, TMetadata>()
{
var importer = new WithMetadataImporter<TExtension, TMetadata>();
_compositionContext.SatisfyImports(importer);
return importer.Exports;
}
IEnumerable<Lazy<TExtension>> IMefHostExportProvider.GetExports<TExtension>()
=> _compositionContext.GetExports<TExtension>().Select(e => new Lazy<TExtension>(() => e));

private sealed class WithMetadataImporter<TExtension, TMetadata>
{
[ImportMany]
public IEnumerable<Lazy<TExtension, TMetadata>> Exports { get; set; }
}
IEnumerable<Lazy<TExtension, TMetadata>> IMefHostExportProvider.GetExports<TExtension, TMetadata>()
{
var importer = new WithMetadataImporter<TExtension, TMetadata>();
_compositionContext.SatisfyImports(importer);
return importer.Exports;
}

private sealed class WithMetadataImporter<TExtension, TMetadata>
{
[ImportMany]
public IEnumerable<Lazy<TExtension, TMetadata>> Exports { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.SemanticModelReuse
namespace Microsoft.CodeAnalysis.SemanticModelReuse;

internal partial class SemanticModelReuseWorkspaceServiceFactory : IWorkspaceServiceFactory
{
internal partial class SemanticModelReuseWorkspaceServiceFactory : IWorkspaceServiceFactory
private sealed class SemanticModelReuseWorkspaceService : ISemanticModelReuseWorkspaceService
{
private sealed class SemanticModelReuseWorkspaceService : ISemanticModelReuseWorkspaceService
public SemanticModelReuseWorkspaceService(Workspace _)
{
public SemanticModelReuseWorkspaceService(Workspace _)
{
}
}

public ValueTask<SemanticModel> ReuseExistingSpeculativeModelAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
// TODO: port the GetSemanticModelForNodeAsync implementation from Workspaces layer,
// which currently relies on a bunch of internal APIs.
// For now, we fall back to the public API to fetch document's SemanticModel.
return document.GetRequiredSemanticModelAsync(cancellationToken);
}
public ValueTask<SemanticModel> ReuseExistingSpeculativeModelAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
// TODO: port the GetSemanticModelForNodeAsync implementation from Workspaces layer,
// which currently relies on a bunch of internal APIs.
// For now, we fall back to the public API to fetch document's SemanticModel.
return document.GetRequiredSemanticModelAsync(cancellationToken);
}
}
}
Loading
Loading