Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Razor.Slim.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"src\\Razor\\test\\Microsoft.CodeAnalysis.Remote.Razor.Test\\Microsoft.CodeAnalysis.Remote.Razor.Test.csproj",
"src\\Razor\\test\\Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test\\Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj",
"src\\Razor\\test\\Microsoft.VisualStudio.LanguageServices.Razor.Test\\Microsoft.VisualStudio.LanguageServices.Razor.Test.csproj",
"src\\Razor\\test\\Microsoft.VisualStudioCode.RazorExtension.Test\\Microsoft.VisualStudioCode.RazorExtension.Test.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Test.Common\\Microsoft.AspNetCore.Razor.Test.Common.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Utilities.Shared.Test\\Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Utilities.Shared\\Microsoft.AspNetCore.Razor.Utilities.Shared.csproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public abstract class CohostTestBase(ITestOutputHelper testOutputHelper) : Tooli
private TestIncompatibleProjectService _incompatibleProjectService = null!;
private RemoteClientInitializationOptions _clientInitializationOptions;
private RemoteClientLSPInitializationOptions _clientLSPInitializationOptions;
private IFilePathService? _filePathService;

private protected abstract IRemoteServiceInvoker RemoteServiceInvoker { get; }
private protected abstract IClientSettingsManager ClientSettingsManager { get; }
private protected abstract IFilePathService FilePathService { get; }

private protected TestIncompatibleProjectService IncompatibleProjectService => _incompatibleProjectService.AssumeNotNull();
private protected IFilePathService FilePathService => _filePathService.AssumeNotNull();
private protected RemoteLanguageServerFeatureOptions FeatureOptions => OOPExportProvider.GetExportedValue<RemoteLanguageServerFeatureOptions>();
private protected RemoteClientCapabilitiesService ClientCapabilitiesService => OOPExportProvider.GetExportedValue<RemoteClientCapabilitiesService>();
private protected RemoteSemanticTokensLegendService SemanticTokensLegendService => OOPExportProvider.GetExportedValue<RemoteSemanticTokensLegendService>();
Expand Down Expand Up @@ -92,8 +91,6 @@ protected override async Task InitializeAsync()
_clientLSPInitializationOptions = GetRemoteClientLSPInitializationOptions();
UpdateClientLSPInitializationOptions(c => c);

_filePathService = new RemoteFilePathService(FeatureOptions);

// Force initialization and creation of the remote workspace. It will be filled in later.
await RemoteWorkspaceProvider.TestAccessor.InitializeRemoteExportProviderBuilderAsync(Path.GetTempPath(), DisposalToken);
_ = RemoteWorkspaceProvider.Instance.GetWorkspace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.Remote;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Razor.Workspaces.Settings;
using Microsoft.VisualStudio.Composition;
using Microsoft.VisualStudio.Razor.Settings;
Expand All @@ -22,10 +23,12 @@ public abstract class CohostEndpointTestBase(ITestOutputHelper testOutputHelper)
{
private TestRemoteServiceInvoker? _remoteServiceInvoker;
private IClientSettingsManager? _clientSettingsManager;
private IFilePathService? _filePathService;

private protected override IRemoteServiceInvoker RemoteServiceInvoker => _remoteServiceInvoker.AssumeNotNull();
private protected TestRemoteServiceInvoker TestRemoteServiceInvoker => _remoteServiceInvoker.AssumeNotNull();
private protected override IClientSettingsManager ClientSettingsManager => _clientSettingsManager.AssumeNotNull();
private protected override IFilePathService FilePathService => _filePathService.AssumeNotNull();

/// <summary>
/// The export provider for Roslyn "devenv" services, if tests opt-in to using them
Expand All @@ -40,6 +43,8 @@ protected override async Task InitializeAsync()
AddDisposable(_remoteServiceInvoker);

_clientSettingsManager = new ClientSettingsManager([], null, null);

_filePathService = new VisualStudioFilePathService(FeatureOptions);
}

private protected override RemoteClientLSPInitializationOptions GetRemoteClientLSPInitializationOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;

