Skip to content
Merged
Changes from all 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
76 changes: 44 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 @@ 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[]) => {
Copy link
Contributor

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.

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,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
Copy link
Contributor

Choose a reason for hiding this comment

The 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))
})
)

Expand Down
Loading