Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task PublishAsync(TextDocument document, SynchronizationResult sync
return;
}

_logger.LogDebug($"The html document for {document.FilePath} is {uri}");
_logger.LogDebug($"The html document for {document.FilePath} is {htmlDocument.Uri}");

await _joinableTaskContext.Factory.SwitchToMainThreadAsync(cancellationToken);

Expand All @@ -56,6 +56,6 @@ public async Task PublishAsync(TextDocument document, SynchronizationResult sync
VisualStudioTextChange[] changes = [new(0, htmlDocument.Snapshot.Length, htmlText)];
_documentManager.UpdateVirtualDocument<HtmlVirtualDocument>(uri, changes, documentSnapshot.Version, state: synchronizationResult.Checksum);

_logger.LogDebug($"Finished Html document generation for {document.FilePath} (into {uri})");
_logger.LogDebug($"Finished Html document generation for {document.FilePath} (into {htmlDocument.Uri})");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.Razor.Cohost;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
using Microsoft.CodeAnalysis.Razor.Telemetry;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;

Expand Down Expand Up @@ -102,6 +103,7 @@ private void UpdateTextDocumentUri<TRequest>(TRequest request, DocumentUri uri,
// We don't implement the endpoint that uses this, but it's the only other thing, at time of writing, in the LSP
// protocol library that isn't handled by the above two cases.
VSInternalRelatedDocumentParams vsInternalRelatedDocumentParams => vsInternalRelatedDocumentParams.TextDocument,
VSCodeActionParams vsCodeActionParams => vsCodeActionParams.TextDocument,
_ => null
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Threading;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.VisualStudio.Extensibility.Testing;
using Microsoft.VisualStudio.Extensibility.Testing;
using Xunit;
using Xunit.Sdk;
using Task = System.Threading.Tasks.Task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public override async Task InitializeAsync()
// fast pace of running integration tests, it's worth taking a slight delay at the start for a more reliable run.
TestServices.Input.Send("{ENTER}");

await Task.Delay(2500);

// Close the file we opened, just in case, so the test can start with a clean slate
await TestServices.Editor.CloseCodeFileAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.IndexRazorFile, saveFile: false, ControlledHangMitigatingCancellationToken);

Expand All @@ -96,7 +94,7 @@ private async Task<string> CreateAndOpenBlazorProjectAsync(CancellationToken can
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

await TestServices.SolutionExplorer.CloseSolutionAsync(ControlledHangMitigatingCancellationToken);
await TestServices.SolutionExplorer.CloseSolutionAndWaitAsync(cancellationToken);

var solutionPath = CreateTemporaryPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task SetBreakpoint_FirstCharacter_SpanAdjusts()
// Wait for classifications to indicate Razor LSP is up and running
await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

await TestServices.RazorProjectSystem.WaitForCSharpVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () =>
await TestServices.RazorProjectSystem.WaitForHtmlVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () =>
{
await TestServices.Editor.SetTextAsync("<p>@{ var abc = 123; }</p>", ControlledHangMitigatingCancellationToken);
}, ControlledHangMitigatingCancellationToken);
Expand All @@ -37,7 +37,7 @@ public async Task SetBreakpoint_FirstCharacter_InvalidLine()
// Wait for classifications to indicate Razor LSP is up and running
await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

await TestServices.RazorProjectSystem.WaitForCSharpVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () =>
await TestServices.RazorProjectSystem.WaitForHtmlVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () =>
{
await TestServices.Editor.SetTextAsync("""
<p>@{
Expand All @@ -58,7 +58,7 @@ public async Task SetBreakpoint_FirstCharacter_ValidLine()
// Wait for classifications to indicate Razor LSP is up and running
await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

await TestServices.RazorProjectSystem.WaitForCSharpVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () =>
await TestServices.RazorProjectSystem.WaitForHtmlVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () =>
{
await TestServices.Editor.SetTextAsync("""
<p>@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task CSharpCodeActionsTests_MakeExpressionBodiedMethod()
await TestServices.Editor.WaitForCurrentLineTextAsync("private void IncrementCount() => currentCount++;", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Roslyn add import feature is currently broken: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2576636")]
public async Task CSharpCodeActionsTests_FullyQualify()
{
// Open the file
Expand Down Expand Up @@ -59,7 +59,7 @@ await TestServices.Editor.SetTextAsync("""
await TestServices.Editor.WaitForCurrentLineTextAsync("var x = System.Data.ConflictOption.CompareAllSearchableValues;", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Roslyn add import feature is currently broken: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2576636")]
public async Task CSharpCodeActionsTests_AddUsing()
{
// Open the file
Expand Down Expand Up @@ -94,7 +94,7 @@ @using System.Data
""", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Roslyn add import feature is currently broken: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2576636")]
public async Task CSharpCodeActionsTests_AddUsing_WithTypo()
{
// Open the file
Expand Down Expand Up @@ -128,7 +128,7 @@ @using System.Data
""", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Roslyn code refactoring provider is not finding the expression in cohosting")]
public async Task CSharpCodeActionsTests_IntroduceLocal()
{
// Open the file
Expand Down Expand Up @@ -179,7 +179,7 @@ void M(string[] args)
""", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Roslyn code refactoring provider is not finding the expression in cohosting")]
public async Task CSharpCodeActionsTests_IntroduceLocal_All()
{
// Open the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Extensibility.Testing;
using Roslyn.Test.Utilities;
Expand Down Expand Up @@ -603,19 +604,28 @@ await TestServices.SolutionExplorer.AddFileAsync(

private async Task VerifyTypeAndCommitCompletionAsync(string input, string output, string search, string[] stringsToType, char? commitChar = null, string? expectedSelectedItemLabel = null)
{
const string CompletionTestFileName = "Completion.razor";

await TestServices.SolutionExplorer.AddFileAsync(
RazorProjectConstants.BlazorProjectName,
"Test.razor",
CompletionTestFileName,
input,
open: true,
ControlledHangMitigatingCancellationToken);

await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

var filePath = await TestServices.SolutionExplorer.GetAbsolutePathForProjectRelativeFilePathAsync(RazorProjectConstants.BlazorProjectName, CompletionTestFileName, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.PlaceCaretAsync(search, charsOffset: 1, ControlledHangMitigatingCancellationToken);
foreach (var stringToType in stringsToType)
{
TestServices.Input.Send(stringToType);
await TestServices.RazorProjectSystem.WaitForHtmlVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, filePath, () =>
{
TestServices.Input.Send(stringToType);

return Task.CompletedTask;
}, ControlledHangMitigatingCancellationToken);
}

if (expectedSelectedItemLabel is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public async Task FindAllReferences_CSharpInRazor()
Assert.Equal(expected: "Counter.razor", Path.GetFileName(reference.DocumentName));
},
});

await TestServices.FindReferencesWindow.CloseToolWindowAsync(ControlledHangMitigatingCancellationToken);
}

[IdeFact]
Expand Down Expand Up @@ -88,6 +90,8 @@ public async Task FindAllReferences_ComponentAttribute_FromRazor()
Assert.Equal("public string? Title { get; set; }", reference.Code);
}
);

await TestServices.FindReferencesWindow.CloseToolWindowAsync(ControlledHangMitigatingCancellationToken);
}

[ConditionalSkipIdeFact(Issue = "https://github.com/dotnet/razor/issues/8036")]
Expand Down Expand Up @@ -127,6 +131,8 @@ public async Task FindAllReferences_ComponentAttribute_FromCSharpInRazor()
Assert.Equal(expected: "Title", reference.Code);
}
);

await TestServices.FindReferencesWindow.CloseToolWindowAsync(ControlledHangMitigatingCancellationToken);
}

[ConditionalSkipIdeFact(Issue = "https://github.com/dotnet/razor/issues/8036")]
Expand Down Expand Up @@ -201,6 +207,8 @@ await TestServices.SolutionExplorer.AddFileAsync(RazorProjectConstants.BlazorPro
Assert.Equal(expected: "MyPage.razor", Path.GetFileName(reference.DocumentName));
},
});

