@codingame/monaco-vscode-210e86a9-a91b-5273-b05d-390c776dde1f-common 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/empty.js ADDED
@@ -0,0 +1 @@
1
+ export {}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@codingame/monaco-vscode-210e86a9-a91b-5273-b05d-390c776dde1f-common",
3
+ "version": "15.0.0",
4
+ "private": false,
5
+ "description": "VSCode public API plugged on the monaco editor - common package (chat, extensions, interactive, notebook, terminal, view-common)",
6
+ "keywords": [],
7
+ "author": {
8
+ "name": "CodinGame",
9
+ "url": "http://www.codingame.com"
10
+ },
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+ssh://git@github.com/CodinGame/monaco-vscode-api.git"
15
+ },
16
+ "type": "module",
17
+ "dependencies": {
18
+ "@codingame/monaco-vscode-api": "15.0.0"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "default": "./empty.js"
23
+ },
24
+ "./vscode/*": {
25
+ "types": "./vscode/src/*.d.ts",
26
+ "default": "./vscode/src/*.js"
27
+ },
28
+ "./*": {
29
+ "types": "./*.d.ts",
30
+ "default": "./*.js"
31
+ }
32
+ },
33
+ "typesVersions": {
34
+ "*": {
35
+ "vscode/*": [
36
+ "./vscode/src/*.d.ts"
37
+ ]
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ import { Range } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range";
2
+ import { IIdentifiedSingleEditOperation } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
3
+ import { LineRange } from "./lineRange.js";
4
+ export declare class LineRangeEdit {
5
+ readonly range: LineRange;
6
+ readonly newLines: string[];
7
+ constructor(range: LineRange, newLines: string[]);
8
+ equals(other: LineRangeEdit): boolean;
9
+ toEdits(modelLineCount: number): IIdentifiedSingleEditOperation[];
10
+ }
11
+ export declare class RangeEdit {
12
+ readonly range: Range;
13
+ readonly newText: string;
14
+ constructor(range: Range, newText: string);
15
+ equals(other: RangeEdit): boolean;
16
+ }
17
+ export declare class LineEdits {
18
+ readonly edits: readonly LineRangeEdit[];
19
+ constructor(edits: readonly LineRangeEdit[]);
20
+ toEdits(modelLineCount: number): IIdentifiedSingleEditOperation[];
21
+ }
@@ -0,0 +1,57 @@
1
+
2
+ import { equals } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
3
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
4
+
5
+ class LineRangeEdit {
6
+ constructor(range, newLines) {
7
+ this.range = range;
8
+ this.newLines = newLines;
9
+ }
10
+ equals(other) {
11
+ return this.range.equals(other.range) && equals(this.newLines, other.newLines);
12
+ }
13
+ toEdits(modelLineCount) {
14
+ return ( new LineEdits([this])).toEdits(modelLineCount);
15
+ }
16
+ }
17
+ class RangeEdit {
18
+ constructor(range, newText) {
19
+ this.range = range;
20
+ this.newText = newText;
21
+ }
22
+ equals(other) {
23
+ return Range.equalsRange(this.range, other.range) && this.newText === other.newText;
24
+ }
25
+ }
26
+ class LineEdits {
27
+ constructor(edits) {
28
+ this.edits = edits;
29
+ }
30
+ toEdits(modelLineCount) {
31
+ return ( this.edits.map((e) => {
32
+ if (e.range.endLineNumberExclusive <= modelLineCount) {
33
+ return {
34
+ range: ( new Range(e.range.startLineNumber, 1, e.range.endLineNumberExclusive, 1)),
35
+ text: ( e.newLines.map(s => s + '\n')).join(''),
36
+ };
37
+ }
38
+ if (e.range.startLineNumber === 1) {
39
+ return {
40
+ range: ( new Range(1, 1, modelLineCount, Number.MAX_SAFE_INTEGER)),
41
+ text: e.newLines.join('\n'),
42
+ };
43
+ }
44
+ return {
45
+ range: ( new Range(
46
+ e.range.startLineNumber - 1,
47
+ Number.MAX_SAFE_INTEGER,
48
+ modelLineCount,
49
+ Number.MAX_SAFE_INTEGER
50
+ )),
51
+ text: ( e.newLines.map(s => '\n' + s)).join(''),
52
+ };
53
+ }));
54
+ }
55
+ }
56
+
57
+ export { LineEdits, LineRangeEdit, RangeEdit };
@@ -0,0 +1,29 @@
1
+ import { Comparator } from "@codingame/monaco-vscode-api/vscode/vs/base/common/arrays";
2
+ import { Range } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range";
3
+ import { ITextModel } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
4
+ export declare class LineRange {
5
+ readonly startLineNumber: number;
6
+ readonly lineCount: number;
7
+ static readonly compareByStart: Comparator<LineRange>;
8
+ static join(ranges: LineRange[]): LineRange | undefined;
9
+ static fromLineNumbers(startLineNumber: number, endExclusiveLineNumber: number): LineRange;
10
+ constructor(startLineNumber: number, lineCount: number);
11
+ join(other: LineRange): LineRange;
12
+ get endLineNumberExclusive(): number;
13
+ get isEmpty(): boolean;
14
+ touches(other: LineRange): boolean;
15
+ isAfter(range: LineRange): boolean;
16
+ isBefore(range: LineRange): boolean;
17
+ delta(lineDelta: number): LineRange;
18
+ toString(): string;
19
+ equals(originalRange: LineRange): boolean;
20
+ contains(lineNumber: number): boolean;
21
+ deltaEnd(delta: number): LineRange;
22
+ deltaStart(lineDelta: number): LineRange;
23
+ getLines(model: ITextModel): string[];
24
+ containsRange(range: LineRange): boolean;
25
+ toRange(): Range;
26
+ toInclusiveRange(): Range | undefined;
27
+ toInclusiveRangeOrEmpty(): Range;
28
+ intersects(lineRange: LineRange): boolean;
29
+ }
@@ -0,0 +1,112 @@
1
+
2
+ import { compareBy, numberComparator } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
3
+ import { BugIndicatingError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
4
+ import { Constants } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uint';
5
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
6
+
7
+ class LineRange {
8
+ static { this.compareByStart = compareBy(l => l.startLineNumber, numberComparator); }
9
+ static join(ranges) {
10
+ if (ranges.length === 0) {
11
+ return undefined;
12
+ }
13
+ let startLineNumber = Number.MAX_SAFE_INTEGER;
14
+ let endLineNumber = 0;
15
+ for (const range of ranges) {
16
+ startLineNumber = Math.min(startLineNumber, range.startLineNumber);
17
+ endLineNumber = Math.max(endLineNumber, range.startLineNumber + range.lineCount);
18
+ }
19
+ return ( new LineRange(startLineNumber, endLineNumber - startLineNumber));
20
+ }
21
+ static fromLineNumbers(startLineNumber, endExclusiveLineNumber) {
22
+ return ( new LineRange(startLineNumber, endExclusiveLineNumber - startLineNumber));
23
+ }
24
+ constructor(startLineNumber, lineCount) {
25
+ this.startLineNumber = startLineNumber;
26
+ this.lineCount = lineCount;
27
+ if (lineCount < 0) {
28
+ throw ( new BugIndicatingError());
29
+ }
30
+ }
31
+ join(other) {
32
+ return ( new LineRange(
33
+ Math.min(this.startLineNumber, other.startLineNumber),
34
+ Math.max(this.endLineNumberExclusive, other.endLineNumberExclusive) - this.startLineNumber
35
+ ));
36
+ }
37
+ get endLineNumberExclusive() {
38
+ return this.startLineNumber + this.lineCount;
39
+ }
40
+ get isEmpty() {
41
+ return this.lineCount === 0;
42
+ }
43
+ touches(other) {
44
+ return (this.endLineNumberExclusive >= other.startLineNumber &&
45
+ other.endLineNumberExclusive >= this.startLineNumber);
46
+ }
47
+ isAfter(range) {
48
+ return this.startLineNumber >= range.endLineNumberExclusive;
49
+ }
50
+ isBefore(range) {
51
+ return range.startLineNumber >= this.endLineNumberExclusive;
52
+ }
53
+ delta(lineDelta) {
54
+ return ( new LineRange(this.startLineNumber + lineDelta, this.lineCount));
55
+ }
56
+ toString() {
57
+ return `[${this.startLineNumber},${this.endLineNumberExclusive})`;
58
+ }
59
+ equals(originalRange) {
60
+ return this.startLineNumber === originalRange.startLineNumber && this.lineCount === originalRange.lineCount;
61
+ }
62
+ contains(lineNumber) {
63
+ return this.startLineNumber <= lineNumber && lineNumber < this.endLineNumberExclusive;
64
+ }
65
+ deltaEnd(delta) {
66
+ return ( new LineRange(this.startLineNumber, this.lineCount + delta));
67
+ }
68
+ deltaStart(lineDelta) {
69
+ return ( new LineRange(this.startLineNumber + lineDelta, this.lineCount - lineDelta));
70
+ }
71
+ getLines(model) {
72
+ const result = ( new Array(this.lineCount));
73
+ for (let i = 0; i < this.lineCount; i++) {
74
+ result[i] = model.getLineContent(this.startLineNumber + i);
75
+ }
76
+ return result;
77
+ }
78
+ containsRange(range) {
79
+ return this.startLineNumber <= range.startLineNumber && range.endLineNumberExclusive <= this.endLineNumberExclusive;
80
+ }
81
+ toRange() {
82
+ return ( new Range(this.startLineNumber, 1, this.endLineNumberExclusive, 1));
83
+ }
84
+ toInclusiveRange() {
85
+ if (this.isEmpty) {
86
+ return undefined;
87
+ }
88
+ return ( new Range(
89
+ this.startLineNumber,
90
+ 1,
91
+ this.endLineNumberExclusive - 1,
92
+ Constants.MAX_SAFE_SMALL_INTEGER
93
+ ));
94
+ }
95
+ toInclusiveRangeOrEmpty() {
96
+ if (this.isEmpty) {
97
+ return ( new Range(this.startLineNumber, 1, this.startLineNumber, 1));
98
+ }
99
+ return ( new Range(
100
+ this.startLineNumber,
101
+ 1,
102
+ this.endLineNumberExclusive - 1,
103
+ Constants.MAX_SAFE_SMALL_INTEGER
104
+ ));
105
+ }
106
+ intersects(lineRange) {
107
+ return this.startLineNumber <= lineRange.endLineNumberExclusive
108
+ && lineRange.startLineNumber <= this.endLineNumberExclusive;
109
+ }
110
+ }
111
+
112
+ export { LineRange };
@@ -0,0 +1,69 @@
1
+ import { Position } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/position";
2
+ import { Range } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range";
3
+ import { ITextModel } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
4
+ import { LineRangeEdit } from "./editing.js";
5
+ import { LineRange } from "./lineRange.js";
6
+ export declare class LineRangeMapping {
7
+ readonly inputRange: LineRange;
8
+ readonly outputRange: LineRange;
9
+ static join(mappings: readonly LineRangeMapping[]): LineRangeMapping | undefined;
10
+ constructor(inputRange: LineRange, outputRange: LineRange);
11
+ extendInputRange(extendedInputRange: LineRange): LineRangeMapping;
12
+ join(other: LineRangeMapping): LineRangeMapping;
13
+ get resultingDeltaFromOriginalToModified(): number;
14
+ toString(): string;
15
+ addOutputLineDelta(delta: number): LineRangeMapping;
16
+ addInputLineDelta(delta: number): LineRangeMapping;
17
+ reverse(): LineRangeMapping;
18
+ }
19
+ export declare class DocumentLineRangeMap {
20
+ readonly lineRangeMappings: LineRangeMapping[];
21
+ readonly inputLineCount: number;
22
+ static betweenOutputs(inputToOutput1: readonly LineRangeMapping[], inputToOutput2: readonly LineRangeMapping[], inputLineCount: number): DocumentLineRangeMap;
23
+ constructor(lineRangeMappings: LineRangeMapping[], inputLineCount: number);
24
+ project(lineNumber: number): LineRangeMapping;
25
+ get outputLineCount(): number;
26
+ reverse(): DocumentLineRangeMap;
27
+ }
28
+ export declare class MappingAlignment<T extends LineRangeMapping> {
29
+ readonly inputRange: LineRange;
30
+ readonly output1Range: LineRange;
31
+ readonly output1LineMappings: T[];
32
+ readonly output2Range: LineRange;
33
+ readonly output2LineMappings: T[];
34
+ static compute<T extends LineRangeMapping>(fromInputToOutput1: readonly T[], fromInputToOutput2: readonly T[]): MappingAlignment<T>[];
35
+ constructor(inputRange: LineRange, output1Range: LineRange, output1LineMappings: T[], output2Range: LineRange, output2LineMappings: T[]);
36
+ toString(): string;
37
+ }
38
+ export declare class DetailedLineRangeMapping extends LineRangeMapping {
39
+ readonly inputTextModel: ITextModel;
40
+ readonly outputTextModel: ITextModel;
41
+ static join(mappings: readonly DetailedLineRangeMapping[]): DetailedLineRangeMapping | undefined;
42
+ readonly rangeMappings: readonly RangeMapping[];
43
+ constructor(inputRange: LineRange, inputTextModel: ITextModel, outputRange: LineRange, outputTextModel: ITextModel, rangeMappings?: readonly RangeMapping[]);
44
+ addOutputLineDelta(delta: number): DetailedLineRangeMapping;
45
+ addInputLineDelta(delta: number): DetailedLineRangeMapping;
46
+ join(other: DetailedLineRangeMapping): DetailedLineRangeMapping;
47
+ getLineEdit(): LineRangeEdit;
48
+ getReverseLineEdit(): LineRangeEdit;
49
+ private getOutputLines;
50
+ private getInputLines;
51
+ }
52
+ export declare class RangeMapping {
53
+ readonly inputRange: Range;
54
+ readonly outputRange: Range;
55
+ constructor(inputRange: Range, outputRange: Range);
56
+ toString(): string;
57
+ addOutputLineDelta(deltaLines: number): RangeMapping;
58
+ addInputLineDelta(deltaLines: number): RangeMapping;
59
+ reverse(): RangeMapping;
60
+ }
61
+ export declare class DocumentRangeMap {
62
+ readonly rangeMappings: RangeMapping[];
63
+ readonly inputLineCount: number;
64
+ constructor(rangeMappings: RangeMapping[], inputLineCount: number);
65
+ project(position: Position): RangeMapping;
66
+ projectRange(range: Range): RangeMapping;
67
+ get outputLineCount(): number;
68
+ reverse(): DocumentRangeMap;
69
+ }
@@ -0,0 +1,261 @@
1
+
2
+ import { compareBy, numberComparator } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
3
+ import { findLast } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arraysFind';
4
+ import { assertFn, checkAdjacentItems } from '@codingame/monaco-vscode-api/vscode/vs/base/common/assert';
5
+ import { BugIndicatingError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
6
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
7
+ import { concatArrays } from '../utils.js';
8
+ import { LineRangeEdit } from './editing.js';
9
+ import { LineRange } from './lineRange.js';
10
+ import { rangeIsBeforeOrTouching, rangeContainsPosition, lengthBetweenPositions, addLength } from './rangeUtils.js';
11
+
12
+ class LineRangeMapping {
13
+ static join(mappings) {
14
+ return mappings.reduce((acc, cur) => acc ? acc.join(cur) : cur, undefined);
15
+ }
16
+ constructor(inputRange, outputRange) {
17
+ this.inputRange = inputRange;
18
+ this.outputRange = outputRange;
19
+ }
20
+ extendInputRange(extendedInputRange) {
21
+ if (!extendedInputRange.containsRange(this.inputRange)) {
22
+ throw ( new BugIndicatingError());
23
+ }
24
+ const startDelta = extendedInputRange.startLineNumber - this.inputRange.startLineNumber;
25
+ const endDelta = extendedInputRange.endLineNumberExclusive - this.inputRange.endLineNumberExclusive;
26
+ return ( new LineRangeMapping(extendedInputRange, ( new LineRange(
27
+ this.outputRange.startLineNumber + startDelta,
28
+ this.outputRange.lineCount - startDelta + endDelta
29
+ ))));
30
+ }
31
+ join(other) {
32
+ return ( new LineRangeMapping(
33
+ this.inputRange.join(other.inputRange),
34
+ this.outputRange.join(other.outputRange)
35
+ ));
36
+ }
37
+ get resultingDeltaFromOriginalToModified() {
38
+ return this.outputRange.endLineNumberExclusive - this.inputRange.endLineNumberExclusive;
39
+ }
40
+ toString() {
41
+ return `${( this.inputRange.toString())} -> ${( this.outputRange.toString())}`;
42
+ }
43
+ addOutputLineDelta(delta) {
44
+ return ( new LineRangeMapping(this.inputRange, this.outputRange.delta(delta)));
45
+ }
46
+ addInputLineDelta(delta) {
47
+ return ( new LineRangeMapping(this.inputRange.delta(delta), this.outputRange));
48
+ }
49
+ reverse() {
50
+ return ( new LineRangeMapping(this.outputRange, this.inputRange));
51
+ }
52
+ }
53
+ class DocumentLineRangeMap {
54
+ static betweenOutputs(inputToOutput1, inputToOutput2, inputLineCount) {
55
+ const alignments = MappingAlignment.compute(inputToOutput1, inputToOutput2);
56
+ const mappings = ( alignments.map((m) => ( new LineRangeMapping(m.output1Range, m.output2Range))));
57
+ return ( new DocumentLineRangeMap(mappings, inputLineCount));
58
+ }
59
+ constructor(
60
+ lineRangeMappings, inputLineCount) {
61
+ this.lineRangeMappings = lineRangeMappings;
62
+ this.inputLineCount = inputLineCount;
63
+ assertFn(() => {
64
+ return checkAdjacentItems(lineRangeMappings, (m1, m2) => m1.inputRange.isBefore(m2.inputRange) && m1.outputRange.isBefore(m2.outputRange) &&
65
+ m2.inputRange.startLineNumber - m1.inputRange.endLineNumberExclusive === m2.outputRange.startLineNumber - m1.outputRange.endLineNumberExclusive);
66
+ });
67
+ }
68
+ project(lineNumber) {
69
+ const lastBefore = findLast(this.lineRangeMappings, r => r.inputRange.startLineNumber <= lineNumber);
70
+ if (!lastBefore) {
71
+ return ( new LineRangeMapping(( new LineRange(lineNumber, 1)), ( new LineRange(lineNumber, 1))));
72
+ }
73
+ if (lastBefore.inputRange.contains(lineNumber)) {
74
+ return lastBefore;
75
+ }
76
+ const containingRange = ( new LineRange(lineNumber, 1));
77
+ const mappedRange = ( new LineRange(lineNumber +
78
+ lastBefore.outputRange.endLineNumberExclusive -
79
+ lastBefore.inputRange.endLineNumberExclusive, 1));
80
+ return ( new LineRangeMapping(containingRange, mappedRange));
81
+ }
82
+ get outputLineCount() {
83
+ const last = this.lineRangeMappings.at(-1);
84
+ const diff = last ? last.outputRange.endLineNumberExclusive - last.inputRange.endLineNumberExclusive : 0;
85
+ return this.inputLineCount + diff;
86
+ }
87
+ reverse() {
88
+ return ( new DocumentLineRangeMap(( this.lineRangeMappings.map(r => r.reverse())), this.outputLineCount));
89
+ }
90
+ }
91
+ class MappingAlignment {
92
+ static compute(fromInputToOutput1, fromInputToOutput2) {
93
+ const compareByStartLineNumber = compareBy((d) => d.inputRange.startLineNumber, numberComparator);
94
+ const combinedDiffs = concatArrays(( fromInputToOutput1.map((diff) => ({ source: 0, diff }))), ( fromInputToOutput2.map((diff) => ({ source: 1, diff })))).sort(compareBy((d) => d.diff, compareByStartLineNumber));
95
+ const currentDiffs = [( new Array()), ( new Array())];
96
+ const deltaFromBaseToInput = [0, 0];
97
+ const alignments = ( new Array());
98
+ function pushAndReset(inputRange) {
99
+ const mapping1 = LineRangeMapping.join(currentDiffs[0]) || ( new LineRangeMapping(inputRange, inputRange.delta(deltaFromBaseToInput[0])));
100
+ const mapping2 = LineRangeMapping.join(currentDiffs[1]) || ( new LineRangeMapping(inputRange, inputRange.delta(deltaFromBaseToInput[1])));
101
+ alignments.push(( new MappingAlignment(
102
+ currentInputRange,
103
+ mapping1.extendInputRange(currentInputRange).outputRange,
104
+ currentDiffs[0],
105
+ mapping2.extendInputRange(currentInputRange).outputRange,
106
+ currentDiffs[1]
107
+ )));
108
+ currentDiffs[0] = [];
109
+ currentDiffs[1] = [];
110
+ }
111
+ let currentInputRange;
112
+ for (const diff of combinedDiffs) {
113
+ const range = diff.diff.inputRange;
114
+ if (currentInputRange && !currentInputRange.touches(range)) {
115
+ pushAndReset(currentInputRange);
116
+ currentInputRange = undefined;
117
+ }
118
+ deltaFromBaseToInput[diff.source] =
119
+ diff.diff.resultingDeltaFromOriginalToModified;
120
+ currentInputRange = currentInputRange ? currentInputRange.join(range) : range;
121
+ currentDiffs[diff.source].push(diff.diff);
122
+ }
123
+ if (currentInputRange) {
124
+ pushAndReset(currentInputRange);
125
+ }
126
+ return alignments;
127
+ }
128
+ constructor(inputRange, output1Range, output1LineMappings, output2Range, output2LineMappings) {
129
+ this.inputRange = inputRange;
130
+ this.output1Range = output1Range;
131
+ this.output1LineMappings = output1LineMappings;
132
+ this.output2Range = output2Range;
133
+ this.output2LineMappings = output2LineMappings;
134
+ }
135
+ toString() {
136
+ return `${this.output1Range} <- ${this.inputRange} -> ${this.output2Range}`;
137
+ }
138
+ }
139
+ class DetailedLineRangeMapping extends LineRangeMapping {
140
+ static join(mappings) {
141
+ return mappings.reduce((acc, cur) => acc ? acc.join(cur) : cur, undefined);
142
+ }
143
+ constructor(inputRange, inputTextModel, outputRange, outputTextModel, rangeMappings) {
144
+ super(inputRange, outputRange);
145
+ this.inputTextModel = inputTextModel;
146
+ this.outputTextModel = outputTextModel;
147
+ this.rangeMappings = rangeMappings || [( new RangeMapping(this.inputRange.toRange(), this.outputRange.toRange()))];
148
+ }
149
+ addOutputLineDelta(delta) {
150
+ return ( new DetailedLineRangeMapping(
151
+ this.inputRange,
152
+ this.inputTextModel,
153
+ this.outputRange.delta(delta),
154
+ this.outputTextModel,
155
+ ( this.rangeMappings.map(d => d.addOutputLineDelta(delta)))
156
+ ));
157
+ }
158
+ addInputLineDelta(delta) {
159
+ return ( new DetailedLineRangeMapping(
160
+ this.inputRange.delta(delta),
161
+ this.inputTextModel,
162
+ this.outputRange,
163
+ this.outputTextModel,
164
+ ( this.rangeMappings.map(d => d.addInputLineDelta(delta)))
165
+ ));
166
+ }
167
+ join(other) {
168
+ return ( new DetailedLineRangeMapping(
169
+ this.inputRange.join(other.inputRange),
170
+ this.inputTextModel,
171
+ this.outputRange.join(other.outputRange),
172
+ this.outputTextModel
173
+ ));
174
+ }
175
+ getLineEdit() {
176
+ return ( new LineRangeEdit(this.inputRange, this.getOutputLines()));
177
+ }
178
+ getReverseLineEdit() {
179
+ return ( new LineRangeEdit(this.outputRange, this.getInputLines()));
180
+ }
181
+ getOutputLines() {
182
+ return this.outputRange.getLines(this.outputTextModel);
183
+ }
184
+ getInputLines() {
185
+ return this.inputRange.getLines(this.inputTextModel);
186
+ }
187
+ }
188
+ class RangeMapping {
189
+ constructor(inputRange, outputRange) {
190
+ this.inputRange = inputRange;
191
+ this.outputRange = outputRange;
192
+ }
193
+ toString() {
194
+ function rangeToString(range) {
195
+ return `[${range.startLineNumber}:${range.startColumn}, ${range.endLineNumber}:${range.endColumn})`;
196
+ }
197
+ return `${rangeToString(this.inputRange)} -> ${rangeToString(this.outputRange)}`;
198
+ }
199
+ addOutputLineDelta(deltaLines) {
200
+ return ( new RangeMapping(this.inputRange, ( new Range(
201
+ this.outputRange.startLineNumber + deltaLines,
202
+ this.outputRange.startColumn,
203
+ this.outputRange.endLineNumber + deltaLines,
204
+ this.outputRange.endColumn
205
+ ))));
206
+ }
207
+ addInputLineDelta(deltaLines) {
208
+ return ( new RangeMapping(( new Range(
209
+ this.inputRange.startLineNumber + deltaLines,
210
+ this.inputRange.startColumn,
211
+ this.inputRange.endLineNumber + deltaLines,
212
+ this.inputRange.endColumn
213
+ )), this.outputRange));
214
+ }
215
+ reverse() {
216
+ return ( new RangeMapping(this.outputRange, this.inputRange));
217
+ }
218
+ }
219
+ class DocumentRangeMap {
220
+ constructor(
221
+ rangeMappings, inputLineCount) {
222
+ this.rangeMappings = rangeMappings;
223
+ this.inputLineCount = inputLineCount;
224
+ assertFn(() => checkAdjacentItems(rangeMappings, (m1, m2) => rangeIsBeforeOrTouching(m1.inputRange, m2.inputRange) &&
225
+ rangeIsBeforeOrTouching(m1.outputRange, m2.outputRange)
226
+ ));
227
+ }
228
+ project(position) {
229
+ const lastBefore = findLast(this.rangeMappings, r => r.inputRange.getStartPosition().isBeforeOrEqual(position));
230
+ if (!lastBefore) {
231
+ return ( new RangeMapping(
232
+ Range.fromPositions(position, position),
233
+ Range.fromPositions(position, position)
234
+ ));
235
+ }
236
+ if (rangeContainsPosition(lastBefore.inputRange, position)) {
237
+ return lastBefore;
238
+ }
239
+ const dist = lengthBetweenPositions(lastBefore.inputRange.getEndPosition(), position);
240
+ const outputPos = addLength(lastBefore.outputRange.getEndPosition(), dist);
241
+ return ( new RangeMapping(Range.fromPositions(position), Range.fromPositions(outputPos)));
242
+ }
243
+ projectRange(range) {
244
+ const start = this.project(range.getStartPosition());
245
+ const end = this.project(range.getEndPosition());
246
+ return ( new RangeMapping(
247
+ start.inputRange.plusRange(end.inputRange),
248
+ start.outputRange.plusRange(end.outputRange)
249
+ ));
250
+ }
251
+ get outputLineCount() {
252
+ const last = this.rangeMappings.at(-1);
253
+ const diff = last ? last.outputRange.endLineNumber - last.inputRange.endLineNumber : 0;
254
+ return this.inputLineCount + diff;
255
+ }
256
+ reverse() {
257
+ return ( new DocumentRangeMap(( this.rangeMappings.map(m => m.reverse())), this.outputLineCount));
258
+ }
259
+ }
260
+
261
+ export { DetailedLineRangeMapping, DocumentLineRangeMap, DocumentRangeMap, LineRangeMapping, MappingAlignment, RangeMapping };
@@ -0,0 +1,112 @@
1
+ import { ITextModel } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
2
+ import { LineRangeEdit } from "./editing.js";
3
+ import { LineRange } from "./lineRange.js";
4
+ import { DetailedLineRangeMapping } from "./mapping.js";
5
+ export declare class ModifiedBaseRange {
6
+ readonly baseRange: LineRange;
7
+ readonly baseTextModel: ITextModel;
8
+ readonly input1Range: LineRange;
9
+ readonly input1TextModel: ITextModel;
10
+ readonly input1Diffs: readonly DetailedLineRangeMapping[];
11
+ readonly input2Range: LineRange;
12
+ readonly input2TextModel: ITextModel;
13
+ readonly input2Diffs: readonly DetailedLineRangeMapping[];
14
+ static fromDiffs(diffs1: readonly DetailedLineRangeMapping[], diffs2: readonly DetailedLineRangeMapping[], baseTextModel: ITextModel, input1TextModel: ITextModel, input2TextModel: ITextModel): ModifiedBaseRange[];
15
+ readonly input1CombinedDiff: DetailedLineRangeMapping | undefined;
16
+ readonly input2CombinedDiff: DetailedLineRangeMapping | undefined;
17
+ readonly isEqualChange: boolean;
18
+ constructor(baseRange: LineRange, baseTextModel: ITextModel, input1Range: LineRange, input1TextModel: ITextModel, input1Diffs: readonly DetailedLineRangeMapping[], input2Range: LineRange, input2TextModel: ITextModel, input2Diffs: readonly DetailedLineRangeMapping[]);
19
+ getInputRange(inputNumber: 1 | 2): LineRange;
20
+ getInputCombinedDiff(inputNumber: 1 | 2): DetailedLineRangeMapping | undefined;
21
+ getInputDiffs(inputNumber: 1 | 2): readonly DetailedLineRangeMapping[];
22
+ get isConflicting(): boolean;
23
+ get canBeCombined(): boolean;
24
+ get isOrderRelevant(): boolean;
25
+ getEditForBase(state: ModifiedBaseRangeState): {
26
+ edit: LineRangeEdit | undefined;
27
+ effectiveState: ModifiedBaseRangeState;
28
+ };
29
+ private smartInput1LineRangeEdit;
30
+ private smartInput2LineRangeEdit;
31
+ private smartCombineInputs;
32
+ private dumbInput1LineRangeEdit;
33
+ private dumbInput2LineRangeEdit;
34
+ private dumbCombineInputs;
35
+ }
36
+ export declare enum ModifiedBaseRangeStateKind {
37
+ base = 0,
38
+ input1 = 1,
39
+ input2 = 2,
40
+ both = 3,
41
+ unrecognized = 4
42
+ }
43
+ export type InputNumber = 1 | 2;
44
+ export declare function getOtherInputNumber(inputNumber: InputNumber): InputNumber;
45
+ export declare abstract class AbstractModifiedBaseRangeState {
46
+ constructor();
47
+ abstract get kind(): ModifiedBaseRangeStateKind;
48
+ get includesInput1(): boolean;
49
+ get includesInput2(): boolean;
50
+ includesInput(inputNumber: InputNumber): boolean;
51
+ isInputIncluded(inputNumber: InputNumber): boolean;
52
+ abstract toString(): string;
53
+ abstract swap(): ModifiedBaseRangeState;
54
+ abstract withInputValue(inputNumber: InputNumber, value: boolean, smartCombination?: boolean): ModifiedBaseRangeState;
55
+ abstract equals(other: ModifiedBaseRangeState): boolean;
56
+ toggle(inputNumber: InputNumber): ModifiedBaseRangeState;
57
+ getInput(inputNumber: 1 | 2): InputState;
58
+ }
59
+ export declare class ModifiedBaseRangeStateBase extends AbstractModifiedBaseRangeState {
60
+ get kind(): ModifiedBaseRangeStateKind.base;
61
+ toString(): string;
62
+ swap(): ModifiedBaseRangeState;
63
+ withInputValue(inputNumber: InputNumber, value: boolean, smartCombination?: boolean): ModifiedBaseRangeState;
64
+ equals(other: ModifiedBaseRangeState): boolean;
65
+ }
66
+ export declare class ModifiedBaseRangeStateInput1 extends AbstractModifiedBaseRangeState {
67
+ get kind(): ModifiedBaseRangeStateKind.input1;
68
+ get includesInput1(): boolean;
69
+ toString(): string;
70
+ swap(): ModifiedBaseRangeState;
71
+ withInputValue(inputNumber: InputNumber, value: boolean, smartCombination?: boolean): ModifiedBaseRangeState;
72
+ equals(other: ModifiedBaseRangeState): boolean;
73
+ }
74
+ export declare class ModifiedBaseRangeStateInput2 extends AbstractModifiedBaseRangeState {
75
+ get kind(): ModifiedBaseRangeStateKind.input2;
76
+ get includesInput2(): boolean;
77
+ toString(): string;
78
+ swap(): ModifiedBaseRangeState;
79
+ withInputValue(inputNumber: InputNumber, value: boolean, smartCombination?: boolean): ModifiedBaseRangeState;
80
+ equals(other: ModifiedBaseRangeState): boolean;
81
+ }
82
+ export declare class ModifiedBaseRangeStateBoth extends AbstractModifiedBaseRangeState {
83
+ readonly firstInput: InputNumber;
84
+ readonly smartCombination: boolean;
85
+ constructor(firstInput: InputNumber, smartCombination: boolean);
86
+ get kind(): ModifiedBaseRangeStateKind.both;
87
+ get includesInput1(): boolean;
88
+ get includesInput2(): boolean;
89
+ toString(): string;
90
+ swap(): ModifiedBaseRangeState;
91
+ withInputValue(inputNumber: InputNumber, value: boolean, smartCombination?: boolean): ModifiedBaseRangeState;
92
+ equals(other: ModifiedBaseRangeState): boolean;
93
+ getInput(inputNumber: 1 | 2): InputState;
94
+ }
95
+ export declare class ModifiedBaseRangeStateUnrecognized extends AbstractModifiedBaseRangeState {
96
+ get kind(): ModifiedBaseRangeStateKind.unrecognized;
97
+ toString(): string;
98
+ swap(): ModifiedBaseRangeState;
99
+ withInputValue(inputNumber: InputNumber, value: boolean, smartCombination?: boolean): ModifiedBaseRangeState;
100
+ equals(other: ModifiedBaseRangeState): boolean;
101
+ }
102
+ export type ModifiedBaseRangeState = ModifiedBaseRangeStateBase | ModifiedBaseRangeStateInput1 | ModifiedBaseRangeStateInput2 | ModifiedBaseRangeStateInput2 | ModifiedBaseRangeStateBoth | ModifiedBaseRangeStateUnrecognized;
103
+ export declare namespace ModifiedBaseRangeState {
104
+ const base: ModifiedBaseRangeStateBase;
105
+ const unrecognized: ModifiedBaseRangeStateUnrecognized;
106
+ }
107
+ export declare enum InputState {
108
+ excluded = 0,
109
+ first = 1,
110
+ second = 2,
111
+ unrecognized = 3
112
+ }
@@ -0,0 +1,315 @@
1
+
2
+ import { equals, tieBreakComparators, compareBy, numberComparator } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
3
+ import { BugIndicatingError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
4
+ import { splitLines } from '@codingame/monaco-vscode-api/vscode/vs/base/common/strings';
5
+ import { Constants } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uint';
6
+ import { Position } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/position';
7
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
8
+ import { RangeEdit, LineRangeEdit } from './editing.js';
9
+ import { MappingAlignment, DetailedLineRangeMapping } from './mapping.js';
10
+ import { concatArrays } from '../utils.js';
11
+
12
+ class ModifiedBaseRange {
13
+ static fromDiffs(diffs1, diffs2, baseTextModel, input1TextModel, input2TextModel) {
14
+ const alignments = MappingAlignment.compute(diffs1, diffs2);
15
+ return ( alignments.map((a) => ( new ModifiedBaseRange(
16
+ a.inputRange,
17
+ baseTextModel,
18
+ a.output1Range,
19
+ input1TextModel,
20
+ a.output1LineMappings,
21
+ a.output2Range,
22
+ input2TextModel,
23
+ a.output2LineMappings
24
+ ))));
25
+ }
26
+ constructor(baseRange, baseTextModel, input1Range, input1TextModel,
27
+ input1Diffs, input2Range, input2TextModel,
28
+ input2Diffs) {
29
+ this.baseRange = baseRange;
30
+ this.baseTextModel = baseTextModel;
31
+ this.input1Range = input1Range;
32
+ this.input1TextModel = input1TextModel;
33
+ this.input1Diffs = input1Diffs;
34
+ this.input2Range = input2Range;
35
+ this.input2TextModel = input2TextModel;
36
+ this.input2Diffs = input2Diffs;
37
+ this.input1CombinedDiff = DetailedLineRangeMapping.join(this.input1Diffs);
38
+ this.input2CombinedDiff = DetailedLineRangeMapping.join(this.input2Diffs);
39
+ this.isEqualChange = equals(this.input1Diffs, this.input2Diffs, (a, b) => a.getLineEdit().equals(b.getLineEdit()));
40
+ this.smartInput1LineRangeEdit = null;
41
+ this.smartInput2LineRangeEdit = null;
42
+ this.dumbInput1LineRangeEdit = null;
43
+ this.dumbInput2LineRangeEdit = null;
44
+ if (this.input1Diffs.length === 0 && this.input2Diffs.length === 0) {
45
+ throw ( new BugIndicatingError('must have at least one diff'));
46
+ }
47
+ }
48
+ getInputRange(inputNumber) {
49
+ return inputNumber === 1 ? this.input1Range : this.input2Range;
50
+ }
51
+ getInputCombinedDiff(inputNumber) {
52
+ return inputNumber === 1 ? this.input1CombinedDiff : this.input2CombinedDiff;
53
+ }
54
+ getInputDiffs(inputNumber) {
55
+ return inputNumber === 1 ? this.input1Diffs : this.input2Diffs;
56
+ }
57
+ get isConflicting() {
58
+ return this.input1Diffs.length > 0 && this.input2Diffs.length > 0;
59
+ }
60
+ get canBeCombined() {
61
+ return this.smartCombineInputs(1) !== undefined;
62
+ }
63
+ get isOrderRelevant() {
64
+ const input1 = this.smartCombineInputs(1);
65
+ const input2 = this.smartCombineInputs(2);
66
+ if (!input1 || !input2) {
67
+ return false;
68
+ }
69
+ return !input1.equals(input2);
70
+ }
71
+ getEditForBase(state) {
72
+ const diffs = [];
73
+ if (state.includesInput1 && this.input1CombinedDiff) {
74
+ diffs.push({ diff: this.input1CombinedDiff, inputNumber: 1 });
75
+ }
76
+ if (state.includesInput2 && this.input2CombinedDiff) {
77
+ diffs.push({ diff: this.input2CombinedDiff, inputNumber: 2 });
78
+ }
79
+ if (diffs.length === 0) {
80
+ return { edit: undefined, effectiveState: ModifiedBaseRangeState.base };
81
+ }
82
+ if (diffs.length === 1) {
83
+ return { edit: diffs[0].diff.getLineEdit(), effectiveState: ModifiedBaseRangeState.base.withInputValue(diffs[0].inputNumber, true, false) };
84
+ }
85
+ if (state.kind !== ModifiedBaseRangeStateKind.both) {
86
+ throw ( new BugIndicatingError());
87
+ }
88
+ const smartCombinedEdit = state.smartCombination ? this.smartCombineInputs(state.firstInput) : this.dumbCombineInputs(state.firstInput);
89
+ if (smartCombinedEdit) {
90
+ return { edit: smartCombinedEdit, effectiveState: state };
91
+ }
92
+ return {
93
+ edit: diffs[getOtherInputNumber(state.firstInput) - 1].diff.getLineEdit(),
94
+ effectiveState: ModifiedBaseRangeState.base.withInputValue(getOtherInputNumber(state.firstInput), true, false),
95
+ };
96
+ }
97
+ smartCombineInputs(firstInput) {
98
+ if (firstInput === 1 && this.smartInput1LineRangeEdit !== null) {
99
+ return this.smartInput1LineRangeEdit;
100
+ }
101
+ else if (firstInput === 2 && this.smartInput2LineRangeEdit !== null) {
102
+ return this.smartInput2LineRangeEdit;
103
+ }
104
+ const combinedDiffs = concatArrays(this.input1Diffs.flatMap((diffs) => ( diffs.rangeMappings.map((diff) => ({ diff, input: 1 })))), this.input2Diffs.flatMap((diffs) => ( diffs.rangeMappings.map((diff) => ({ diff, input: 2 }))))).sort(tieBreakComparators(compareBy((d) => d.diff.inputRange, Range.compareRangesUsingStarts), compareBy((d) => (d.input === firstInput ? 1 : 2), numberComparator)));
105
+ const sortedEdits = ( combinedDiffs.map(d => {
106
+ const sourceTextModel = d.input === 1 ? this.input1TextModel : this.input2TextModel;
107
+ return ( new RangeEdit(d.diff.inputRange, sourceTextModel.getValueInRange(d.diff.outputRange)));
108
+ }));
109
+ const result = editsToLineRangeEdit(this.baseRange, sortedEdits, this.baseTextModel);
110
+ if (firstInput === 1) {
111
+ this.smartInput1LineRangeEdit = result;
112
+ }
113
+ else {
114
+ this.smartInput2LineRangeEdit = result;
115
+ }
116
+ return result;
117
+ }
118
+ dumbCombineInputs(firstInput) {
119
+ if (firstInput === 1 && this.dumbInput1LineRangeEdit !== null) {
120
+ return this.dumbInput1LineRangeEdit;
121
+ }
122
+ else if (firstInput === 2 && this.dumbInput2LineRangeEdit !== null) {
123
+ return this.dumbInput2LineRangeEdit;
124
+ }
125
+ let input1Lines = this.input1Range.getLines(this.input1TextModel);
126
+ let input2Lines = this.input2Range.getLines(this.input2TextModel);
127
+ if (firstInput === 2) {
128
+ [input1Lines, input2Lines] = [input2Lines, input1Lines];
129
+ }
130
+ const result = ( new LineRangeEdit(this.baseRange, input1Lines.concat(input2Lines)));
131
+ if (firstInput === 1) {
132
+ this.dumbInput1LineRangeEdit = result;
133
+ }
134
+ else {
135
+ this.dumbInput2LineRangeEdit = result;
136
+ }
137
+ return result;
138
+ }
139
+ }
140
+ function editsToLineRangeEdit(range, sortedEdits, textModel) {
141
+ let text = '';
142
+ const startsLineBefore = range.startLineNumber > 1;
143
+ let currentPosition = startsLineBefore
144
+ ? ( new Position(
145
+ range.startLineNumber - 1,
146
+ textModel.getLineMaxColumn(range.startLineNumber - 1)
147
+ ))
148
+ : ( new Position(range.startLineNumber, 1));
149
+ for (const edit of sortedEdits) {
150
+ const diffStart = edit.range.getStartPosition();
151
+ if (!currentPosition.isBeforeOrEqual(diffStart)) {
152
+ return undefined;
153
+ }
154
+ let originalText = textModel.getValueInRange(Range.fromPositions(currentPosition, diffStart));
155
+ if (diffStart.lineNumber > textModel.getLineCount()) {
156
+ originalText += '\n';
157
+ }
158
+ text += originalText;
159
+ text += edit.newText;
160
+ currentPosition = edit.range.getEndPosition();
161
+ }
162
+ const endsLineAfter = range.endLineNumberExclusive <= textModel.getLineCount();
163
+ const end = endsLineAfter ? ( new Position(range.endLineNumberExclusive, 1)) : ( new Position(range.endLineNumberExclusive - 1, Constants.MAX_SAFE_SMALL_INTEGER));
164
+ const originalText = textModel.getValueInRange(Range.fromPositions(currentPosition, end));
165
+ text += originalText;
166
+ const lines = splitLines(text);
167
+ if (startsLineBefore) {
168
+ if (lines[0] !== '') {
169
+ return undefined;
170
+ }
171
+ lines.shift();
172
+ }
173
+ if (endsLineAfter) {
174
+ if (lines[lines.length - 1] !== '') {
175
+ return undefined;
176
+ }
177
+ lines.pop();
178
+ }
179
+ return ( new LineRangeEdit(range, lines));
180
+ }
181
+ var ModifiedBaseRangeStateKind;
182
+ (function (ModifiedBaseRangeStateKind) {
183
+ ModifiedBaseRangeStateKind[ModifiedBaseRangeStateKind["base"] = 0] = "base";
184
+ ModifiedBaseRangeStateKind[ModifiedBaseRangeStateKind["input1"] = 1] = "input1";
185
+ ModifiedBaseRangeStateKind[ModifiedBaseRangeStateKind["input2"] = 2] = "input2";
186
+ ModifiedBaseRangeStateKind[ModifiedBaseRangeStateKind["both"] = 3] = "both";
187
+ ModifiedBaseRangeStateKind[ModifiedBaseRangeStateKind["unrecognized"] = 4] = "unrecognized";
188
+ })(ModifiedBaseRangeStateKind || (ModifiedBaseRangeStateKind = {}));
189
+ function getOtherInputNumber(inputNumber) {
190
+ return inputNumber === 1 ? 2 : 1;
191
+ }
192
+ class AbstractModifiedBaseRangeState {
193
+ constructor() { }
194
+ get includesInput1() { return false; }
195
+ get includesInput2() { return false; }
196
+ includesInput(inputNumber) {
197
+ return inputNumber === 1 ? this.includesInput1 : this.includesInput2;
198
+ }
199
+ isInputIncluded(inputNumber) {
200
+ return inputNumber === 1 ? this.includesInput1 : this.includesInput2;
201
+ }
202
+ toggle(inputNumber) {
203
+ return this.withInputValue(inputNumber, !this.includesInput(inputNumber), true);
204
+ }
205
+ getInput(inputNumber) {
206
+ if (!this.isInputIncluded(inputNumber)) {
207
+ return InputState.excluded;
208
+ }
209
+ return InputState.first;
210
+ }
211
+ }
212
+ class ModifiedBaseRangeStateBase extends AbstractModifiedBaseRangeState {
213
+ get kind() { return ModifiedBaseRangeStateKind.base; }
214
+ toString() { return 'base'; }
215
+ swap() { return this; }
216
+ withInputValue(inputNumber, value, smartCombination = false) {
217
+ if (inputNumber === 1) {
218
+ return value ? ( new ModifiedBaseRangeStateInput1()) : this;
219
+ }
220
+ else {
221
+ return value ? ( new ModifiedBaseRangeStateInput2()) : this;
222
+ }
223
+ }
224
+ equals(other) {
225
+ return other.kind === ModifiedBaseRangeStateKind.base;
226
+ }
227
+ }
228
+ class ModifiedBaseRangeStateInput1 extends AbstractModifiedBaseRangeState {
229
+ get kind() { return ModifiedBaseRangeStateKind.input1; }
230
+ get includesInput1() { return true; }
231
+ toString() { return '1✓'; }
232
+ swap() { return ( new ModifiedBaseRangeStateInput2()); }
233
+ withInputValue(inputNumber, value, smartCombination = false) {
234
+ if (inputNumber === 1) {
235
+ return value ? this : ( new ModifiedBaseRangeStateBase());
236
+ }
237
+ else {
238
+ return value ? ( new ModifiedBaseRangeStateBoth(1, smartCombination)) : ( new ModifiedBaseRangeStateInput2());
239
+ }
240
+ }
241
+ equals(other) {
242
+ return other.kind === ModifiedBaseRangeStateKind.input1;
243
+ }
244
+ }
245
+ class ModifiedBaseRangeStateInput2 extends AbstractModifiedBaseRangeState {
246
+ get kind() { return ModifiedBaseRangeStateKind.input2; }
247
+ get includesInput2() { return true; }
248
+ toString() { return '2✓'; }
249
+ swap() { return ( new ModifiedBaseRangeStateInput1()); }
250
+ withInputValue(inputNumber, value, smartCombination = false) {
251
+ if (inputNumber === 2) {
252
+ return value ? this : ( new ModifiedBaseRangeStateBase());
253
+ }
254
+ else {
255
+ return value ? ( new ModifiedBaseRangeStateBoth(2, smartCombination)) : ( new ModifiedBaseRangeStateInput2());
256
+ }
257
+ }
258
+ equals(other) {
259
+ return other.kind === ModifiedBaseRangeStateKind.input2;
260
+ }
261
+ }
262
+ class ModifiedBaseRangeStateBoth extends AbstractModifiedBaseRangeState {
263
+ constructor(firstInput, smartCombination) {
264
+ super();
265
+ this.firstInput = firstInput;
266
+ this.smartCombination = smartCombination;
267
+ }
268
+ get kind() { return ModifiedBaseRangeStateKind.both; }
269
+ get includesInput1() { return true; }
270
+ get includesInput2() { return true; }
271
+ toString() {
272
+ return '2✓';
273
+ }
274
+ swap() { return ( new ModifiedBaseRangeStateBoth(getOtherInputNumber(this.firstInput), this.smartCombination)); }
275
+ withInputValue(inputNumber, value, smartCombination = false) {
276
+ if (value) {
277
+ return this;
278
+ }
279
+ return inputNumber === 1 ? ( new ModifiedBaseRangeStateInput2()) : ( new ModifiedBaseRangeStateInput1());
280
+ }
281
+ equals(other) {
282
+ return other.kind === ModifiedBaseRangeStateKind.both && this.firstInput === other.firstInput && this.smartCombination === other.smartCombination;
283
+ }
284
+ getInput(inputNumber) {
285
+ return inputNumber === this.firstInput ? InputState.first : InputState.second;
286
+ }
287
+ }
288
+ class ModifiedBaseRangeStateUnrecognized extends AbstractModifiedBaseRangeState {
289
+ get kind() { return ModifiedBaseRangeStateKind.unrecognized; }
290
+ toString() { return 'unrecognized'; }
291
+ swap() { return this; }
292
+ withInputValue(inputNumber, value, smartCombination = false) {
293
+ if (!value) {
294
+ return this;
295
+ }
296
+ return inputNumber === 1 ? ( new ModifiedBaseRangeStateInput1()) : ( new ModifiedBaseRangeStateInput2());
297
+ }
298
+ equals(other) {
299
+ return other.kind === ModifiedBaseRangeStateKind.unrecognized;
300
+ }
301
+ }
302
+ var ModifiedBaseRangeState;
303
+ (function (ModifiedBaseRangeState) {
304
+ ModifiedBaseRangeState.base = ( new ModifiedBaseRangeStateBase());
305
+ ModifiedBaseRangeState.unrecognized = ( new ModifiedBaseRangeStateUnrecognized());
306
+ })(ModifiedBaseRangeState || (ModifiedBaseRangeState = {}));
307
+ var InputState;
308
+ (function (InputState) {
309
+ InputState[InputState["excluded"] = 0] = "excluded";
310
+ InputState[InputState["first"] = 1] = "first";
311
+ InputState[InputState["second"] = 2] = "second";
312
+ InputState[InputState["unrecognized"] = 3] = "unrecognized";
313
+ })(InputState || (InputState = {}));
314
+
315
+ export { AbstractModifiedBaseRangeState, InputState, ModifiedBaseRange, ModifiedBaseRangeState, ModifiedBaseRangeStateBase, ModifiedBaseRangeStateBoth, ModifiedBaseRangeStateInput1, ModifiedBaseRangeStateInput2, ModifiedBaseRangeStateKind, ModifiedBaseRangeStateUnrecognized, getOtherInputNumber };
@@ -0,0 +1,8 @@
1
+ import { Position } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/position";
2
+ import { Range } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range";
3
+ import { TextLength } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/textLength";
4
+ export declare function rangeContainsPosition(range: Range, position: Position): boolean;
5
+ export declare function lengthOfRange(range: Range): TextLength;
6
+ export declare function lengthBetweenPositions(position1: Position, position2: Position): TextLength;
7
+ export declare function addLength(position: Position, length: TextLength): Position;
8
+ export declare function rangeIsBeforeOrTouching(range: Range, other: Range): boolean;
@@ -0,0 +1,47 @@
1
+
2
+ import { Position } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/position';
3
+ import { TextLength } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/textLength';
4
+
5
+ function rangeContainsPosition(range, position) {
6
+ if (position.lineNumber < range.startLineNumber || position.lineNumber > range.endLineNumber) {
7
+ return false;
8
+ }
9
+ if (position.lineNumber === range.startLineNumber && position.column < range.startColumn) {
10
+ return false;
11
+ }
12
+ if (position.lineNumber === range.endLineNumber && position.column >= range.endColumn) {
13
+ return false;
14
+ }
15
+ return true;
16
+ }
17
+ function lengthOfRange(range) {
18
+ if (range.startLineNumber === range.endLineNumber) {
19
+ return ( new TextLength(0, range.endColumn - range.startColumn));
20
+ }
21
+ else {
22
+ return ( new TextLength(range.endLineNumber - range.startLineNumber, range.endColumn - 1));
23
+ }
24
+ }
25
+ function lengthBetweenPositions(position1, position2) {
26
+ if (position1.lineNumber === position2.lineNumber) {
27
+ return ( new TextLength(0, position2.column - position1.column));
28
+ }
29
+ else {
30
+ return ( new TextLength(position2.lineNumber - position1.lineNumber, position2.column - 1));
31
+ }
32
+ }
33
+ function addLength(position, length) {
34
+ if (length.lineCount === 0) {
35
+ return ( new Position(position.lineNumber, position.column + length.columnCount));
36
+ }
37
+ else {
38
+ return ( new Position(position.lineNumber + length.lineCount, length.columnCount + 1));
39
+ }
40
+ }
41
+ function rangeIsBeforeOrTouching(range, other) {
42
+ return (range.endLineNumber < other.startLineNumber ||
43
+ (range.endLineNumber === other.startLineNumber &&
44
+ range.endColumn <= other.startColumn));
45
+ }
46
+
47
+ export { addLength, lengthBetweenPositions, lengthOfRange, rangeContainsPosition, rangeIsBeforeOrTouching };
@@ -0,0 +1,35 @@
1
+ import { CompareResult } from "@codingame/monaco-vscode-api/vscode/vs/base/common/arrays";
2
+ import { IDisposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
3
+ import { IObservable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/observable";
4
+ import { CodeEditorWidget } from "@codingame/monaco-vscode-api/vscode/vs/editor/browser/widget/codeEditor/codeEditorWidget";
5
+ import { IModelDeltaDecoration } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
6
+ import { IStorageService } from "@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service";
7
+ export declare function setStyle(element: HTMLElement, style: {
8
+ width?: number | string;
9
+ height?: number | string;
10
+ left?: number | string;
11
+ top?: number | string;
12
+ }): void;
13
+ export declare function applyObservableDecorations(editor: CodeEditorWidget, decorations: IObservable<IModelDeltaDecoration[]>): IDisposable;
14
+ export declare function leftJoin<TLeft, TRight>(left: Iterable<TLeft>, right: readonly TRight[], compare: (left: TLeft, right: TRight) => CompareResult): IterableIterator<{
15
+ left: TLeft;
16
+ rights: TRight[];
17
+ }>;
18
+ export declare function join<TLeft, TRight>(left: Iterable<TLeft>, right: readonly TRight[], compare: (left: TLeft, right: TRight) => CompareResult): IterableIterator<{
19
+ left?: TLeft;
20
+ rights: TRight[];
21
+ }>;
22
+ export declare function concatArrays<TArr extends any[]>(...arrays: TArr): TArr[number][number][];
23
+ export declare function elementAtOrUndefined<T>(arr: T[], index: number): T | undefined;
24
+ export declare function thenIfNotDisposed<T>(promise: Promise<T>, then: () => void): IDisposable;
25
+ export declare function setFields<T extends {}>(obj: T, fields: Partial<T>): T;
26
+ export declare function deepMerge<T extends {}>(source1: T, source2: Partial<T>): T;
27
+ export declare class PersistentStore<T> {
28
+ private readonly key;
29
+ private readonly storageService;
30
+ private hasValue;
31
+ private value;
32
+ constructor(key: string, storageService: IStorageService);
33
+ get(): Readonly<T> | undefined;
34
+ set(newValue: T | undefined): void;
35
+ }
@@ -0,0 +1,121 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { ArrayQueue, CompareResult } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
4
+ import { onUnexpectedError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
5
+ import { DisposableStore, toDisposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
6
+ import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
7
+ import { StorageScope, StorageTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
8
+ import { IStorageService } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service';
9
+ import { autorunOpts } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/autorun';
10
+
11
+ function setStyle(element, style) {
12
+ Object.entries(style).forEach(([key, value]) => {
13
+ element.style.setProperty(key, toSize(value));
14
+ });
15
+ }
16
+ function toSize(value) {
17
+ return typeof value === 'number' ? `${value}px` : value;
18
+ }
19
+ function applyObservableDecorations(editor, decorations) {
20
+ const d = ( new DisposableStore());
21
+ let decorationIds = [];
22
+ d.add(autorunOpts({ debugName: () => `Apply decorations from ${decorations.debugName}` }, reader => {
23
+ const d = decorations.read(reader);
24
+ editor.changeDecorations(a => {
25
+ decorationIds = a.deltaDecorations(decorationIds, d);
26
+ });
27
+ }));
28
+ d.add({
29
+ dispose: () => {
30
+ editor.changeDecorations(a => {
31
+ decorationIds = a.deltaDecorations(decorationIds, []);
32
+ });
33
+ }
34
+ });
35
+ return d;
36
+ }
37
+ function* leftJoin(left, right, compare) {
38
+ const rightQueue = ( new ArrayQueue(right));
39
+ for (const leftElement of left) {
40
+ rightQueue.takeWhile(rightElement => CompareResult.isGreaterThan(compare(leftElement, rightElement)));
41
+ const equals = rightQueue.takeWhile(rightElement => CompareResult.isNeitherLessOrGreaterThan(compare(leftElement, rightElement)));
42
+ yield { left: leftElement, rights: equals || [] };
43
+ }
44
+ }
45
+ function* join(left, right, compare) {
46
+ const rightQueue = ( new ArrayQueue(right));
47
+ for (const leftElement of left) {
48
+ const skipped = rightQueue.takeWhile(rightElement => CompareResult.isGreaterThan(compare(leftElement, rightElement)));
49
+ if (skipped) {
50
+ yield { rights: skipped };
51
+ }
52
+ const equals = rightQueue.takeWhile(rightElement => CompareResult.isNeitherLessOrGreaterThan(compare(leftElement, rightElement)));
53
+ yield { left: leftElement, rights: equals || [] };
54
+ }
55
+ }
56
+ function concatArrays(...arrays) {
57
+ return [].concat(...arrays);
58
+ }
59
+ function thenIfNotDisposed(promise, then) {
60
+ let disposed = false;
61
+ promise.then(() => {
62
+ if (disposed) {
63
+ return;
64
+ }
65
+ then();
66
+ });
67
+ return toDisposable(() => {
68
+ disposed = true;
69
+ });
70
+ }
71
+ function setFields(obj, fields) {
72
+ return Object.assign(obj, fields);
73
+ }
74
+ function deepMerge(source1, source2) {
75
+ const result = {};
76
+ for (const key in source1) {
77
+ result[key] = source1[key];
78
+ }
79
+ for (const key in source2) {
80
+ const source2Value = source2[key];
81
+ if (typeof result[key] === 'object' && source2Value && typeof source2Value === 'object') {
82
+ result[key] = deepMerge(result[key], source2Value);
83
+ }
84
+ else {
85
+ result[key] = source2Value;
86
+ }
87
+ }
88
+ return result;
89
+ }
90
+ let PersistentStore = class PersistentStore {
91
+ constructor(key, storageService) {
92
+ this.key = key;
93
+ this.storageService = storageService;
94
+ this.hasValue = false;
95
+ this.value = undefined;
96
+ }
97
+ get() {
98
+ if (!this.hasValue) {
99
+ const value = this.storageService.get(this.key, StorageScope.PROFILE);
100
+ if (value !== undefined) {
101
+ try {
102
+ this.value = JSON.parse(value);
103
+ }
104
+ catch (e) {
105
+ onUnexpectedError(e);
106
+ }
107
+ }
108
+ this.hasValue = true;
109
+ }
110
+ return this.value;
111
+ }
112
+ set(newValue) {
113
+ this.value = newValue;
114
+ this.storageService.store(this.key, JSON.stringify(this.value), StorageScope.PROFILE, StorageTarget.USER);
115
+ }
116
+ };
117
+ PersistentStore = ( __decorate([
118
+ ( __param(1, IStorageService))
119
+ ], PersistentStore));
120
+
121
+ export { PersistentStore, applyObservableDecorations, concatArrays, deepMerge, join, leftJoin, setFields, setStyle, thenIfNotDisposed };