public class CohostFindAllReferencesEndpointTest(ITestOutputHelper testOutputHelper) : CohostEndpointTestBase(testOutputHelper)
{
[Theory]
[CombinatorialData]
public Task FindCSharpMember(bool supportsVSExtensions)
[Fact]
public Task FindCSharpMember()
=> VerifyFindAllReferencesAsync("""
@{
string M()
Expand All @@ -33,12 +32,10 @@ string M()
@code {
private const string [|$$MyName|] = "David";
}
""",
supportsVSExtensions);
""");

[Theory]
[CombinatorialData]
public async Task ComponentAttribute(bool supportsVSExtensions)
[Fact]
public async Task ComponentAttribute()
{
TestCode input = """
<SurveyPrompt [|Ti$$tle|]="InputValue" />
Expand All @@ -56,13 +53,12 @@ @namespace SomeProject
}
""";

await VerifyFindAllReferencesAsync(input, supportsVSExtensions,
await VerifyFindAllReferencesAsync(input,
(FilePath("SurveyPrompt.razor"), surveyPrompt));
}

[Theory]
[CombinatorialData]
public async Task OtherCSharpFile(bool supportsVSExtensions)
[Fact]
public async Task OtherCSharpFile()
{
TestCode input = """
@code
Expand All @@ -86,18 +82,12 @@ public class OtherClass
}
""";

await VerifyFindAllReferencesAsync(input, supportsVSExtensions,
await VerifyFindAllReferencesAsync(input,
(FilePath("OtherClass.cs"), otherClass));
}

private async Task VerifyFindAllReferencesAsync(TestCode input, bool supportsVSExtensions, params (string fileName, TestCode testCode)[]? additionalFiles)
private async Task VerifyFindAllReferencesAsync(TestCode input, params (string fileName, TestCode testCode)[] additionalFiles)
{
UpdateClientLSPInitializationOptions(c =>
{
c.ClientCapabilities.SupportsVisualStudioExtensions = supportsVSExtensions;
return c;
});

var document = CreateProjectAndRazorDocument(input.Text, additionalFiles: [.. additionalFiles.Select(f => (f.fileName, f.testCode.Text))]);
var inputText = await document.GetTextAsync(DisposalToken);
var position = inputText.GetPosition(input.Position);
Expand All @@ -123,7 +113,6 @@ private async Task VerifyFindAllReferencesAsync(TestCode input, bool supportsVSE
{
if (result.TryGetFirst(out var referenceItem))
{
Assert.True(supportsVSExtensions);
if (referenceItem.DisplayPath is not null)
{
Assert.False(referenceItem.DisplayPath.EndsWith(".g.cs"));
Expand All @@ -134,10 +123,6 @@ private async Task VerifyFindAllReferencesAsync(TestCode input, bool supportsVSE
Assert.False(referenceItem.DocumentName.EndsWith(".g.cs"));
}
}
else
{
Assert.False(supportsVSExtensions);
}
}

foreach (var result in results)
Expand Down Expand Up @@ -171,7 +156,7 @@ private static string GetText(VSInternalReferenceItem referenceItem)
return string.Join("", classifiedText.Runs.Select(s => s.Text));
}

return referenceItem.Text.AssumeNotNull().ToString();
return referenceItem.Text.AssumeNotNull().ToString()!;
}

private static LspLocation GetLocation(SumType<VSInternalReferenceItem, LspLocation> r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ private async Task VerifyGoToDefinitionAsync(

var requestInvoker = new TestHtmlRequestInvoker([(Methods.TextDocumentDefinitionName, htmlResponse)]);

var filePathService = new VisualStudioFilePathService(FeatureOptions);
var endpoint = new CohostGoToDefinitionEndpoint(IncompatibleProjectService, RemoteServiceInvoker, requestInvoker, filePathService);
var endpoint = new CohostGoToDefinitionEndpoint(IncompatibleProjectService, RemoteServiceInvoker, requestInvoker, FilePathService);

var textDocumentPositionParams = new TextDocumentPositionParams
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public Task PageDirective()
""");

