@@ -31,10 +31,13 @@ import org.eclipse.lsp4j.CreateFilesParams
3131import org.eclipse.lsp4j.DeleteFilesParams
3232import org.eclipse.lsp4j.DidChangeWatchedFilesParams
3333import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams
34+ import org.eclipse.lsp4j.DidCloseTextDocumentParams
35+ import org.eclipse.lsp4j.DidOpenTextDocumentParams
3436import org.eclipse.lsp4j.FileChangeType
3537import org.eclipse.lsp4j.RenameFilesParams
3638import org.eclipse.lsp4j.WorkspaceFolder
3739import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage
40+ import org.eclipse.lsp4j.services.TextDocumentService
3841import org.eclipse.lsp4j.services.WorkspaceService
3942import org.junit.jupiter.api.BeforeEach
4043import org.junit.jupiter.api.Test
@@ -50,13 +53,15 @@ class WorkspaceServiceHandlerTest {
5053 private lateinit var project: Project
5154 private lateinit var mockLanguageServer: AmazonQLanguageServer
5255 private lateinit var mockWorkspaceService: WorkspaceService
56+ private lateinit var mockTextDocumentService: TextDocumentService
5357 private lateinit var sut: WorkspaceServiceHandler
5458 private lateinit var mockApplication: Application
5559
5660 @BeforeEach
5761 fun setup () {
5862 project = mockk<Project >()
5963 mockWorkspaceService = mockk<WorkspaceService >()
64+ mockTextDocumentService = mockk<TextDocumentService >()
6065 mockLanguageServer = mockk<AmazonQLanguageServer >()
6166
6267 mockApplication = mockk<Application >()
@@ -89,6 +94,11 @@ class WorkspaceServiceHandlerTest {
8994 every { mockWorkspaceService.didChangeWatchedFiles(any()) } returns Unit
9095 every { mockWorkspaceService.didChangeWorkspaceFolders(any()) } returns Unit
9196
97+ // Mock textDocument service (for didRename calls)
98+ every { mockLanguageServer.textDocumentService } returns mockTextDocumentService
99+ every { mockTextDocumentService.didOpen(any()) } returns Unit
100+ every { mockTextDocumentService.didClose(any()) } returns Unit
101+
92102 // Mock message bus
93103 val messageBus = mockk<MessageBus >()
94104 every { project.messageBus } returns messageBus
@@ -389,6 +399,15 @@ class WorkspaceServiceHandlerTest {
389399 // Act
390400 sut.after(listOf (propertyEvent))
391401
402+ val closeParams = slot<DidCloseTextDocumentParams >()
403+ verify { mockTextDocumentService.didClose(capture(closeParams)) }
404+ assertThat(closeParams.captured.textDocument.uri).isEqualTo(normalizeFileUri(" file:///testDir/$oldName " ))
405+
406+ val openParams = slot<DidOpenTextDocumentParams >()
407+ verify { mockTextDocumentService.didOpen(capture(openParams)) }
408+ assertThat(openParams.captured.textDocument.uri).isEqualTo(normalizeFileUri(" file:///testDir/$newName " ))
409+ assertThat(openParams.captured.textDocument.text).isEqualTo(normalizeFileUri(" content" ))
410+
392411 // Assert
393412 val paramsSlot = slot<RenameFilesParams >()
394413 verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
@@ -411,6 +430,8 @@ class WorkspaceServiceHandlerTest {
411430 sut.after(listOf (propertyEvent))
412431
413432 // Assert
433+ verify(exactly = 0 ) { mockTextDocumentService.didClose(any()) }
434+ verify(exactly = 0 ) { mockTextDocumentService.didOpen(any()) }
414435 verify(exactly = 0 ) { mockWorkspaceService.didRenameFiles(any()) }
415436 }
416437
@@ -427,6 +448,8 @@ class WorkspaceServiceHandlerTest {
427448 sut.after(listOf (propertyEvent))
428449
429450 // Assert
451+ verify(exactly = 0 ) { mockTextDocumentService.didClose(any()) }
452+ verify(exactly = 0 ) { mockTextDocumentService.didOpen(any()) }
430453 val paramsSlot = slot<RenameFilesParams >()
431454 verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
432455 with (paramsSlot.captured.files[0 ]) {
@@ -624,6 +647,7 @@ class WorkspaceServiceHandlerTest {
624647 every { fileSystem } returns mockk {
625648 every { protocol } returns " file"
626649 }
650+ every { this @mockk.inputStream } returns " content" .byteInputStream()
627651 }
628652 }
629653
0 commit comments