diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/BreakpointSpanTests.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/BreakpointSpanTests.cs index 81eb2aa660..7cacf5c1d9 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/BreakpointSpanTests.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/BreakpointSpanTests.cs @@ -17,13 +17,15 @@ public class BreakpointSpanTests(ITestOutputHelper testOutputHelper) : AbstractR // Wait for classifications to indicate Razor LSP is up and running await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken); - await TestServices.Editor.SetTextAsync("

@{ var abc = 123; }

", ControlledHangMitigatingCancellationToken); - // Act - await TestServices.Debugger.SetBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 1, character: 1, ControlledHangMitigatingCancellationToken); + await TestServices.RazorProjectSystem.WaitForCSharpVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () => + { + await TestServices.Editor.SetTextAsync("

@{ var abc = 123; }

", ControlledHangMitigatingCancellationToken); + }, ControlledHangMitigatingCancellationToken); - // Assert - await TestServices.Debugger.VerifyBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 1, character: 7, ControlledHangMitigatingCancellationToken); + Assert.True(await TestServices.Debugger.SetBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 1, character: 1, ControlledHangMitigatingCancellationToken)); + + Assert.True(await TestServices.Debugger.VerifyBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 1, character: 7, ControlledHangMitigatingCancellationToken)); } [IdeFact] @@ -34,15 +36,17 @@ public class BreakpointSpanTests(ITestOutputHelper testOutputHelper) : AbstractR // Wait for classifications to indicate Razor LSP is up and running await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken); - await TestServices.Editor.SetTextAsync(@"

@{ - var abc = 123; -}

", ControlledHangMitigatingCancellationToken); - // Act - var result = await TestServices.Debugger.SetBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 1, character: 1, ControlledHangMitigatingCancellationToken); + await TestServices.RazorProjectSystem.WaitForCSharpVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () => + { + await TestServices.Editor.SetTextAsync(""" +

@{ + var abc = 123; + }

+ """, ControlledHangMitigatingCancellationToken); + }, ControlledHangMitigatingCancellationToken); - // Assert - Assert.False(result); + Assert.False(await TestServices.Debugger.SetBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 1, character: 1, ControlledHangMitigatingCancellationToken)); } [IdeFact] @@ -53,14 +57,18 @@ public class BreakpointSpanTests(ITestOutputHelper testOutputHelper) : AbstractR // Wait for classifications to indicate Razor LSP is up and running await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken); - await TestServices.Editor.SetTextAsync(@"

@{ - var abc = 123; -}

", ControlledHangMitigatingCancellationToken); - // Act - await TestServices.Debugger.SetBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 2, character: 1, ControlledHangMitigatingCancellationToken); + await TestServices.RazorProjectSystem.WaitForCSharpVirtualDocumentUpdateAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, async () => + { + await TestServices.Editor.SetTextAsync(""" +

@{ + var abc = 123; + }

+ """, ControlledHangMitigatingCancellationToken); + }, ControlledHangMitigatingCancellationToken); - // Assert - await TestServices.Debugger.VerifyBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 2, character: 4, ControlledHangMitigatingCancellationToken); + Assert.True(await TestServices.Debugger.SetBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 2, character: 1, ControlledHangMitigatingCancellationToken)); + + Assert.True(await TestServices.Debugger.VerifyBreakpointAsync(RazorProjectConstants.CounterRazorFile, line: 2, character: 5, ControlledHangMitigatingCancellationToken)); } } diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/DebuggerInProcess.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/DebuggerInProcess.cs index d8c08224a5..4d8c7f4529 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/DebuggerInProcess.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/DebuggerInProcess.cs @@ -39,7 +39,7 @@ internal partial class DebuggerInProcess foreach (EnvDTE.Breakpoint breakpoint in debugger.Breakpoints) { - if (breakpoint.File == fileName && + if (breakpoint.File.EndsWith(fileName) && breakpoint.FileLine == line && breakpoint.FileColumn == character) { diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/RazorProjectSystemInProcess.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/RazorProjectSystemInProcess.cs index 04f8659b0f..98b4f5c753 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/RazorProjectSystemInProcess.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/RazorProjectSystemInProcess.cs @@ -127,4 +127,43 @@ internal partial class RazorProjectSystemInProcess }, TimeSpan.FromMilliseconds(100), cancellationToken); } + + public async Task WaitForCSharpVirtualDocumentUpdateAsync(string projectName, string relativeFilePath, Func updater, CancellationToken cancellationToken) + { + var filePath = await TestServices.SolutionExplorer.GetAbsolutePathForProjectRelativeFilePathAsync(projectName, relativeFilePath, cancellationToken); + + var documentManager = await TestServices.Shell.GetComponentModelServiceAsync(cancellationToken); + + var uri = new Uri(filePath, UriKind.Absolute); + + long? desiredVersion = null; + + await Helper.RetryAsync(async ct => + { + if (documentManager.TryGetDocument(uri, out var snapshot)) + { + if (snapshot.TryGetVirtualDocument(out var virtualDocument)) + { + if (!virtualDocument.ProjectKey.IsUnknown && + virtualDocument.Snapshot.Length > 0) + { + if (desiredVersion is null) + { + desiredVersion = virtualDocument.HostDocumentSyncVersion + 1; + await updater(); + } + else if (virtualDocument.HostDocumentSyncVersion == desiredVersion) + { + return true; + } + } + + return false; + } + } + + return false; + + }, TimeSpan.FromMilliseconds(100), cancellationToken); + } }