| 3 | import type { ClientCapabilities } from 'vscode-languageserver'; |
| 4 | |
| 5 | function binaryNodeSearchInner<T extends alphaTab.importer.alphaTex.AlphaTexAstNode>( |
| 6 | items: T[], |
| 7 | offset: number, |
| 8 | left: number = 0, |
| 9 | right: number = items.length, |
| 10 | trailingEnd: number |
| 11 | ) { |
| 12 | if (left > right) { |
| 13 | return undefined; |
| 14 | } |
| 15 | |
| 16 | const center = Math.trunc((left + right) / 2); |
| 17 | const centerItem = items[center]; |
| 18 | |
| 19 | // match |
| 20 | const end = center === items.length - 1 ? trailingEnd : items[center + 1].start!.offset; |
| 21 | if (centerItem.start!.offset <= offset && offset <= end) { |
| 22 | return centerItem; |
| 23 | } |
| 24 | |
| 25 | // left half |
| 26 | if (offset < centerItem.start!.offset) { |
| 27 | return binaryNodeSearchInner(items, offset, left, center, trailingEnd); |
| 28 | } |
| 29 | |
| 30 | // right half |
| 31 | return binaryNodeSearchInner(items, offset, center, right, trailingEnd); |
| 32 | } |
| 33 | |
| 34 | export function binaryNodeSearch<T extends alphaTab.importer.alphaTex.AlphaTexAstNode>( |
| 35 | items: T[], |