|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.Collections.Concurrent; |
| 6 | +using Microsoft.CodeAnalysis.LanguageServer.HostWorkspace; |
| 7 | +using Xunit.Abstractions; |
| 8 | + |
| 9 | +namespace Microsoft.CodeAnalysis.LanguageServer.UnitTests; |
| 10 | + |
| 11 | +public sealed class LanguageServerProjectSystemTests(ITestOutputHelper testOutputHelper) : AbstractLanguageServerHostTests(testOutputHelper) |
| 12 | +{ |
| 13 | + [Fact] |
| 14 | + public async Task OpenProjectsDoesNotLoadOrLogSharedProject() |
| 15 | + { |
| 16 | + await using var server = await CreateLanguageServerAsync(serverConfiguration: ServerConfigurationWithoutDevKit); |
| 17 | + var logMessages = new ConcurrentQueue<string>(); |
| 18 | + server.LogMessageReceived += logMessage => logMessages.Enqueue(logMessage.Message); |
| 19 | + var projectPath = TempRoot.CreateDirectory().CreateFile("Unsupported.shproj").Path; |
| 20 | + |
| 21 | + await server.OpenProjectsAsync([projectPath], CancellationToken.None); |
| 22 | + |
| 23 | + var projectSystem = server.GetRequiredLspService<LanguageServerProjectSystem>(); |
| 24 | + Assert.Empty(await projectSystem.GetTestAccessor().GetLoadedProjectPathsAsync()); |
| 25 | + Assert.Empty(server.GetRequiredLspService<LanguageServerWorkspaceFactory>().HostWorkspace.CurrentSolution.Projects); |
| 26 | + Assert.DoesNotContain(logMessages, message => IsUnsupportedProjectLog(message, projectPath)); |
| 27 | + } |
| 28 | + |
| 29 | + [Fact] |
| 30 | + public async Task OpenProjectsLogsUnsupportedProject() |
| 31 | + { |
| 32 | + await using var server = await CreateLanguageServerAsync(serverConfiguration: ServerConfigurationWithoutDevKit); |
| 33 | + var logMessages = new ConcurrentQueue<string>(); |
| 34 | + server.LogMessageReceived += logMessage => logMessages.Enqueue(logMessage.Message); |
| 35 | + var projectPath = TempRoot.CreateDirectory().CreateFile("Unsupported.unsupportedproj").Path; |
| 36 | + |
| 37 | + await server.OpenProjectsAsync([projectPath], CancellationToken.None); |
| 38 | + |
| 39 | + var projectSystem = server.GetRequiredLspService<LanguageServerProjectSystem>(); |
| 40 | + Assert.Empty(await projectSystem.GetTestAccessor().GetLoadedProjectPathsAsync()); |
| 41 | + Assert.Empty(server.GetRequiredLspService<LanguageServerWorkspaceFactory>().HostWorkspace.CurrentSolution.Projects); |
| 42 | + Assert.Contains(logMessages, message => IsUnsupportedProjectLog(message, projectPath)); |
| 43 | + } |
| 44 | + |
| 45 | + private static bool IsUnsupportedProjectLog(string message, string projectPath) |
| 46 | + => message.Contains($"Not loading project '{projectPath}' because its language is not supported.", StringComparison.Ordinal); |
| 47 | +} |
0 commit comments