await TestServices.FindReferencesWindow.CloseToolWindowAsync(ControlledHangMitigatingCancellationToken);
}

private static IEnumerable<TableEntry> OrderResults(ImmutableArray<ITableEntryHandle2> results)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.Razor.IntegrationTests;

public class GoToDefinitionTests(ITestOutputHelper testOutputHelper) : AbstractRazorEditorTest(testOutputHelper)
{
[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_MethodInSameFile()
{
// Open the file
Expand All @@ -24,7 +24,7 @@ public async Task GoToDefinition_MethodInSameFile()
await TestServices.Editor.WaitForCurrentLineTextAsync("private void IncrementCount()", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_CSharpClass()
{
// Open the file
Expand All @@ -39,9 +39,11 @@ public async Task GoToDefinition_CSharpClass()

// Assert
await TestServices.Editor.WaitForActiveWindowAsync("Program.cs", ControlledHangMitigatingCancellationToken);

await TestServices.Editor.CloseCodeFileAsync(RazorProjectConstants.BlazorProjectName, "Program.cs", saveFile: false, ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_Component()
{
// Open the file
Expand All @@ -56,7 +58,7 @@ public async Task GoToDefinition_Component()
await TestServices.Editor.WaitForActiveWindowAsync("SurveyPrompt.razor", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_ComponentAttribute_InOtherRazorFile()
{
// Open the file
Expand All @@ -72,7 +74,7 @@ public async Task GoToDefinition_ComponentAttribute_InOtherRazorFile()
await TestServices.Editor.WaitForCurrentLineTextAsync("public string? Title { get; set; }", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_ComponentAttribute_InSameRazorFile()
{
// Create the file
Expand Down Expand Up @@ -102,7 +104,7 @@ await TestServices.SolutionExplorer.AddFileAsync(RazorProjectConstants.BlazorPro
await TestServices.Editor.WaitForCurrentLineTextAsync("public string? MyProperty { get; set; }", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_ComponentAttribute_Minimized()
{
// Create the file
Expand Down Expand Up @@ -292,7 +294,7 @@ await TestServices.SolutionExplorer.AddFileAsync(RazorProjectConstants.BlazorPro
await TestServices.Editor.WaitForCurrentLineTextAsync("public string FieldName { get; set; }", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_ComponentAttribute_BoundAttribute()
{
// Create the files
Expand Down Expand Up @@ -336,7 +338,7 @@ await TestServices.SolutionExplorer.AddFileAsync(RazorProjectConstants.BlazorPro
await TestServices.Editor.WaitForCurrentLineTextAsync("public string? Value { get; set; }", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToDefinition_ComponentAttribute_WriteOnlyProperty()
{
// Create the file
Expand Down Expand Up @@ -365,7 +367,7 @@ public string? MyProperty { set { } }
await TestServices.Editor.WaitForCurrentLineTextAsync("public string? MyProperty { set { } }", ControlledHangMitigatingCancellationToken);
}

[IdeTheory]
[IdeTheory(Skip = "Go To Def hangs prevents the Roslyn language server from shutting down for some reason")]
[InlineData("MyProperty:get")]
[InlineData("MyProperty:set")]
[InlineData("MyProperty:after")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.Razor.IntegrationTests;

public class GoToImplementationTests(ITestOutputHelper testOutputHelper) : AbstractRazorEditorTest(testOutputHelper)
{
[IdeFact]
[IdeFact(Skip = "Go To Impl hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToImplementation_SameFile()
{
// Open the file
Expand All @@ -24,7 +24,7 @@ public async Task GoToImplementation_SameFile()
await TestServices.Editor.WaitForCurrentLineTextAsync("private void IncrementCount()", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "Go To Impl hangs prevents the Roslyn language server from shutting down for some reason")]
public async Task GoToImplementation_CSharpClass()
{
// Open the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@ private async Task<IWpfTableControl2> GetFindReferencesWindowAsync(CancellationT
var tableControl = (IWpfTableControl2)tableControlField.GetValue(toolWindowControl);
return tableControl;
}

public async Task CloseToolWindowAsync(CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var shell = await GetRequiredGlobalServiceAsync<SVsUIShell, IVsUIShell>(cancellationToken);
ErrorHandler.ThrowOnFailure(shell.FindToolWindowEx((uint)__VSFINDTOOLWIN.FTW_fFindFirst, FindReferencesWindowGuid, dwToolWinId: 0, out var windowFrame));
ErrorHandler.ThrowOnFailure(windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public async Task WaitForLSPServerDeactivatedAsync(CancellationToken cancellatio

private async Task WaitForLSPServerActivationStatusAsync(bool active, CancellationToken cancellationToken)
{
if (await IsCohostingActiveAsync(cancellationToken))
{
return;
}

var tracker = await TestServices.Shell.GetComponentModelServiceAsync<ILspServerActivationTracker>(cancellationToken);
await Helper.RetryAsync(ct =>
{
Expand Down Expand Up @@ -126,25 +121,19 @@ public async Task<ImmutableArray<string>> GetProjectKeyIdsForProjectAsync(string
return projectManager.GetProjectKeysWithFilePath(projectFilePath).SelectAsArray(static key => key.Id);
}

public async Task WaitForCSharpVirtualDocumentAsync(string razorFilePath, CancellationToken cancellationToken)
public async Task WaitForHtmlVirtualDocumentAsync(string razorFilePath, CancellationToken cancellationToken)
{
if (await IsCohostingActiveAsync(cancellationToken))
{
return;
}

var documentManager = await TestServices.Shell.GetComponentModelServiceAsync<LSPDocumentManager>(cancellationToken);

var uri = new Uri(razorFilePath, UriKind.Absolute);
await Helper.RetryAsync(ct =>
{
if (documentManager.TryGetDocument(uri, out var snapshot))
{
if (snapshot.TryGetVirtualDocument<CSharpVirtualDocumentSnapshot>(out var virtualDocument))
if (snapshot.TryGetVirtualDocument<HtmlVirtualDocumentSnapshot>(out var virtualDocument))
{
var result = !virtualDocument.ProjectKey.IsUnknown &&
virtualDocument.Snapshot.Length > 0;
return Task.FromResult(result);
//var result = virtualDocument.Snapshot.Length > 0;
return Task.FromResult(true);
}
}

Expand All @@ -153,15 +142,8 @@ await Helper.RetryAsync(ct =>
}, TimeSpan.FromMilliseconds(100), cancellationToken);
}

public async Task WaitForCSharpVirtualDocumentUpdateAsync(string projectName, string relativeFilePath, Func<Task> updater, CancellationToken cancellationToken)
public async Task WaitForHtmlVirtualDocumentUpdateAsync(string projectName, string relativeFilePath, Func<Task> updater, CancellationToken cancellationToken)
{
if (await IsCohostingActiveAsync(cancellationToken))
{
// In cohosting we don't wait for anything, we just update the Razor doc and assume that Roslyn will do the right things
await updater();
return;
}

var filePath = await TestServices.SolutionExplorer.GetAbsolutePathForProjectRelativeFilePathAsync(projectName, relativeFilePath, cancellationToken);

var documentManager = await TestServices.Shell.GetComponentModelServiceAsync<LSPDocumentManager>(cancellationToken);
Expand All @@ -174,10 +156,9 @@ await Helper.RetryAsync(async ct =>
{
if (documentManager.TryGetDocument(uri, out var snapshot))
{
if (snapshot.TryGetVirtualDocument<CSharpVirtualDocumentSnapshot>(out var virtualDocument))
if (snapshot.TryGetVirtualDocument<HtmlVirtualDocumentSnapshot>(out var virtualDocument))
{
if (!virtualDocument.ProjectKey.IsUnknown &&
virtualDocument.Snapshot.Length > 0)
if (virtualDocument.Snapshot.Length > 0)
{
if (desiredVersion is null)
{
Expand Down
Loading
Loading