-
Notifications
You must be signed in to change notification settings - Fork 749
fix(amazonq): Fix edge cases of context command updates #6686
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d9b084
update mynahUI to beta 11
leigaol 06876e2
fix edge cases of index update
leigaol f191329
Merge branch 'aws:feature/falcon' into feature/falcon
leigaol a68d84c
Merge branch 'feature/falcon' of github.com:leigaol/aws-toolkit-vscod…
leigaol cab8a6f
adjust timeout
leigaol 83b9032
github actions
leigaol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -315,6 +315,37 @@ export async function activate(extensionContext: ExtensionContext) { | |
|
|
||
| let savedDocument: vscode.Uri | undefined = undefined | ||
|
|
||
| const onAdd = async (filePaths: string[]) => { | ||
| const indexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| await LspClient.instance.updateIndex(filePaths, 'add') | ||
| await waitUntil( | ||
| async () => { | ||
| const newIndexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| if (newIndexSeqNum > indexSeqNum) { | ||
| await vscode.commands.executeCommand(`aws.amazonq.updateContextCommandItems`) | ||
| return true | ||
| } | ||
| return false | ||
| }, | ||
| { interval: 500, timeout: 5_000, truthy: true } | ||
| ) | ||
| } | ||
| const onRemove = async (filePaths: string[]) => { | ||
| const indexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| await LspClient.instance.updateIndex(filePaths, 'remove') | ||
| await waitUntil( | ||
| async () => { | ||
| const newIndexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| if (newIndexSeqNum > indexSeqNum) { | ||
| await vscode.commands.executeCommand(`aws.amazonq.updateContextCommandItems`) | ||
| return true | ||
| } | ||
| return false | ||
| }, | ||
| { interval: 500, timeout: 5_000, truthy: true } | ||
| ) | ||
| } | ||
|
|
||
| toDispose.push( | ||
| vscode.workspace.onDidSaveTextDocument((document) => { | ||
| if (document.uri.scheme !== 'file') { | ||
|
|
@@ -326,42 +357,23 @@ export async function activate(extensionContext: ExtensionContext) { | |
| if (savedDocument && editor && editor.document.uri.fsPath !== savedDocument.fsPath) { | ||
| void LspClient.instance.updateIndex([savedDocument.fsPath], 'update') | ||
| } | ||
| // user created a new empty file using File -> New File | ||
| // these events will not be captured by vscode.workspace.onDidCreateFiles | ||
| // because it was created by File Explorer(Win) or Finder(MacOS) | ||
| // TODO: consider using a high performance fs watcher | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? fs watchers have been a source of performance issues in the past. Please do not add more of them without careful consideration. (We already spawn tons of them.) |
||
| if (editor?.document.getText().length === 0) { | ||
| void onAdd([editor.document.uri.fsPath]) | ||
| } | ||
| }), | ||
| vscode.workspace.onDidCreateFiles(async (e) => { | ||
| const indexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| await LspClient.instance.updateIndex( | ||
| e.files.map((f) => f.fsPath), | ||
| 'add' | ||
| ) | ||
| await waitUntil( | ||
| async () => { | ||
| const newIndexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| if (newIndexSeqNum > indexSeqNum) { | ||
| await vscode.commands.executeCommand(`aws.amazonq.updateContextCommandItems`) | ||
| return true | ||
| } | ||
| return false | ||
| }, | ||
| { interval: 500, timeout: 10_000, truthy: true } | ||
| ) | ||
| await onAdd(e.files.map((f) => f.fsPath)) | ||
| }), | ||
| vscode.workspace.onDidDeleteFiles(async (e) => { | ||
| const indexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| await LspClient.instance.updateIndex( | ||
| e.files.map((f) => f.fsPath), | ||
| 'remove' | ||
| ) | ||
| await waitUntil( | ||
| async () => { | ||
| const newIndexSeqNum = await LspClient.instance.getIndexSequenceNumber() | ||
| if (newIndexSeqNum > indexSeqNum) { | ||
| await vscode.commands.executeCommand(`aws.amazonq.updateContextCommandItems`) | ||
| return true | ||
| } | ||
| return false | ||
| }, | ||
| { interval: 500, timeout: 10_000, truthy: true } | ||
| ) | ||
| await onRemove(e.files.map((f) => f.fsPath)) | ||
| }), | ||
| vscode.workspace.onDidRenameFiles(async (e) => { | ||
| await onRemove(e.files.map((f) => f.oldUri.fsPath)) | ||
| await onAdd(e.files.map((f) => f.newUri.fsPath)) | ||
| }) | ||
| ) | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This code is nearly identical to the onAdd case above.