Skip to content

Commit

Permalink
check parent range when creating selection range, #67872
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Mar 12, 2019
1 parent a2f6ec6 commit 8579e43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/vs/workbench/api/node/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,10 @@ export class SelectionRange {
constructor(range: Range, parent?: SelectionRange) {
this.range = range;
this.parent = parent;

if (parent && !parent.range.contains(this.range)) {
throw new Error('Invalid argument: parent must contain this range');
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,19 +1119,15 @@ suite('ExtHostLanguageFeatures', function () {
});

test('Selection Ranges, bad data', async () => {
disposables.push(extHost.registerSelectionRangeProvider(defaultExtension, defaultSelector, new class implements vscode.SelectionRangeProvider {
provideSelectionRanges() {
return [
new types.SelectionRange(new types.Range(0, 10, 0, 18),
new types.SelectionRange(new types.Range(0, 11, 0, 18))),
];
}
}));

await rpcProtocol.sync();
try {
let _a = new types.SelectionRange(new types.Range(0, 10, 0, 18),
new types.SelectionRange(new types.Range(0, 11, 0, 18))
);
assert.ok(false, String(_a));
} catch (err) {
assert.ok(true);
}

provideSelectionRanges(model, [new Position(1, 17)], CancellationToken.None).then(ranges => {
assert.equal(ranges.length, 0);
});
});
});

0 comments on commit 8579e43

Please sign in to comment.