File: LanguageServer\TestRazorDocumentServiceProvider.cs
Web Access
Project: src\src\Razor\src\Razor\test\Microsoft.AspNetCore.Razor.Test.Common.Tooling\Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj (Microsoft.AspNetCore.Razor.Test.Common.Tooling)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
 
namespace Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
 
internal class TestRazorDocumentServiceProvider(IRazorMappingService mappingService) : IRazorDocumentServiceProvider
{
    private readonly IRazorMappingService _mappingService = mappingService;
 
    public bool CanApplyChange => true;
 
    public bool SupportDiagnostics => true;
 
    TService? IRazorDocumentServiceProvider.GetService<TService>() where TService : class
    {
        var serviceType = typeof(TService);
 
        if (serviceType == typeof(IRazorMappingService))
        {
            return (TService?)_mappingService;
        }
 
        if (serviceType == typeof(IRazorDocumentPropertiesService))
        {
            return (TService?)(IRazorDocumentPropertiesService)new TestRazorDocumentPropertiesService();
        }
 
        if (serviceType == typeof(IRazorMappingService))
        {
            return null;
        }
 
        return (this as TService).AssumeNotNull();
    }
 
    private class TestRazorDocumentPropertiesService : IRazorDocumentPropertiesService
    {
        public bool DesignTimeOnly => false;
 
        public string DiagnosticsLspClientName => "RazorCSharp";
    }
}