Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix issue where we were querying a linq expression over and over #73750

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ internal static class HostWorkspaceServicesExtensions
public static CodeAnalysis.Host.LanguageServices? GetProjectServices(
this SolutionServices workspaceServices, IContentType contentType)
{
foreach (var language in workspaceServices.SupportedLanguages)
foreach (var language in workspaceServices.SupportedLanguagesArray)
{
if (LanguageMatches(language, contentType, workspaceServices))
{
return workspaceServices.GetLanguageServices(language);
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Host;
Expand Down Expand Up @@ -86,7 +87,9 @@ internal virtual ITextFactoryService TextFactory
/// <summary>
/// A list of language names for supported language services.
/// </summary>
public virtual IEnumerable<string> SupportedLanguages => [];
public virtual IEnumerable<string> SupportedLanguages => SupportedLanguagesArray;

internal virtual ImmutableArray<string> SupportedLanguagesArray => [];

/// <summary>
/// Returns true if the language is supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.Host;
Expand Down Expand Up @@ -43,6 +44,9 @@ public TWorkspaceService GetRequiredService<TWorkspaceService>() where TWorkspac
public IEnumerable<string> SupportedLanguages
=> _services.SupportedLanguages;

internal ImmutableArray<string> SupportedLanguagesArray
=> _services.SupportedLanguagesArray;

/// <inheritdoc cref="HostWorkspaceServices.IsSupported"/>
public bool IsSupported(string languageName)
=> _services.IsSupported(languageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
private ImmutableDictionary<string, MefLanguageServices> _languageServicesMap
= ImmutableDictionary<string, MefLanguageServices>.Empty;

private ImmutableArray<string> _languages;

public MefWorkspaceServices(IMefHostExportProvider host, Workspace workspace)
{
_exportProvider = host;
Expand Down Expand Up @@ -86,29 +88,27 @@
return service != null;
}

private IEnumerable<string>? _languages;

private IEnumerable<string> GetSupportedLanguages()
internal override ImmutableArray<string> SupportedLanguagesArray

Check failure on line 91 in src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/MefWorkspaceServices.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/MefWorkspaceServices.cs#L91

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/MefWorkspaceServices.cs(91,50): error CS0115: (NETCORE_ENGINEERING_TELEMETRY=Build) 'MefWorkspaceServices.SupportedLanguagesArray': no suitable method found to override
{
if (_languages == null)
get
{
var list = _exportProvider.GetExports<ILanguageService, LanguageServiceMetadata>().Select(lz => lz.Metadata.Language).Concat(
_exportProvider.GetExports<ILanguageServiceFactory, LanguageServiceMetadata>().Select(lz => lz.Metadata.Language))
.Distinct();

Interlocked.CompareExchange(ref _languages, list, null);
}
var localLanguages = _languages;
if (localLanguages.IsDefault)
{
var list = _exportProvider.GetExports<ILanguageService, LanguageServiceMetadata>().Select(lz => lz.Metadata.Language).Concat(
_exportProvider.GetExports<ILanguageServiceFactory, LanguageServiceMetadata>().Select(lz => lz.Metadata.Language))
.Distinct()
.ToImmutableArray();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops.


return _languages;
}
ImmutableInterlocked.InterlockedCompareExchange(ref _languages, list, localLanguages);
}

public override IEnumerable<string> SupportedLanguages
{
get { return this.GetSupportedLanguages(); }
return _languages;
}
}

public override bool IsSupported(string languageName)
=> this.GetSupportedLanguages().Contains(languageName);
=> this.SupportedLanguagesArray.Contains(languageName);

public override HostLanguageServices GetLanguageServices(string languageName)
{
Expand Down
Loading