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

fix(amazonq): Fix edge cases of context command updates #6686

Merged
merged 6 commits into from
Feb 27, 2025
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 43 additions & 32 deletions packages/core/src/amazonq/lsp/lspClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,37 @@

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') {
Expand All @@ -326,42 +357,22 @@
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)
if (editor?.document.getText().length === 0) {
onAdd([editor.document.uri.fsPath])

Check failure on line 364 in packages/core/src/amazonq/lsp/lspClient.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
}),
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 }
)
onAdd(e.files.map((f) => f.fsPath))

Check failure on line 368 in packages/core/src/amazonq/lsp/lspClient.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}),
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 }
)
onRemove(e.files.map((f) => f.fsPath))

Check failure on line 371 in packages/core/src/amazonq/lsp/lspClient.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}),
vscode.workspace.onDidRenameFiles(async (e) => {
await onRemove(e.files.map((f) => f.oldUri.fsPath))
await onAdd(e.files.map((f) => f.newUri.fsPath))
})
)

Expand Down
Loading