Skip to content

Conversation

@samgst-amazon
Copy link
Contributor

@samgst-amazon samgst-amazon commented Feb 26, 2025

Added service handlers for aws/credential messages.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Description

Implemented credential service class to invoke messaging the LSP server for token updates and token deletion.

Checklist

  • My code follows the code style of this project
  • I have added tests to cover my changes
  • A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
  • I have added metrics for my changes (if required)

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

@samgst-amazon samgst-amazon requested a review from a team as a code owner February 26, 2025 01:56
@github-actions
Copy link

github-actions bot commented Feb 26, 2025

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at [email protected]

Comment on lines 29 to 41
return CompletableFuture<ResponseMessage>().also { completableFuture ->
AmazonQLspService.executeIfRunning(project) { server ->
server.updateTokenCredentials(payload)
.whenComplete { response, throwable ->
if (throwable != null) {
completableFuture.completeExceptionally(throwable)
} else {
completableFuture.complete(response)
}
}
} ?: completableFuture.completeExceptionally(IllegalStateException("LSP Server not running"))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can reduce the boilerplate to

Suggested change
return CompletableFuture<ResponseMessage>().also { completableFuture ->
AmazonQLspService.executeIfRunning(project) { server ->
server.updateTokenCredentials(payload)
.whenComplete { response, throwable ->
if (throwable != null) {
completableFuture.completeExceptionally(throwable)
} else {
completableFuture.complete(response)
}
}
} ?: completableFuture.completeExceptionally(IllegalStateException("LSP Server not running"))
}
}
return AmazonQLspService.executeIfRunning(project) { server ->
server.updateTokenCredentials(payload)
} ?: CompletableFuture.failedFuture(IllegalStateException("LSP Server not running"))

then redefine the execute methods with type generics

    suspend fun<T> execute(runnable: suspend (AmazonQLanguageServer) -> T): T {
        val lsp = withTimeout(10.seconds) {
            val holder = mutex.withLock { instance }.await()
            holder.initializer.join()

            holder.languageServer
        }

        return runnable(lsp)
    }

    fun<T> executeSync(runnable: suspend (AmazonQLanguageServer) -> T): T =
        runBlocking(cs.coroutineContext) {
            execute(runnable)
        }

fun updateTokenCredentials(payload: UpdateCredentialsPayload): CompletableFuture<ResponseMessage>

@JsonNotification("aws/credentials/token/delete")
fun deleteTokenCredentials()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun deleteTokenCredentials()
fun deleteTokenCredentials(): CompletableFuture<Void>

should it also return a future?

Comment on lines +10 to +11
fun updateTokenCredentials(accessToken: String, encrypted: Boolean): CompletableFuture<ResponseMessage>
fun deleteTokenCredentials(): CompletableFuture<Unit>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im assuming hooking these up will be a followup?

@samgst-amazon samgst-amazon enabled auto-merge (squash) February 26, 2025 22:28
@samgst-amazon samgst-amazon merged commit 35b0424 into feature/q-lsp Feb 26, 2025
15 of 18 checks passed
@samgst-amazon samgst-amazon deleted the samgst/aws-credentials branch February 26, 2025 22:57
leigaol pushed a commit to leigaol/aws-toolkit-jetbrains that referenced this pull request Mar 20, 2025
* implement aws/credentials/token messages

* detekt

* feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants