@@ -180,6 +180,34 @@ void M()
180180 Assert . Null ( GetMiscellaneousDocument ( testLspServer ) ) ;
181181 }
182182
183+ [ Theory , CombinatorialData ]
184+ public async Task TestLooseFile_RazorFile ( bool mutatingLspWorkspace )
185+ {
186+ var source = "<div></div>" ;
187+
188+ // Create a server that supports LSP misc files and verify no misc files present.
189+ await using var testLspServer = await CreateTestLspServerAsync ( string . Empty , mutatingLspWorkspace , new InitializationOptions { ServerKind = WellKnownLspServerKinds . CSharpVisualBasicLspServer } ) ;
190+ Assert . Null ( GetMiscellaneousDocument ( testLspServer ) ) ;
191+ Assert . Null ( GetMiscellaneousAdditionalDocument ( testLspServer ) ) ;
192+
193+ // Open an empty loose file and make a request to verify it gets added to the misc workspace.
194+ var looseFileUri = ProtocolConversions . CreateAbsoluteUri ( @"C:\SomeFile.razor" ) ;
195+ await testLspServer . OpenDocumentAsync ( looseFileUri , source ) . ConfigureAwait ( false ) ;
196+
197+ // Trigger a request and assert we got a file in the misc workspace.
198+ await AssertFileInMiscWorkspaceAsync ( testLspServer , looseFileUri ) . ConfigureAwait ( false ) ;
199+ Assert . Null ( GetMiscellaneousDocument ( testLspServer ) ) ;
200+ Assert . NotNull ( GetMiscellaneousAdditionalDocument ( testLspServer ) ) ;
201+
202+ // Trigger another request and assert we got a file in the misc workspace.
203+ await AssertFileInMiscWorkspaceAsync ( testLspServer , looseFileUri ) . ConfigureAwait ( false ) ;
204+ Assert . NotNull ( GetMiscellaneousAdditionalDocument ( testLspServer ) ) ;
205+
206+ await testLspServer . CloseDocumentAsync ( looseFileUri ) . ConfigureAwait ( false ) ;
207+ Assert . Null ( GetMiscellaneousDocument ( testLspServer ) ) ;
208+ Assert . Null ( GetMiscellaneousAdditionalDocument ( testLspServer ) ) ;
209+ }
210+
183211 [ Theory , CombinatorialData ]
184212 public async Task TestLooseFile_RequestedTwiceAndClosed ( bool mutatingLspWorkspace )
185213 {
@@ -306,7 +334,12 @@ private static async Task AssertFileInMainWorkspaceAsync(TestLspServer testLspSe
306334
307335 private static Document ? GetMiscellaneousDocument ( TestLspServer testLspServer )
308336 {
309- return testLspServer . GetManagerAccessor ( ) . GetLspMiscellaneousFilesWorkspace ( ) ! . CurrentSolution . Projects . SingleOrDefault ( ) ? . Documents . Single ( ) ;
337+ return testLspServer . GetManagerAccessor ( ) . GetLspMiscellaneousFilesWorkspace ( ) ! . CurrentSolution . Projects . SingleOrDefault ( ) ? . Documents . SingleOrDefault ( ) ;
338+ }
339+
340+ private static TextDocument ? GetMiscellaneousAdditionalDocument ( TestLspServer testLspServer )
341+ {
342+ return testLspServer . GetManagerAccessor ( ) . GetLspMiscellaneousFilesWorkspace ( ) ! . CurrentSolution . Projects . SingleOrDefault ( ) ? . AdditionalDocuments . SingleOrDefault ( ) ;
310343 }
311344
312345 private static async Task < LSP . Hover > RunGetHoverAsync ( TestLspServer testLspServer , LSP . Location caret )
0 commit comments