-
Notifications
You must be signed in to change notification settings - Fork 274
feat(amazonq): Implement aws/syncModuleDependencies call #5414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
9d71b4c
1f1c2ac
f92ab4d
58e3ea2
060f64a
63eb25c
f5f4c87
10ddb2d
44c794e
90d5365
9edbfac
b9ba38f
a461559
5ff55ca
b2d5cc3
a1c08a5
f254b7a
c9d7ab3
7b77a6f
3263ac9
7e74c9e
e35e956
d14bfe4
2edaba4
6d9eb85
db03df1
2fd9ee6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||||||||||||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| package software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import com.intellij.openapi.Disposable | ||||||||||||||||||||
| import com.intellij.openapi.module.ModuleManager | ||||||||||||||||||||
| import com.intellij.openapi.project.Project | ||||||||||||||||||||
| import com.intellij.openapi.roots.ModuleRootEvent | ||||||||||||||||||||
| import com.intellij.openapi.roots.ModuleRootListener | ||||||||||||||||||||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService | ||||||||||||||||||||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies.ModuleDependencyProvider.Companion.EP_NAME | ||||||||||||||||||||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.dependencies.SyncModuleDependenciesParams | ||||||||||||||||||||
| import java.util.concurrent.CompletableFuture | ||||||||||||||||||||
|
|
||||||||||||||||||||
| class DefaultModuleDependenciesService( | ||||||||||||||||||||
| private val project: Project, | ||||||||||||||||||||
| serverInstance: Disposable, | ||||||||||||||||||||
| ) : ModuleDependenciesService, | ||||||||||||||||||||
| ModuleRootListener { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| init { | ||||||||||||||||||||
| project.messageBus.connect(serverInstance).subscribe( | ||||||||||||||||||||
| ModuleRootListener.TOPIC, | ||||||||||||||||||||
| this | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| // project initiation with initial list of dependencies | ||||||||||||||||||||
| syncAllModules() | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| override fun rootsChanged(event: ModuleRootEvent) { | ||||||||||||||||||||
| if (event.isCausedByFileTypesChange) return | ||||||||||||||||||||
| // call on change with updated dependencies | ||||||||||||||||||||
| syncAllModules() | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| override fun syncModuleDependencies(params: SyncModuleDependenciesParams): CompletableFuture<Unit> = | ||||||||||||||||||||
| CompletableFuture<Unit>().also { completableFuture -> | ||||||||||||||||||||
| AmazonQLspService.executeIfRunning(project) { languageServer -> | ||||||||||||||||||||
| languageServer.syncModuleDependencies(params) | ||||||||||||||||||||
| completableFuture.complete(null) | ||||||||||||||||||||
| } ?: completableFuture.completeExceptionally(IllegalStateException("LSP Server not running")) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
||||||||||||||||||||
| CompletableFuture<Unit>().also { completableFuture -> | |
| AmazonQLspService.executeIfRunning(project) { languageServer -> | |
| languageServer.syncModuleDependencies(params) | |
| completableFuture.complete(null) | |
| } ?: completableFuture.completeExceptionally(IllegalStateException("LSP Server not running")) | |
| } | |
| AmazonQLspService.executeIfRunning(project) { languageServer -> | |
| languageServer.syncModuleDependencies(params) | |
| }?.toCompletableFuture() ?: CompletableFuture.failedFuture(IllegalStateException("LSP Server not running")) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies | ||
|
|
||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.dependencies.SyncModuleDependenciesParams | ||
| import java.util.concurrent.CompletableFuture | ||
|
|
||
| interface ModuleDependenciesService { | ||
| fun syncModuleDependencies(params: SyncModuleDependenciesParams): CompletableFuture<Unit> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies | ||
|
|
||
| import com.intellij.openapi.extensions.ExtensionPointName | ||
| import com.intellij.openapi.module.Module | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.dependencies.SyncModuleDependenciesParams | ||
|
|
||
| interface ModuleDependencyProvider { | ||
| companion object { | ||
| val EP_NAME = ExtensionPointName<ModuleDependencyProvider>("software.aws.toolkits.jetbrains.moduleDependencyProvider") | ||
| } | ||
|
|
||
| fun isApplicable(module: Module): Boolean | ||
| fun createParams(module: Module): SyncModuleDependenciesParams | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies.providers | ||
|
|
||
| import com.intellij.openapi.module.Module | ||
| import com.intellij.openapi.projectRoots.JavaSdkType | ||
| import com.intellij.openapi.roots.ModuleRootManager | ||
| import com.intellij.openapi.roots.OrderRootType | ||
| import com.intellij.openapi.vfs.VfsUtil | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies.ModuleDependencyProvider | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.dependencies.SyncModuleDependenciesParams | ||
|
|
||
| internal class JavaModuleDependencyProvider : ModuleDependencyProvider { | ||
| override fun isApplicable(module: Module): Boolean = | ||
| ModuleRootManager.getInstance(module).sdk?.sdkType is JavaSdkType | ||
|
|
||
| override fun createParams(module: Module): SyncModuleDependenciesParams { | ||
| val sourceRoots = getSourceRoots(module) | ||
| val dependencies = mutableListOf<String>() | ||
|
|
||
| ModuleRootManager.getInstance(module).orderEntries().forEachLibrary { library -> | ||
| library.getUrls(OrderRootType.CLASSES).forEach { url -> | ||
| dependencies.add(VfsUtil.urlToPath(url)) | ||
| } | ||
| true | ||
| } | ||
|
|
||
| return SyncModuleDependenciesParams( | ||
| moduleName = module.name, | ||
| programmingLanguage = "Java", | ||
| files = sourceRoots, | ||
| dirs = dependencies, | ||
| includePatterns = emptyList(), | ||
| excludePatterns = emptyList() | ||
| ) | ||
| } | ||
|
|
||
| private fun getSourceRoots(module: Module): List<String> = | ||
| ModuleRootManager.getInstance(module).contentEntries | ||
| .flatMap { contentEntry -> | ||
| contentEntry.sourceFolders | ||
| .filter { !it.isTestSource } | ||
| .mapNotNull { it.file?.path } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies.providers | ||
|
|
||
| import com.intellij.openapi.module.Module | ||
| import com.intellij.openapi.roots.ModuleRootManager | ||
| import com.jetbrains.python.packaging.management.PythonPackageManager | ||
| import com.jetbrains.python.sdk.PythonSdkUtil | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.dependencies.ModuleDependencyProvider | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.dependencies.SyncModuleDependenciesParams | ||
|
|
||
| internal class PythonModuleDependencyProvider : ModuleDependencyProvider { | ||
| override fun isApplicable(module: Module): Boolean = | ||
| PythonSdkUtil.findPythonSdk(module) != null | ||
|
|
||
| override fun createParams(module: Module): SyncModuleDependenciesParams { | ||
| val sourceRoots = getSourceRoots(module) | ||
| val dependencies = mutableListOf<String>() | ||
|
|
||
| PythonSdkUtil.findPythonSdk(module)?.let { sdk -> | ||
| val packageManager = PythonPackageManager.forSdk(module.project, sdk) | ||
Check warningCode scanning / QDJVMC Unstable API Usage Warning
'com.jetbrains.python.packaging.management.PythonPackageManager.Companion' is declared in unstable 'com.jetbrains.python.packaging.management.PythonPackageManager' marked with @ApiStatus.Experimental
Check warningCode scanning / QDJVMC Unstable API Usage Warning
'forSdk(com.intellij.openapi.project.Project, com.intellij.openapi.projectRoots.Sdk)' is declared in unstable 'com.jetbrains.python.packaging.management.PythonPackageManager' marked with @ApiStatus.Experimental
|
||
| packageManager.installedPackages.forEach { pkg -> | ||
Check warningCode scanning / QDJVMC Unstable API Usage Warning
'getInstalledPackages()' is declared in unstable 'com.jetbrains.python.packaging.management.PythonPackageManager' marked with @ApiStatus.Experimental
|
||
| dependencies.add(pkg.name) | ||
| } | ||
| } | ||
|
|
||
| return SyncModuleDependenciesParams( | ||
| moduleName = module.name, | ||
| programmingLanguage = "Python", | ||
| files = sourceRoots, | ||
| dirs = dependencies, | ||
| includePatterns = emptyList(), | ||
| excludePatterns = emptyList() | ||
| ) | ||
| } | ||
|
|
||
| private fun getSourceRoots(module: Module): List<String> = | ||
| ModuleRootManager.getInstance(module).contentEntries | ||
| .flatMap { contentEntry -> | ||
| contentEntry.sourceFolders | ||
| .filter { !it.isTestSource } | ||
| .mapNotNull { it.file?.path } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.dependencies | ||
|
|
||
| class SyncModuleDependenciesParams( | ||
| val moduleName: String, | ||
Check warningCode scanning / QDJVMC Unused symbol Warning
Property "moduleName" is never used
|
||
| val programmingLanguage: String, | ||
| val files: List<String>, | ||
| val dirs: List<String>, | ||
Check warningCode scanning / QDJVMC Unused symbol Warning
Property "dirs" is never used
|
||
| val includePatterns: List<String>, | ||
Check warningCode scanning / QDJVMC Unused symbol Warning
Property "includePatterns" is never used
|
||
| val excludePatterns: List<String>, | ||
Check warningCode scanning / QDJVMC Unused symbol Warning
Property "excludePatterns" is never used
|
||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you see if
@JsonNotificationworks