[Fact]
[System.ComponentModel.Description("Desc")]
public Task AttributeDirective()
=> VerifyInlayHintsAsync(
input: """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor;
using Microsoft.CodeAnalysis.Razor.Remote;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Razor.Workspaces.Settings;
using Microsoft.CodeAnalysis.Remote.Razor;
using Microsoft.VisualStudio.Composition;
Expand All @@ -18,10 +19,11 @@ public abstract class CohostEndpointTestBase(ITestOutputHelper testOutputHelper)
{
private IClientSettingsManager? _clientSettingsManager;
private VSCodeRemoteServiceInvoker? _remoteServiceInvoker;
private IFilePathService? _filePathService;

private protected override IRemoteServiceInvoker RemoteServiceInvoker => _remoteServiceInvoker.AssumeNotNull();

private protected override IClientSettingsManager ClientSettingsManager => _clientSettingsManager.AssumeNotNull();
private protected override IFilePathService FilePathService => _filePathService.AssumeNotNull();

/// <summary>
/// The export provider for Roslyn "devenv" services, if tests opt-in to using them
Expand All @@ -42,6 +44,8 @@ protected override async Task InitializeAsync()
AddDisposable(_remoteServiceInvoker);

_clientSettingsManager = new ClientSettingsManager();

_filePathService = new VSCodeFilePathService(FeatureOptions);
}

private protected override RemoteClientLSPInitializationOptions GetRemoteClientLSPInitializationOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public void Composes()

// There are known failures that are satisfied by Microsoft.CodeAnalysis.LanguageServer, which we don't reference
Assert.Collection(errors,
e => AssertEx.Equal("""
e => AssertEx.AssertEqualToleratingWhitespaceDifferences("""
Microsoft.CodeAnalysis.ExternalAccess.Pythia.PythiaSignatureHelpProvider.ctor(implementation): expected exactly 1 export matching constraints:
Contract name: Microsoft.CodeAnalysis.ExternalAccess.Pythia.Api.IPythiaSignatureHelpProviderImplementation
TypeIdentityName: Microsoft.CodeAnalysis.ExternalAccess.Pythia.Api.IPythiaSignatureHelpProviderImplementation
but found 0.
""", e),
e => AssertEx.Equal("""
e => AssertEx.AssertEqualToleratingWhitespaceDifferences("""
Microsoft.VisualStudioCode.RazorExtension.Services.WorkspaceService.ctor(loggerFactory): expected exactly 1 export matching constraints:
Contract name: Microsoft.Extensions.Logging.ILoggerFactory
TypeIdentityName: Microsoft.Extensions.Logging.ILoggerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO.Pipelines;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.Utilities;
Expand Down Expand Up @@ -56,7 +57,7 @@ public async Task TwoProjectsAdded_OneWithDynamicFiles_SchedulesOneTask()
Assert.Equal(1, listener.SerializeCalls[project2.Id]);
}

[Fact]
[ConditionalFact(Is.Windows)]
public async Task TwoProjectsAdded_SchedulesTwoTasks()
{
using var workspace = new AdhocWorkspace(CodeAnalysis.Host.Mef.MefHostServices.DefaultHost);
Expand Down Expand Up @@ -166,7 +167,7 @@ public async Task DocumentAdded_SchedulesTask()
Assert.Equal(1, listener.SerializeCalls[project.Id]);
}

[Fact]
[ConditionalFact(Is.Windows)]
public async Task DocumentAdded_WithDelay_SchedulesTwoTasks()
{
using var workspace = new AdhocWorkspace(CodeAnalysis.Host.Mef.MefHostServices.DefaultHost);
Expand Down Expand Up @@ -209,7 +210,7 @@ public async Task ProjectAddedAndRemoved_DeferredInitialization_NoTasks()
Assert.Empty(listener.SerializeCalls);
}

[Fact]
[ConditionalFact(Is.Windows)]
public async Task TestSerialization()
{
using var workspace = new AdhocWorkspace(CodeAnalysis.Host.Mef.MefHostServices.DefaultHost);
Expand Down