Skip to content

Commit

Permalink
fix: fix infinite loop when race condition happens (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Donovan-Ye authored Nov 4, 2024
1 parent 3fa85d0 commit 5ad31fb
Showing 1 changed file with 4 additions and 6 deletions.
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

0 comments on commit 5ad31fb

Please # to comment.