1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.locToRange = exports.offsetToPosition = exports.Position = exports.Range = void 0;
|
4 | class Range {
|
5 | constructor(start, end) {
|
6 | this.containsPosition = (position) => {
|
7 | if (this.start.line === position.line) {
|
8 | return this.start.character <= position.character;
|
9 | }
|
10 | else if (this.end.line === position.line) {
|
11 | return this.end.character >= position.character;
|
12 | }
|
13 | else {
|
14 | return this.start.line <= position.line && this.end.line >= position.line;
|
15 | }
|
16 | };
|
17 | this.start = start;
|
18 | this.end = end;
|
19 | }
|
20 | setStart(line, character) {
|
21 | this.start = new Position(line, character);
|
22 | }
|
23 | setEnd(line, character) {
|
24 | this.end = new Position(line, character);
|
25 | }
|
26 | }
|
27 | exports.Range = Range;
|
28 | class Position {
|
29 | constructor(line, character) {
|
30 | this.lessThanOrEqualTo = (position) => this.line < position.line ||
|
31 | (this.line === position.line && this.character <= position.character);
|
32 | this.line = line;
|
33 | this.character = character;
|
34 | }
|
35 | setLine(line) {
|
36 | this.line = line;
|
37 | }
|
38 | setCharacter(character) {
|
39 | this.character = character;
|
40 | }
|
41 | }
|
42 | exports.Position = Position;
|
43 | function offsetToPosition(text, loc) {
|
44 | const EOL = '\n';
|
45 | const buf = text.slice(0, loc);
|
46 | const lines = buf.split(EOL).length - 1;
|
47 | const lastLineIndex = buf.lastIndexOf(EOL);
|
48 | return new Position(lines, loc - lastLineIndex - 1);
|
49 | }
|
50 | exports.offsetToPosition = offsetToPosition;
|
51 | function locToRange(text, loc) {
|
52 | const start = offsetToPosition(text, loc.start);
|
53 | const end = offsetToPosition(text, loc.end);
|
54 | return new Range(start, end);
|
55 | }
|
56 | exports.locToRange = locToRange;
|
57 |
|
\ | No newline at end of file |