Skip to content

Commit

Permalink
Fix issues with VSCode LSP EA causing handlers to fail to load
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Aug 9, 2024
1 parent 2158b59 commit e46fb2d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static async Task<ExportProvider> CreateExportProviderAsync(
var config = CompositionConfiguration.Create(catalog);

// Verify we only have expected errors.
ThrowOnUnexpectedErrors(config, logger);
ThrowOnUnexpectedErrors(config, catalog, logger);

// Prepare an ExportProvider factory based on this graph.
var exportProviderFactory = config.CreateExportProviderFactory();
Expand All @@ -75,7 +75,7 @@ public static async Task<ExportProvider> CreateExportProviderAsync(
return exportProvider;
}

private static void ThrowOnUnexpectedErrors(CompositionConfiguration configuration, ILogger logger)
private static void ThrowOnUnexpectedErrors(CompositionConfiguration configuration, ComposableCatalog catalog, ILogger logger)
{
// Verify that we have exactly the MEF errors that we expect. If we have less or more this needs to be updated to assert the expected behavior.
// Currently we are expecting the following:
Expand All @@ -87,15 +87,16 @@ private static void ThrowOnUnexpectedErrors(CompositionConfiguration configurati
// part definition Microsoft.CodeAnalysis.ExternalAccess.Pythia.PythiaSignatureHelpProvider
var erroredParts = configuration.CompositionErrors.FirstOrDefault()?.SelectMany(error => error.Parts).Select(part => part.Definition.Type.Name) ?? Enumerable.Empty<string>();
var expectedErroredParts = new string[] { "PythiaSignatureHelpProvider" };
if (erroredParts.Count() != expectedErroredParts.Length || !erroredParts.All(part => expectedErroredParts.Contains(part)))
if (erroredParts.Count() != expectedErroredParts.Length || !erroredParts.All(part => expectedErroredParts.Contains(part)) || !catalog.DiscoveredParts.DiscoveryErrors.IsEmpty)
{
try
{
catalog.DiscoveredParts.ThrowOnErrors();
configuration.ThrowOnErrors();
}
catch (CompositionFailedException ex)
{
// The ToString for the composition failed exception doesn't output a nice set of errors by default, so log it separately here.
// The ToString for the composition failed exception doesn't output a nice set of errors by default, so log it separately
logger.LogError($"Encountered errors in the MEF composition:{Environment.NewLine}{ex.ErrorsAsString}");
throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<ProjectReference Include="..\..\Features\ExternalAccess\AspNetCore\Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.csproj" />
<ProjectReference Include="..\ExternalAccess\VisualDiagnostics\Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.csproj" />
<ProjectReference Include="..\..\Tools\ExternalAccess\Xaml\Microsoft.CodeAnalysis.ExternalAccess.Xaml.csproj" />
<ProjectReference Include="..\ExternalAccess\CompilerDeveloperSDK\Microsoft.CodeAnalysis.ExternalAccess.CompilerDeveloperSDK.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Xaml;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false), MetadataAttribute]
internal sealed class ExportXamlLspServiceFactoryAttribute : ExportLspServiceFactoryAttribute
{
public ExportXamlLspServiceFactoryAttribute(Type type, WellKnownLspServerKinds serverKind = WellKnownLspServerKinds.Any)
[Obsolete("Use the constructor that takes only a type")]
public ExportXamlLspServiceFactoryAttribute(Type type, WellKnownLspServerKinds serverKind)
: base(type, ProtocolConstants.RoslynLspLanguagesContract, serverKind)
{
}

public ExportXamlLspServiceFactoryAttribute(Type type)
: base(type, ProtocolConstants.RoslynLspLanguagesContract)
{
}
}
3 changes: 2 additions & 1 deletion src/Tools/ExternalAccess/Xaml/InternalAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Microsoft.CodeAnalysis.ExternalAccess.Xaml.DescriptionService.DescriptionService
Microsoft.CodeAnalysis.ExternalAccess.Xaml.DescriptionService.GetDescriptionAsync(Microsoft.CodeAnalysis.ISymbol! symbol, Microsoft.CodeAnalysis.Project! project, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.TaggedText>!>!
Microsoft.CodeAnalysis.ExternalAccess.Xaml.DescriptionService.GetMarkupContent(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.TaggedText> tags, string! language, bool featureSupportsMarkdown) -> (string! content, bool isMarkdown)
Microsoft.CodeAnalysis.ExternalAccess.Xaml.ExportXamlLspServiceFactoryAttribute
Microsoft.CodeAnalysis.ExternalAccess.Xaml.ExportXamlLspServiceFactoryAttribute.ExportXamlLspServiceFactoryAttribute(System.Type! type, Microsoft.CodeAnalysis.LanguageServer.WellKnownLspServerKinds serverKind = Microsoft.CodeAnalysis.LanguageServer.WellKnownLspServerKinds.Any) -> void
Microsoft.CodeAnalysis.ExternalAccess.Xaml.ExportXamlLspServiceFactoryAttribute.ExportXamlLspServiceFactoryAttribute(System.Type! type) -> void
Microsoft.CodeAnalysis.ExternalAccess.Xaml.ExportXamlLspServiceFactoryAttribute.ExportXamlLspServiceFactoryAttribute(System.Type! type, Microsoft.CodeAnalysis.LanguageServer.WellKnownLspServerKinds serverKind) -> void
Microsoft.CodeAnalysis.ExternalAccess.Xaml.ExportXamlStatelessLspServiceAttribute
Microsoft.CodeAnalysis.ExternalAccess.Xaml.ExportXamlStatelessLspServiceAttribute.ExportXamlStatelessLspServiceAttribute(System.Type! handlerType) -> void
Microsoft.CodeAnalysis.ExternalAccess.Xaml.IClientCapabilityProvider
Expand Down

0 comments on commit e46fb2d

Please sign in to comment.