Skip to content

Commit

Permalink
prevent service fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed May 22, 2024
1 parent f6f7d32 commit 1eba0d9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
namespace Microsoft.CodeAnalysis.CSharp.Classification;

[ExportLanguageService(typeof(IClassificationService), LanguageNames.CSharp), Shared]
internal class CSharpEditorClassificationService : AbstractClassificationService
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class CSharpEditorClassificationService(
CSharpSyntaxClassificationService syntaxClassificationService) : AbstractClassificationService(syntaxClassificationService)
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpEditorClassificationService()
{
}

public override void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
=> ClassificationHelpers.AddLexicalClassifications(text, textSpan, result, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Microsoft.CodeAnalysis.CSharp.Classification;

[ExportLanguageService(typeof(ISyntaxClassificationService), LanguageNames.CSharp), Shared]
[ExportLanguageService(typeof(ISyntaxClassificationService), LanguageNames.CSharp), Export, Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class CSharpSyntaxClassificationService() : AbstractSyntaxClassificationService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

namespace Microsoft.CodeAnalysis.Classification;

internal abstract class AbstractClassificationService : IClassificationService
internal abstract class AbstractClassificationService(ISyntaxClassificationService syntaxClassificationService) : IClassificationService
{
private readonly ISyntaxClassificationService _syntaxClassificationService = syntaxClassificationService;

public abstract void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
public abstract ClassifiedSpan AdjustStaleClassification(SourceText text, ClassifiedSpan classifiedSpan);

Expand Down Expand Up @@ -192,8 +194,7 @@ public void AddSyntacticClassifications(
if (root is null)
return;

var classificationService = services.GetLanguageServices(root.Language).GetRequiredService<ISyntaxClassificationService>();
classificationService.AddSyntacticClassifications(root, textSpans, result, cancellationToken);
_syntaxClassificationService.AddSyntacticClassifications(root, textSpans, result, cancellationToken);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ namespace Microsoft.CodeAnalysis.Classification;

internal abstract partial class AbstractSyntaxClassificationService : ISyntaxClassificationService
{
protected AbstractSyntaxClassificationService()
{
}

public abstract void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
public abstract void AddSyntacticClassifications(SyntaxNode root, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ Imports Microsoft.CodeAnalysis.Classification
Imports Microsoft.CodeAnalysis.Classification.Classifiers
Imports Microsoft.CodeAnalysis.Collections
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.PooledObjects
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Classification.Classifiers

Namespace Microsoft.CodeAnalysis.VisualBasic.Classification
<ExportLanguageService(GetType(ISyntaxClassificationService), LanguageNames.VisualBasic), [Shared]>
<ExportLanguageService(GetType(ISyntaxClassificationService), LanguageNames.VisualBasic), Export, [Shared]>
Partial Friend Class VisualBasicSyntaxClassificationService
Inherits AbstractSyntaxClassificationService

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Classification

<ImportingConstructor>
<Obsolete(MefConstruction.ImportingConstructorMessage, True)>
Public Sub New()
Public Sub New(syntaxClassificationService As VisualBasicSyntaxClassificationService)
MyBase.New(syntaxClassificationService)
End Sub

Public Overrides Sub AddLexicalClassifications(text As SourceText, textSpan As TextSpan, result As SegmentedList(Of ClassifiedSpan), cancellationToken As CancellationToken)
Expand Down

0 comments on commit 1eba0d9

Please sign in to comment.