Repair (?) error when searching for the very last position in a file, such as for a missing close parenthesis
This commit is contained in:
parent
a37879695e
commit
50eaec69ef
|
@ -33,17 +33,17 @@ export class SpanIndex<T> {
|
|||
let lo = 0;
|
||||
let hi = this.index.length;
|
||||
|
||||
// console.log(`\nsearching for ${target}`);
|
||||
// console.log(`\nsearching for ${pos}`);
|
||||
while (true) {
|
||||
if (lo === hi) {
|
||||
if (lo === 0) return null;
|
||||
const e = this.index[lo - 1];
|
||||
if (e[0] > pos) throw new Error("INTERNAL ERROR: bad binary search (1)");
|
||||
if (this.index[lo]?.[0] <= pos) throw new Error("INTERNAL ERROR: bad binary search (2)");
|
||||
// console.log(`found ${JSON.stringify(e)}, ${JSON.stringify(items[lo] ?? null)}`);
|
||||
// console.log(`found ${JSON.stringify(e)}, ${JSON.stringify(this.index[lo] ?? null)}`);
|
||||
const r = new SpanResult<T>(pos, e[0]);
|
||||
e[1].forEach(([end, item]) => {
|
||||
if (pos < end) {
|
||||
if (pos <= end) {
|
||||
r.items.push({ end, item });
|
||||
}
|
||||
});
|
||||
|
@ -53,7 +53,7 @@ export class SpanIndex<T> {
|
|||
const mid = (lo + hi) >> 1;
|
||||
const e = this.index[mid];
|
||||
|
||||
// console.log(`${target} lo ${lo} hi ${hi} mid ${mid} probe ${JSON.stringify([e[0], e[1].target])}`);
|
||||
// console.log(`${pos} lo ${lo} hi ${hi} mid ${mid} probe ${JSON.stringify(e)}`);
|
||||
|
||||
if (e[0] <= pos) {
|
||||
lo = mid + 1;
|
||||
|
|
Loading…
Reference in New Issue