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
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
import org.eclipse.lsp4j.DeleteFilesParams
import org.eclipse.lsp4j.DidChangeWatchedFilesParams
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams
import org.eclipse.lsp4j.DidCloseTextDocumentParams
import org.eclipse.lsp4j.DidOpenTextDocumentParams
import org.eclipse.lsp4j.FileChangeType
import org.eclipse.lsp4j.FileCreate
import org.eclipse.lsp4j.FileDelete
import org.eclipse.lsp4j.FileEvent
import org.eclipse.lsp4j.FileRename
import org.eclipse.lsp4j.RenameFilesParams
import org.eclipse.lsp4j.TextDocumentIdentifier
import org.eclipse.lsp4j.TextDocumentItem
import org.eclipse.lsp4j.WorkspaceFolder
import org.eclipse.lsp4j.WorkspaceFoldersChangeEvent
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
Expand Down Expand Up @@ -135,6 +139,29 @@
val oldUri = toUriString(parentFile)?.let { parentUri -> "$parentUri/$oldFileName" }
val newUri = toUriString(renamedFile)

if (!renamedFile.isDirectory) {
oldUri?.let { uri ->
languageServer.textDocumentService.didClose(
DidCloseTextDocumentParams().apply {
textDocument = TextDocumentIdentifier().apply {
this.uri = uri
}
}

Check warning on line 149 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt#L144-L149

Added lines #L144 - L149 were not covered by tests
)
}

Check warning on line 151 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt#L151

Added line #L151 was not covered by tests

newUri?.let { uri ->
languageServer.textDocumentService.didOpen(
DidOpenTextDocumentParams().apply {
textDocument = TextDocumentItem().apply {
this.uri = uri
text = renamedFile.inputStream.readAllBytes().decodeToString()
}
}

Check warning on line 160 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt#L154-L160

Added lines #L154 - L160 were not covered by tests
)
}

Check warning on line 162 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt#L162

Added line #L162 was not covered by tests
}

FileRename().apply {
this.oldUri = oldUri
this.newUri = newUri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ import org.eclipse.lsp4j.CreateFilesParams
import org.eclipse.lsp4j.DeleteFilesParams
import org.eclipse.lsp4j.DidChangeWatchedFilesParams
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams
import org.eclipse.lsp4j.DidCloseTextDocumentParams
import org.eclipse.lsp4j.DidOpenTextDocumentParams
import org.eclipse.lsp4j.FileChangeType
import org.eclipse.lsp4j.RenameFilesParams
import org.eclipse.lsp4j.WorkspaceFolder
import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage
import org.eclipse.lsp4j.services.TextDocumentService
import org.eclipse.lsp4j.services.WorkspaceService
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -50,13 +53,15 @@ class WorkspaceServiceHandlerTest {
private lateinit var project: Project
private lateinit var mockLanguageServer: AmazonQLanguageServer
private lateinit var mockWorkspaceService: WorkspaceService
private lateinit var mockTextDocumentService: TextDocumentService
private lateinit var sut: WorkspaceServiceHandler
private lateinit var mockApplication: Application

@BeforeEach
fun setup() {
project = mockk<Project>()
mockWorkspaceService = mockk<WorkspaceService>()
mockTextDocumentService = mockk<TextDocumentService>()
mockLanguageServer = mockk<AmazonQLanguageServer>()

mockApplication = mockk<Application>()
Expand Down Expand Up @@ -89,6 +94,11 @@ class WorkspaceServiceHandlerTest {
every { mockWorkspaceService.didChangeWatchedFiles(any()) } returns Unit
every { mockWorkspaceService.didChangeWorkspaceFolders(any()) } returns Unit

// Mock textDocument service (for didRename calls)
every { mockLanguageServer.textDocumentService } returns mockTextDocumentService
every { mockTextDocumentService.didOpen(any()) } returns Unit
every { mockTextDocumentService.didClose(any()) } returns Unit

// Mock message bus
val messageBus = mockk<MessageBus>()
every { project.messageBus } returns messageBus
Expand Down Expand Up @@ -389,6 +399,15 @@ class WorkspaceServiceHandlerTest {
// Act
sut.after(listOf(propertyEvent))

val closeParams = slot<DidCloseTextDocumentParams>()
verify { mockTextDocumentService.didClose(capture(closeParams)) }
assertThat(closeParams.captured.textDocument.uri).isEqualTo(normalizeFileUri("file:///testDir/$oldName"))

val openParams = slot<DidOpenTextDocumentParams>()
verify { mockTextDocumentService.didOpen(capture(openParams)) }
assertThat(openParams.captured.textDocument.uri).isEqualTo(normalizeFileUri("file:///testDir/$newName"))
assertThat(openParams.captured.textDocument.text).isEqualTo(normalizeFileUri("content"))

// Assert
val paramsSlot = slot<RenameFilesParams>()
verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
Expand All @@ -411,6 +430,8 @@ class WorkspaceServiceHandlerTest {
sut.after(listOf(propertyEvent))

// Assert
verify(exactly = 0) { mockTextDocumentService.didClose(any()) }
verify(exactly = 0) { mockTextDocumentService.didOpen(any()) }
verify(exactly = 0) { mockWorkspaceService.didRenameFiles(any()) }
}

Expand All @@ -427,6 +448,8 @@ class WorkspaceServiceHandlerTest {
sut.after(listOf(propertyEvent))

// Assert
verify(exactly = 0) { mockTextDocumentService.didClose(any()) }
verify(exactly = 0) { mockTextDocumentService.didOpen(any()) }
val paramsSlot = slot<RenameFilesParams>()
verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
with(paramsSlot.captured.files[0]) {
Expand Down Expand Up @@ -624,6 +647,7 @@ class WorkspaceServiceHandlerTest {
every { fileSystem } returns mockk {
every { protocol } returns "file"
}
every { [email protected] } returns "content".byteInputStream()
}
}

Expand Down
Loading