File: Options\LspOptionsTests.cs
Web Access
Project: ..\..\..\src\Features\LanguageServer\ProtocolUnitTests\Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests.csproj (Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
 
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.AddImport;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Editor.Test;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using Xunit.Abstractions;
 
namespace Microsoft.CodeAnalysis.LanguageServer.UnitTests.References;
public class LspOptionsTests : AbstractLanguageServerProtocolTests
{
    public LspOptionsTests(ITestOutputHelper? testOutputHelper) : base(testOutputHelper)
    {
    }
 
    protected override TestComposition Composition => EditorTestCompositions.LanguageServerProtocol
        .AddParts(typeof(TestDocumentTrackingService))
        .AddParts(typeof(TestWorkspaceRegistrationService));
 
    [Fact]
    public async Task TestCanRetrieveCSharpOptionsWithOnlyLspLayer()
    {
        var markup = "";
        await using var testLspServer = await CreateTestLspServerAsync(markup);
        var globalOptions = testLspServer.TestWorkspace.ExportProvider.GetExportedValue<IGlobalOptionService>();
        var project = testLspServer.GetCurrentSolution().Projects.Single().Services;
        Assert.NotNull(globalOptions.GetAddImportPlacementOptions(project));
        Assert.NotNull(globalOptions.GetCodeGenerationOptions(project));
        Assert.NotNull(globalOptions.GetCodeStyleOptions(project));
        Assert.NotNull(globalOptions.GetSyntaxFormattingOptions(project));
        Assert.NotNull(globalOptions.GetSimplifierOptions(project));
    }
 
    [Fact]
    public async Task TestCanRetrieveVisualBasicOptionsWithOnlyLspLayer()
    {
        var markup = "";
        await using var testLspServer = await CreateVisualBasicTestLspServerAsync(markup);
        var globalOptions = testLspServer.TestWorkspace.ExportProvider.GetExportedValue<IGlobalOptionService>();
        var project = testLspServer.GetCurrentSolution().Projects.Single().Services;
        Assert.NotNull(globalOptions.GetAddImportPlacementOptions(project));
        Assert.NotNull(globalOptions.GetCodeGenerationOptions(project));
        Assert.NotNull(globalOptions.GetCodeStyleOptions(project));
        Assert.NotNull(globalOptions.GetSyntaxFormattingOptions(project));
        Assert.NotNull(globalOptions.GetSimplifierOptions(project));
    }
}