@theia/editor 1.45.0 → 1.46.0-next.72
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/README.md +30 -30
- package/lib/browser/decorations/editor-decoration-style.d.ts +8 -8
- package/lib/browser/decorations/editor-decoration-style.js +36 -36
- package/lib/browser/decorations/editor-decoration.d.ts +106 -106
- package/lib/browser/decorations/editor-decoration.js +37 -37
- package/lib/browser/decorations/editor-decorator.d.ts +6 -6
- package/lib/browser/decorations/editor-decorator.js +43 -43
- package/lib/browser/decorations/index.d.ts +3 -3
- package/lib/browser/decorations/index.js +30 -30
- package/lib/browser/diff-navigator.d.ts +9 -10
- package/lib/browser/diff-navigator.d.ts.map +1 -1
- package/lib/browser/diff-navigator.js +19 -19
- package/lib/browser/diff-navigator.js.map +1 -1
- package/lib/browser/editor-command.d.ts +102 -102
- package/lib/browser/editor-command.js +426 -426
- package/lib/browser/editor-contribution.d.ts +26 -26
- package/lib/browser/editor-contribution.js +198 -198
- package/lib/browser/editor-frontend-module.d.ts +5 -5
- package/lib/browser/editor-frontend-module.js +74 -74
- package/lib/browser/editor-generated-preference-schema.d.ts +282 -249
- package/lib/browser/editor-generated-preference-schema.d.ts.map +1 -1
- package/lib/browser/editor-generated-preference-schema.js +2451 -2316
- package/lib/browser/editor-generated-preference-schema.js.map +1 -1
- package/lib/browser/editor-keybinding.d.ts +5 -5
- package/lib/browser/editor-keybinding.js +55 -55
- package/lib/browser/editor-linenumber-contribution.d.ts +15 -15
- package/lib/browser/editor-linenumber-contribution.d.ts.map +1 -1
- package/lib/browser/editor-linenumber-contribution.js +95 -96
- package/lib/browser/editor-linenumber-contribution.js.map +1 -1
- package/lib/browser/editor-manager.d.ts +115 -115
- package/lib/browser/editor-manager.js +428 -428
- package/lib/browser/editor-menu.d.ts +48 -48
- package/lib/browser/editor-menu.js +210 -210
- package/lib/browser/editor-navigation-contribution.d.ts +67 -67
- package/lib/browser/editor-navigation-contribution.js +343 -343
- package/lib/browser/editor-preferences.d.ts +41 -41
- package/lib/browser/editor-preferences.js +176 -176
- package/lib/browser/editor-variable-contribution.d.ts +8 -8
- package/lib/browser/editor-variable-contribution.js +64 -64
- package/lib/browser/editor-widget-factory.d.ts +17 -17
- package/lib/browser/editor-widget-factory.js +91 -91
- package/lib/browser/editor-widget.d.ts +24 -24
- package/lib/browser/editor-widget.d.ts.map +1 -1
- package/lib/browser/editor-widget.js +122 -114
- package/lib/browser/editor-widget.js.map +1 -1
- package/lib/browser/editor.d.ts +295 -293
- package/lib/browser/editor.d.ts.map +1 -1
- package/lib/browser/editor.js +103 -103
- package/lib/browser/editor.js.map +1 -1
- package/lib/browser/index.d.ts +10 -10
- package/lib/browser/index.js +37 -37
- package/lib/browser/language-status/editor-language-status-service.d.ts +77 -77
- package/lib/browser/language-status/editor-language-status-service.js +251 -251
- package/lib/browser/navigation/navigation-location-service.d.ts +103 -103
- package/lib/browser/navigation/navigation-location-service.js +281 -281
- package/lib/browser/navigation/navigation-location-service.spec.d.ts +1 -1
- package/lib/browser/navigation/navigation-location-service.spec.js +184 -184
- package/lib/browser/navigation/navigation-location-similarity.d.ts +15 -15
- package/lib/browser/navigation/navigation-location-similarity.js +62 -62
- package/lib/browser/navigation/navigation-location-similarity.spec.d.ts +1 -1
- package/lib/browser/navigation/navigation-location-similarity.spec.js +32 -32
- package/lib/browser/navigation/navigation-location-updater.d.ts +35 -35
- package/lib/browser/navigation/navigation-location-updater.js +210 -210
- package/lib/browser/navigation/navigation-location-updater.spec.d.ts +1 -1
- package/lib/browser/navigation/navigation-location-updater.spec.js +177 -177
- package/lib/browser/navigation/navigation-location.d.ts +191 -191
- package/lib/browser/navigation/navigation-location.js +300 -300
- package/lib/browser/navigation/test/mock-navigation-location-updater.d.ts +15 -15
- package/lib/browser/navigation/test/mock-navigation-location-updater.js +38 -38
- package/lib/browser/quick-editor-service.d.ts +16 -16
- package/lib/browser/quick-editor-service.js +109 -109
- package/lib/browser/undo-redo-service.d.ts +23 -23
- package/lib/browser/undo-redo-service.js +110 -110
- package/lib/common/language-selector.d.ts +13 -13
- package/lib/common/language-selector.js +90 -90
- package/lib/package.spec.js +25 -25
- package/package.json +5 -5
- package/src/browser/decorations/editor-decoration-style.ts +41 -41
- package/src/browser/decorations/editor-decoration.ts +127 -127
- package/src/browser/decorations/editor-decorator.ts +36 -36
- package/src/browser/decorations/index.ts +19 -19
- package/src/browser/diff-navigator.ts +27 -28
- package/src/browser/editor-command.ts +414 -414
- package/src/browser/editor-contribution.ts +185 -185
- package/src/browser/editor-frontend-module.ts +87 -87
- package/src/browser/editor-generated-preference-schema.ts +2707 -2539
- package/src/browser/editor-keybinding.ts +55 -55
- package/src/browser/editor-linenumber-contribution.ts +88 -89
- package/src/browser/editor-manager.ts +442 -442
- package/src/browser/editor-menu.ts +224 -224
- package/src/browser/editor-navigation-contribution.ts +343 -343
- package/src/browser/editor-preferences.ts +226 -226
- package/src/browser/editor-variable-contribution.ts +54 -54
- package/src/browser/editor-widget-factory.ts +82 -82
- package/src/browser/editor-widget.ts +137 -130
- package/src/browser/editor.ts +360 -358
- package/src/browser/index.ts +26 -26
- package/src/browser/language-status/editor-language-status-service.ts +271 -271
- package/src/browser/language-status/editor-language-status.css +101 -101
- package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
- package/src/browser/navigation/navigation-location-service.ts +284 -284
- package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
- package/src/browser/navigation/navigation-location-similarity.ts +58 -58
- package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
- package/src/browser/navigation/navigation-location-updater.ts +220 -220
- package/src/browser/navigation/navigation-location.ts +418 -418
- package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
- package/src/browser/quick-editor-service.ts +94 -94
- package/src/browser/style/index.css +19 -19
- package/src/browser/undo-redo-service.ts +120 -120
- package/src/common/language-selector.ts +104 -104
- package/src/package.spec.ts +28 -28
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import { NavigationLocation } from './navigation-location';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Service for checking whether two navigation locations are similar or not.
|
|
22
|
-
*/
|
|
23
|
-
@injectable()
|
|
24
|
-
export class NavigationLocationSimilarity {
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The number of lines to move in the editor to justify for new state.
|
|
28
|
-
*/
|
|
29
|
-
private static EDITOR_SELECTION_THRESHOLD = 10;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* `true` if the `left` and `right` locations are withing +- 10 lines in the same editor. Otherwise, `false`.
|
|
33
|
-
*/
|
|
34
|
-
similar(left: NavigationLocation | undefined, right: NavigationLocation | undefined): boolean {
|
|
35
|
-
if (left === undefined || right === undefined) {
|
|
36
|
-
return left === right;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (left.uri.toString() !== right.uri.toString()) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const leftRange = NavigationLocation.range(left);
|
|
44
|
-
const rightRange = NavigationLocation.range(right);
|
|
45
|
-
if (leftRange === undefined || rightRange === undefined) {
|
|
46
|
-
return leftRange === rightRange;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const leftLineNumber = Math.min(leftRange.start.line, leftRange.end.line);
|
|
50
|
-
const rightLineNumber = Math.min(rightRange.start.line, rightRange.end.line);
|
|
51
|
-
return Math.abs(leftLineNumber - rightLineNumber) < this.getThreshold();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected getThreshold(): number {
|
|
55
|
-
return NavigationLocationSimilarity.EDITOR_SELECTION_THRESHOLD;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { NavigationLocation } from './navigation-location';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Service for checking whether two navigation locations are similar or not.
|
|
22
|
+
*/
|
|
23
|
+
@injectable()
|
|
24
|
+
export class NavigationLocationSimilarity {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The number of lines to move in the editor to justify for new state.
|
|
28
|
+
*/
|
|
29
|
+
private static EDITOR_SELECTION_THRESHOLD = 10;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* `true` if the `left` and `right` locations are withing +- 10 lines in the same editor. Otherwise, `false`.
|
|
33
|
+
*/
|
|
34
|
+
similar(left: NavigationLocation | undefined, right: NavigationLocation | undefined): boolean {
|
|
35
|
+
if (left === undefined || right === undefined) {
|
|
36
|
+
return left === right;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (left.uri.toString() !== right.uri.toString()) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const leftRange = NavigationLocation.range(left);
|
|
44
|
+
const rightRange = NavigationLocation.range(right);
|
|
45
|
+
if (leftRange === undefined || rightRange === undefined) {
|
|
46
|
+
return leftRange === rightRange;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const leftLineNumber = Math.min(leftRange.start.line, leftRange.end.line);
|
|
50
|
+
const rightLineNumber = Math.min(rightRange.start.line, rightRange.end.line);
|
|
51
|
+
return Math.abs(leftLineNumber - rightLineNumber) < this.getThreshold();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected getThreshold(): number {
|
|
55
|
+
return NavigationLocationSimilarity.EDITOR_SELECTION_THRESHOLD;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { expect } from 'chai';
|
|
18
|
-
import { NavigationLocation, Range } from './navigation-location';
|
|
19
|
-
import { TextDocumentContentChangeDelta } from '../editor';
|
|
20
|
-
import { MockNavigationLocationUpdater } from './test/mock-navigation-location-updater';
|
|
21
|
-
|
|
22
|
-
describe('navigation-location-updater', () => {
|
|
23
|
-
|
|
24
|
-
const updater = new MockNavigationLocationUpdater();
|
|
25
|
-
|
|
26
|
-
describe('contained', () => {
|
|
27
|
-
([
|
|
28
|
-
[{ start: { line: 4, character: 3 }, end: { line: 4, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 6, character: 12 } }, true],
|
|
29
|
-
[{ start: { line: 4, character: 3 }, end: { line: 5, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 6, character: 12 } }, true],
|
|
30
|
-
[{ start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, true],
|
|
31
|
-
[{ start: { line: 3, character: 2 }, end: { line: 3, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
32
|
-
[{ start: { line: 2, character: 3 }, end: { line: 3, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
33
|
-
[{ start: { line: 3, character: 3 }, end: { line: 3, character: 13 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
34
|
-
[{ start: { line: 3, character: 3 }, end: { line: 4, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
35
|
-
] as [Range, Range, boolean][]).forEach(test => {
|
|
36
|
-
const [subRange, range, expected] = test;
|
|
37
|
-
it(`range ${JSON.stringify(range)} should${!expected ? ' not' : ''} be contained in range ${JSON.stringify(subRange)}`, () => {
|
|
38
|
-
expect(updater.contained(subRange, range)).to.be.equal(expected);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('affected', () => {
|
|
44
|
-
|
|
45
|
-
it('should never affect a location if they belong to different resources', () => {
|
|
46
|
-
const actual = updater.affects(
|
|
47
|
-
NavigationLocation.create('file:///a', { line: 0, character: 0, }),
|
|
48
|
-
NavigationLocation.create('file:///b', { line: 0, character: 0, })
|
|
49
|
-
);
|
|
50
|
-
expect(actual).to.be.false;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
([
|
|
54
|
-
// Spec(1. and 2.)
|
|
55
|
-
{
|
|
56
|
-
candidate: { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } },
|
|
57
|
-
other: { range: { start: { line: 1, character: 6 }, end: { line: 3, character: 2 } }, rangeLength: 78, text: 'x' },
|
|
58
|
-
expected: { start: { line: 1, character: 8 }, end: { line: 1, character: 17 } }
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
candidate: { start: { line: 3, character: 3 }, end: { line: 4, character: 18 } },
|
|
62
|
-
other: { range: { start: { line: 1, character: 6 }, end: { line: 3, character: 2 } }, rangeLength: 78, text: 'x' },
|
|
63
|
-
expected: { start: { line: 1, character: 8 }, end: { line: 2, character: 18 } }
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
67
|
-
other: { range: { start: { line: 1, character: 3 }, end: { line: 1, character: 12 } }, rangeLength: 9, text: 'x' },
|
|
68
|
-
expected: false
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
72
|
-
other: { range: { start: { line: 1, character: 3 }, end: { line: 1, character: 12 } }, rangeLength: 9, text: 'a\n\b\nc' },
|
|
73
|
-
expected: { start: { line: 5, character: 17 }, end: { line: 5, character: 26 } }
|
|
74
|
-
},
|
|
75
|
-
// Spec (3.)
|
|
76
|
-
{
|
|
77
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
78
|
-
other: { range: { start: { line: 3, character: 18 }, end: { line: 3, character: 24 } }, rangeLength: 6, text: 'x' },
|
|
79
|
-
expected: { start: { line: 3, character: 17 }, end: { line: 3, character: 21 } }
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
83
|
-
other: { range: { start: { line: 3, character: 18 }, end: { line: 3, character: 23 } }, rangeLength: 5, text: 'a\n\b\nc' },
|
|
84
|
-
expected: { start: { line: 3, character: 17 }, end: { line: 5, character: 4 } }
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
88
|
-
other: { range: { start: { line: 3, character: 19 }, end: { line: 4, character: 19 } }, rangeLength: 41, text: 'xxx' },
|
|
89
|
-
expected: { start: { line: 3, character: 17 }, end: { line: 3, character: 29 } }
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
93
|
-
other: { range: { start: { line: 3, character: 19 }, end: { line: 3, character: 21 } }, rangeLength: 2, text: 'a\nb' },
|
|
94
|
-
expected: { start: { line: 3, character: 17 }, end: { line: 5, character: 26 } }
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
98
|
-
other: { range: { start: { line: 3, character: 18 }, end: { line: 4, character: 24 } }, rangeLength: 47, text: 'a\nb\nc' },
|
|
99
|
-
expected: { start: { line: 3, character: 17 }, end: { line: 5, character: 3 } }
|
|
100
|
-
},
|
|
101
|
-
// Spec (4.)
|
|
102
|
-
{
|
|
103
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
104
|
-
other: { range: { start: { line: 6, character: 13 }, end: { line: 6, character: 23 } }, rangeLength: 10, text: '' },
|
|
105
|
-
expected: false
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
109
|
-
other: { range: { start: { line: 6, character: 13 }, end: { line: 6, character: 23 } }, rangeLength: 10, text: 'a\nb\nc' },
|
|
110
|
-
expected: false
|
|
111
|
-
},
|
|
112
|
-
// Spec (5.)
|
|
113
|
-
{
|
|
114
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
115
|
-
other: { range: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } }, rangeLength: 50, text: '' },
|
|
116
|
-
expected: { start: { line: 3, character: 17 }, end: { line: 3, character: 17 } }
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
120
|
-
other: { range: { start: { line: 3, character: 17 }, end: { line: 4, character: 27 } }, rangeLength: 51, text: '' },
|
|
121
|
-
expected: undefined
|
|
122
|
-
},
|
|
123
|
-
] as TestInput[]).forEach(test => {
|
|
124
|
-
const { other, expected, candidate } = test;
|
|
125
|
-
it(`should update the navigation location: ${JSON.stringify(candidate)} => ${JSON.stringify(expected)}`, () => {
|
|
126
|
-
if (test.trace) {
|
|
127
|
-
trace(test);
|
|
128
|
-
}
|
|
129
|
-
const actual = updater.affects(
|
|
130
|
-
NavigationLocation.create('file:///a', candidate),
|
|
131
|
-
NavigationLocation.create('file:///a', other),
|
|
132
|
-
);
|
|
133
|
-
if (typeof expected === 'boolean') {
|
|
134
|
-
expect(actual).to.be.deep.equal(expected);
|
|
135
|
-
} else if (expected === undefined) {
|
|
136
|
-
expect(actual).to.be.undefined;
|
|
137
|
-
} else {
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
-
expect((actual as any).context).to.be.deep.equal(expected);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
interface TestInput {
|
|
149
|
-
readonly candidate: Range;
|
|
150
|
-
readonly other: TextDocumentContentChangeDelta;
|
|
151
|
-
// affected | not affected | should be deleted
|
|
152
|
-
readonly expected: Range | false | undefined;
|
|
153
|
-
readonly trace?: true;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function trace(test: TestInput): void {
|
|
157
|
-
const line = 10;
|
|
158
|
-
const column = 40;
|
|
159
|
-
const doc: string[][] = [];
|
|
160
|
-
const printDoc = (text?: string) => {
|
|
161
|
-
if (text) {
|
|
162
|
-
console.log(`\n START - ${text} `);
|
|
163
|
-
}
|
|
164
|
-
doc.forEach(row => console.log(row.join('')));
|
|
165
|
-
if (text) {
|
|
166
|
-
console.log(` END - ${text} \n`);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
const select = (range: Range, p: string) => {
|
|
170
|
-
for (let i = range.start.line + 1; i < range.end.line; i++) {
|
|
171
|
-
for (let j = 0; j < column; j++) {
|
|
172
|
-
doc[i][j] = p;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (range.start.line === range.end.line) {
|
|
176
|
-
for (let j = range.start.character; j < range.end.character; j++) {
|
|
177
|
-
doc[range.start.line][j] = p;
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
for (let j = range.start.character; j < column; j++) {
|
|
181
|
-
doc[range.start.line][j] = p;
|
|
182
|
-
}
|
|
183
|
-
for (let j = 0; j < range.end.character; j++) {
|
|
184
|
-
doc[range.end.line][j] = p;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
for (let i = 0; i < line; i++) {
|
|
189
|
-
doc.push(Array(column).fill('+'));
|
|
190
|
-
}
|
|
191
|
-
printDoc('EMPTY DOCUMENT');
|
|
192
|
-
select(test.candidate, '_');
|
|
193
|
-
printDoc('CANDIDATE SELECTION');
|
|
194
|
-
select(test.other.range, 'a');
|
|
195
|
-
printDoc('APPLIED MODIFICATION');
|
|
196
|
-
// TODO: Show the "doc" after applying the changes.
|
|
197
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { NavigationLocation, Range } from './navigation-location';
|
|
19
|
+
import { TextDocumentContentChangeDelta } from '../editor';
|
|
20
|
+
import { MockNavigationLocationUpdater } from './test/mock-navigation-location-updater';
|
|
21
|
+
|
|
22
|
+
describe('navigation-location-updater', () => {
|
|
23
|
+
|
|
24
|
+
const updater = new MockNavigationLocationUpdater();
|
|
25
|
+
|
|
26
|
+
describe('contained', () => {
|
|
27
|
+
([
|
|
28
|
+
[{ start: { line: 4, character: 3 }, end: { line: 4, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 6, character: 12 } }, true],
|
|
29
|
+
[{ start: { line: 4, character: 3 }, end: { line: 5, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 6, character: 12 } }, true],
|
|
30
|
+
[{ start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, true],
|
|
31
|
+
[{ start: { line: 3, character: 2 }, end: { line: 3, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
32
|
+
[{ start: { line: 2, character: 3 }, end: { line: 3, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
33
|
+
[{ start: { line: 3, character: 3 }, end: { line: 3, character: 13 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
34
|
+
[{ start: { line: 3, character: 3 }, end: { line: 4, character: 12 } }, { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } }, false],
|
|
35
|
+
] as [Range, Range, boolean][]).forEach(test => {
|
|
36
|
+
const [subRange, range, expected] = test;
|
|
37
|
+
it(`range ${JSON.stringify(range)} should${!expected ? ' not' : ''} be contained in range ${JSON.stringify(subRange)}`, () => {
|
|
38
|
+
expect(updater.contained(subRange, range)).to.be.equal(expected);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('affected', () => {
|
|
44
|
+
|
|
45
|
+
it('should never affect a location if they belong to different resources', () => {
|
|
46
|
+
const actual = updater.affects(
|
|
47
|
+
NavigationLocation.create('file:///a', { line: 0, character: 0, }),
|
|
48
|
+
NavigationLocation.create('file:///b', { line: 0, character: 0, })
|
|
49
|
+
);
|
|
50
|
+
expect(actual).to.be.false;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
([
|
|
54
|
+
// Spec(1. and 2.)
|
|
55
|
+
{
|
|
56
|
+
candidate: { start: { line: 3, character: 3 }, end: { line: 3, character: 12 } },
|
|
57
|
+
other: { range: { start: { line: 1, character: 6 }, end: { line: 3, character: 2 } }, rangeLength: 78, text: 'x' },
|
|
58
|
+
expected: { start: { line: 1, character: 8 }, end: { line: 1, character: 17 } }
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
candidate: { start: { line: 3, character: 3 }, end: { line: 4, character: 18 } },
|
|
62
|
+
other: { range: { start: { line: 1, character: 6 }, end: { line: 3, character: 2 } }, rangeLength: 78, text: 'x' },
|
|
63
|
+
expected: { start: { line: 1, character: 8 }, end: { line: 2, character: 18 } }
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
67
|
+
other: { range: { start: { line: 1, character: 3 }, end: { line: 1, character: 12 } }, rangeLength: 9, text: 'x' },
|
|
68
|
+
expected: false
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
72
|
+
other: { range: { start: { line: 1, character: 3 }, end: { line: 1, character: 12 } }, rangeLength: 9, text: 'a\n\b\nc' },
|
|
73
|
+
expected: { start: { line: 5, character: 17 }, end: { line: 5, character: 26 } }
|
|
74
|
+
},
|
|
75
|
+
// Spec (3.)
|
|
76
|
+
{
|
|
77
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
78
|
+
other: { range: { start: { line: 3, character: 18 }, end: { line: 3, character: 24 } }, rangeLength: 6, text: 'x' },
|
|
79
|
+
expected: { start: { line: 3, character: 17 }, end: { line: 3, character: 21 } }
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 3, character: 26 } },
|
|
83
|
+
other: { range: { start: { line: 3, character: 18 }, end: { line: 3, character: 23 } }, rangeLength: 5, text: 'a\n\b\nc' },
|
|
84
|
+
expected: { start: { line: 3, character: 17 }, end: { line: 5, character: 4 } }
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
88
|
+
other: { range: { start: { line: 3, character: 19 }, end: { line: 4, character: 19 } }, rangeLength: 41, text: 'xxx' },
|
|
89
|
+
expected: { start: { line: 3, character: 17 }, end: { line: 3, character: 29 } }
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
93
|
+
other: { range: { start: { line: 3, character: 19 }, end: { line: 3, character: 21 } }, rangeLength: 2, text: 'a\nb' },
|
|
94
|
+
expected: { start: { line: 3, character: 17 }, end: { line: 5, character: 26 } }
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
98
|
+
other: { range: { start: { line: 3, character: 18 }, end: { line: 4, character: 24 } }, rangeLength: 47, text: 'a\nb\nc' },
|
|
99
|
+
expected: { start: { line: 3, character: 17 }, end: { line: 5, character: 3 } }
|
|
100
|
+
},
|
|
101
|
+
// Spec (4.)
|
|
102
|
+
{
|
|
103
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
104
|
+
other: { range: { start: { line: 6, character: 13 }, end: { line: 6, character: 23 } }, rangeLength: 10, text: '' },
|
|
105
|
+
expected: false
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
109
|
+
other: { range: { start: { line: 6, character: 13 }, end: { line: 6, character: 23 } }, rangeLength: 10, text: 'a\nb\nc' },
|
|
110
|
+
expected: false
|
|
111
|
+
},
|
|
112
|
+
// Spec (5.)
|
|
113
|
+
{
|
|
114
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
115
|
+
other: { range: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } }, rangeLength: 50, text: '' },
|
|
116
|
+
expected: { start: { line: 3, character: 17 }, end: { line: 3, character: 17 } }
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
candidate: { start: { line: 3, character: 17 }, end: { line: 4, character: 26 } },
|
|
120
|
+
other: { range: { start: { line: 3, character: 17 }, end: { line: 4, character: 27 } }, rangeLength: 51, text: '' },
|
|
121
|
+
expected: undefined
|
|
122
|
+
},
|
|
123
|
+
] as TestInput[]).forEach(test => {
|
|
124
|
+
const { other, expected, candidate } = test;
|
|
125
|
+
it(`should update the navigation location: ${JSON.stringify(candidate)} => ${JSON.stringify(expected)}`, () => {
|
|
126
|
+
if (test.trace) {
|
|
127
|
+
trace(test);
|
|
128
|
+
}
|
|
129
|
+
const actual = updater.affects(
|
|
130
|
+
NavigationLocation.create('file:///a', candidate),
|
|
131
|
+
NavigationLocation.create('file:///a', other),
|
|
132
|
+
);
|
|
133
|
+
if (typeof expected === 'boolean') {
|
|
134
|
+
expect(actual).to.be.deep.equal(expected);
|
|
135
|
+
} else if (expected === undefined) {
|
|
136
|
+
expect(actual).to.be.undefined;
|
|
137
|
+
} else {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
+
expect((actual as any).context).to.be.deep.equal(expected);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
interface TestInput {
|
|
149
|
+
readonly candidate: Range;
|
|
150
|
+
readonly other: TextDocumentContentChangeDelta;
|
|
151
|
+
// affected | not affected | should be deleted
|
|
152
|
+
readonly expected: Range | false | undefined;
|
|
153
|
+
readonly trace?: true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function trace(test: TestInput): void {
|
|
157
|
+
const line = 10;
|
|
158
|
+
const column = 40;
|
|
159
|
+
const doc: string[][] = [];
|
|
160
|
+
const printDoc = (text?: string) => {
|
|
161
|
+
if (text) {
|
|
162
|
+
console.log(`\n START - ${text} `);
|
|
163
|
+
}
|
|
164
|
+
doc.forEach(row => console.log(row.join('')));
|
|
165
|
+
if (text) {
|
|
166
|
+
console.log(` END - ${text} \n`);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const select = (range: Range, p: string) => {
|
|
170
|
+
for (let i = range.start.line + 1; i < range.end.line; i++) {
|
|
171
|
+
for (let j = 0; j < column; j++) {
|
|
172
|
+
doc[i][j] = p;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (range.start.line === range.end.line) {
|
|
176
|
+
for (let j = range.start.character; j < range.end.character; j++) {
|
|
177
|
+
doc[range.start.line][j] = p;
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
for (let j = range.start.character; j < column; j++) {
|
|
181
|
+
doc[range.start.line][j] = p;
|
|
182
|
+
}
|
|
183
|
+
for (let j = 0; j < range.end.character; j++) {
|
|
184
|
+
doc[range.end.line][j] = p;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
for (let i = 0; i < line; i++) {
|
|
189
|
+
doc.push(Array(column).fill('+'));
|
|
190
|
+
}
|
|
191
|
+
printDoc('EMPTY DOCUMENT');
|
|
192
|
+
select(test.candidate, '_');
|
|
193
|
+
printDoc('CANDIDATE SELECTION');
|
|
194
|
+
select(test.other.range, 'a');
|
|
195
|
+
printDoc('APPLIED MODIFICATION');
|
|
196
|
+
// TODO: Show the "doc" after applying the changes.
|
|
197
|
+
}
|