Skip to content

Commit

Permalink
IEmbeddedLanguageClassificationService is optional in the workspaces …
Browse files Browse the repository at this point in the history
…layer

The default implementation of IEmbeddedLanguageClassificationService is
provided in the features layer, so make sure it is consumed as optional
in the workspaces layer.

Fixes dotnet#63921
  • Loading branch information
sharwell committed Mar 25, 2024
1 parent d87f6d4 commit 1cce499
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Workspaces/Core/Portable/Classification/Classifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ internal static IEnumerable<ClassifiedSpan> GetClassifiedSpans(
{
var projectServices = services.GetLanguageServices(semanticModel.Language);
var classificationService = projectServices.GetRequiredService<ISyntaxClassificationService>();
var embeddedLanguageService = projectServices.GetRequiredService<IEmbeddedLanguageClassificationService>();

var syntaxClassifiers = classificationService.GetDefaultSyntaxClassifiers();

Expand All @@ -94,8 +93,12 @@ internal static IEnumerable<ClassifiedSpan> GetClassifiedSpans(
classificationService.AddSemanticClassifications(semanticModel, textSpan, getNodeClassifiers, getTokenClassifiers, semanticClassifications, options, cancellationToken);

// intentionally adding to the semanticClassifications array here.
if (includedEmbeddedClassifications && project != null)
if (includedEmbeddedClassifications
&& project != null
&& projectServices.GetService<IEmbeddedLanguageClassificationService>() is { } embeddedLanguageService)
{
embeddedLanguageService.AddEmbeddedLanguageClassifications(services, project, semanticModel, textSpan, options, semanticClassifications, cancellationToken);
}

var allClassifications = new List<ClassifiedSpan>(semanticClassifications.Where(s => s.TextSpan.OverlapsWith(textSpan)));
var semanticSet = semanticClassifications.Select(s => s.TextSpan).ToSet();
Expand Down

0 comments on commit 1cce499

Please sign in to comment.