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 @@ -73,6 +73,7 @@ import software.aws.toolkits.core.utils.writeText
import software.aws.toolkits.jetbrains.core.coroutines.ioDispatcher
import software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts.ArtifactManager
import software.aws.toolkits.jetbrains.services.amazonq.lsp.auth.DefaultAuthCredentialsService
import software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies.DefaultModuleDependenciesService
import software.aws.toolkits.jetbrains.services.amazonq.lsp.encryption.JwtEncryptionManager
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AmazonQLspTypeAdapterFactory
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AwsExtendedInitializeResult
Expand Down Expand Up @@ -592,9 +593,9 @@ private class AmazonQServerInstance(private val project: Project, private val cs
WorkspaceServiceHandler(project, cs, lspInitResult).also {
Disposer.register(this, it)
}
// DefaultModuleDependenciesService(project, cs).also {
// Disposer.register(this, it)
// }
DefaultModuleDependenciesService(project, cs).also {
Disposer.register(this, it)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ModuleRootEvent
import com.intellij.openapi.roots.ModuleRootListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
import software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies.ModuleDependencyProvider.Companion.EP_NAME
Expand Down Expand Up @@ -44,14 +45,34 @@ class DefaultModuleDependenciesService(
}

private fun syncAllModules() {
val paramsMap = mutableMapOf<Pair<String, String>, DidChangeDependencyPathsParams>()

ModuleManager.getInstance(project).modules.forEach { module ->
EP_NAME.forEachExtensionSafe {
if (it.isApplicable(module)) {
didChangeDependencyPaths(it.createParams(module))
val params = it.createParams(module)
val key = params.moduleName to params.runtimeLanguage

paramsMap.merge(key, params) { existing, new ->
DidChangeDependencyPathsParams(
moduleName = existing.moduleName,
runtimeLanguage = existing.runtimeLanguage,
paths = (existing.paths + new.paths).distinct(),
includePatterns = (existing.includePatterns + new.includePatterns).distinct(),
excludePatterns = (existing.excludePatterns + new.excludePatterns).distinct()
)
}
return@forEachExtensionSafe
}
}
}

paramsMap.values.chunked(10).forEachIndexed { index, chunk ->
cs.launch {
delay(index * 1000L)
chunk.forEach { didChangeDependencyPaths(it) }
}
}
}

override fun dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,56 @@ class DefaultModuleDependenciesServiceTest {
verify(exactly = 2) { mockLanguageServer.didChangeDependencyPaths(params) }
}

@Test
fun `test deduplication of same moduleName and runtimeLanguage`() = runTest {
// Arrange
val module1 = mockk<Module>()
val module2 = mockk<Module>()
val params1 = DidChangeDependencyPathsParams(
moduleName = "sameModule",
runtimeLanguage = "java",
paths = listOf("/path/to/dep1.jar"),
includePatterns = listOf("*.java"),
excludePatterns = listOf("test/**")
)
val params2 = DidChangeDependencyPathsParams(
moduleName = "sameModule",
runtimeLanguage = "java",
paths = listOf("/path/to/dep2.jar"),
includePatterns = listOf("*.class"),
excludePatterns = listOf("build/**")
)

every { mockModuleManager.modules } returns arrayOf(module1, module2)
every { mockDependencyProvider.isApplicable(any()) } returns true
every { mockDependencyProvider.createParams(module1) } returns params1
every { mockDependencyProvider.createParams(module2) } returns params2

prepDependencyProvider(
listOf(
Pair(module1, params1),
Pair(module2, params2)
)
)

sut = DefaultModuleDependenciesService(project, this)

advanceUntilIdle()

// Verify only one call with merged paths
verify(exactly = 1) {
mockLanguageServer.didChangeDependencyPaths(
match {
it.moduleName == "sameModule" &&
it.runtimeLanguage == "java" &&
it.paths.containsAll(listOf("/path/to/dep1.jar", "/path/to/dep2.jar")) &&
it.includePatterns.containsAll(listOf("*.java", "*.class")) &&
it.excludePatterns.containsAll(listOf("test/**", "build/**"))
}
)
}
}

private fun prepDependencyProvider(moduleParamPairs: List<Pair<Module, DidChangeDependencyPathsParams>>) {
every { mockModuleManager.modules } returns moduleParamPairs.map { it.first }.toTypedArray()

Expand Down
Loading