Skip to content
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

feat(amazonq): user cancellable lsp download #6573

Merged
merged 7 commits into from
Mar 4, 2025

Conversation

tomcat323
Copy link
Contributor

@tomcat323 tomcat323 commented Feb 13, 2025

Problem

the cancellation button on notification doesn't actually stop the LSP download

Solution

Route the notification timeout into httpResourceFetcher call, so that the user cancellation event stops the download as well.

Demo: non-cancelled and cancelled downloads:

Screen.Recording.2025-02-13.at.11.44.59.AM.mov

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@tomcat323 tomcat323 marked this pull request as ready for review February 13, 2025 16:57
@tomcat323 tomcat323 requested a review from a team as a code owner February 13, 2025 16:57
@hayemaxi
Copy link
Contributor

hayemaxi commented Feb 19, 2025

After some discussion, do we still want this? Cancelling the LSP download means the extension would become unusable.

@jpinkney-aws
Copy link
Contributor

TBH I'm against this now after the meeting yesterday, I think we should still show progress but if the options are:

  1. You always download the language server and get all the features
    OR
  2. You click cancel and then nothings working except for auth

I'd much rather just have them always download the language server

@justinmk3
Copy link
Contributor

I'd much rather just have them always download the language server

What happens if the download fails? We must handle that case anyway. So handling "Cancel" is trivial then.

And if the network is very slow? The user has no way to cancel it?

@@ -82,7 +86,10 @@ export class HttpResourceFetcher implements ResourceFetcher<Response> {
`Error downloading ${this.logText()}: %s`,
error.message ?? error.code ?? error.response.statusText ?? error.response.status
)
return undefined
if (this.params.swallowError) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously this is swallowing all errors from fetch. With this change we can detect and catch the user cancellation errors.

retryOnFail: true,
retryOnFail: (error: Error) => {
// retry unless we got an user cancellation error
return !(error instanceof RequestCancelledError)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Purpose of this added waitUntil feature:
We need to stop download retries if its an user cancel error
But for all other error types from fetch, we continue retry.

@aws aws deleted a comment from github-actions bot Feb 27, 2025
if (error === undefined) {
return typeof opt.retryOnFail === 'boolean' ? opt.retryOnFail : true
}
if (typeof opt.retryOnFail === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make it always be a function? That should simplify some logic, eliminate an overload, and eliminate some tests.

It's trivial for calls to pass () => true if they want a "constant".

throw new ToolkitError('Failed to download server from remote', { code: 'RemoteDownloadFailed' })
} catch (err) {
if (err instanceof RequestCancelledError) {
throw new CancellationError('user')
Copy link
Contributor

@justinmk3 justinmk3 Feb 27, 2025

Choose a reason for hiding this comment

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

Why not add err instanceof RequestCancelledError to isUserCancelledError ?

export function isUserCancelledError(error: unknown): boolean {
return CancellationError.isUserCancelled(error) || (error instanceof ToolkitError && error.cancelled)

Then you wouldn't need to catch-and-throw here. Instead the caller could just check isUserCancelledError , which is the expected pattern.

Copy link

github-actions bot commented Mar 3, 2025

  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@tomcat323 tomcat323 merged commit ff1bbbd into aws:feature/amazonqLSP Mar 4, 2025
16 of 17 checks passed
@justinmk3
Copy link
Contributor

#6573 (comment) wasn't addressed

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.

4 participants