Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: fix infinite loop when race condition happens #24

Merged
merged 1 commit into from
Nov 4, 2024
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
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function showSettingsUpdateDialog(ext: ExtensionContext) {
}

export function activate(ext: ExtensionContext) {
let triggerDoc: TextDocument | undefined
let triggerPos: Position | undefined
let lock: boolean = false

showSettingsUpdateDialog(ext)

Expand All @@ -40,12 +39,10 @@ export function activate(ext: ExtensionContext) {
], {
async provideDefinition(document: TextDocument, position: Position) {
// prevent infinite loop and reduce unnecessary calls
if ((triggerDoc === document && triggerPos?.isEqual(position)))
if (lock)
return null

triggerDoc = document
triggerPos = position

lock = true
const definitions = await commands.executeCommand('vscode.executeDefinitionProvider', document.uri, position) as Definition | DefinitionLink[]
if (!Array.isArray(definitions))
return definitions
Expand Down Expand Up @@ -86,6 +83,7 @@ export function activate(ext: ExtensionContext) {
}
}

lock = false
return modifiedDefinitions as Location[] | LocationLink[]
},
})
Expand Down