Skip to content

Conversation

@Will-ShaoHua
Copy link
Contributor

@Will-ShaoHua Will-ShaoHua commented Aug 1, 2025

Problem

related aws/language-servers#2058

Edits as a newly introduced feature, previously the implementation was living in the same flow as Completion. However the 2 suggestion types have few different product requirements, thus we decided to completely separate these 2 suggestions out in terms of their code path.

Key difference

  • Language server will process Completion request on receiving request from IDE clients, and will BLOCK following requests if in-flight request is not fulfilled yet. Edits, on the other hand, it debounces/delay the execution time for the sake of "latest" file context to ensure the suggestion reflects the CORRECT changes users attempt to make.
  • Triggering heuristic. For example, Completion is not supposed to be invoked when users are deleting the code, whereas Edits allow such scenario to go through.

Solution

  • Introduce a new onEditCompletion language server API which is purely for Edits suggestion.
  • Invoke 2 Flare API and serve the response which first arrives (First come first served).
  • Allow Edits suggestion on code deletion

  • 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.

@amazon-inspector-ohio
Copy link

⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done

@github-actions
Copy link

github-actions bot commented Aug 1, 2025

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.

@amazon-inspector-ohio
Copy link

✅ I finished the code review, and didn't find any security or code quality issues.

@Will-ShaoHua Will-ShaoHua changed the title Concurrent refactor(amazonq): separate edits from completion code path Aug 6, 2025
@Will-ShaoHua Will-ShaoHua marked this pull request as ready for review August 6, 2025 06:55
@Will-ShaoHua Will-ShaoHua requested a review from a team as a code owner August 6, 2025 06:55
andrewyuq
andrewyuq previously approved these changes Aug 6, 2025

if (position.isAfter(editor.selection.active)) {
// Edit suggestion works differently than completion suggestion, so even when it's a deletion and cause cursor to move back, we still allow the request to go through
if (position.isAfter(editor.selection.active) && items.length > 0 && !items[0].isInlineEdit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (is completion) {
if (cursor moved before trigger point)

}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

donee

)
ps.push(editPromise)

let result = await Promise.race(ps)
Copy link
Contributor

Choose a reason for hiding this comment

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

editPromise will likely always win the race because for most users the edit predictions are not enabled, hence its server API response will be very fast, and it will win the race.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

donee

floralph
floralph previously approved these changes Aug 7, 2025
@Will-ShaoHua Will-ShaoHua dismissed stale reviews from floralph and andrewyuq via b9ecf20 August 7, 2025 01:17
Comment on lines +162 to +169
if (ps.length > 1 && result.items.length === 0) {
for (const p of ps) {
const r = await p
if (r.items.length > 0) {
result = r
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugly, but this is the best effort we can do atm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should add another field suggestionType within InlineCompletionListWithReferences so that we know which suggestion type it is instead of this hack. Can follow up.


const result = await this.getRecommendationsWithTimeout(languageClient, request, token)
// Best effort estimate of deletion
const isTriggerByDeletion = documentEventListener.isLastEventDeletion(document.uri.fsPath)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leigaol fyi, logic to handle trigger when users are deleting the code is moved here

@leigaol leigaol merged commit 76a1cd0 into aws:master Aug 7, 2025
29 of 31 checks passed
@Will-ShaoHua Will-ShaoHua deleted the concurrent branch August 7, 2025 17:14
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