@theia/scm 1.34.2 → 1.34.3

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.
Files changed (95) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +31 -31
  3. package/lib/browser/decorations/scm-decorations-service.d.ts +14 -14
  4. package/lib/browser/decorations/scm-decorations-service.js +101 -101
  5. package/lib/browser/decorations/scm-navigator-decorator.d.ts +25 -25
  6. package/lib/browser/decorations/scm-navigator-decorator.js +132 -132
  7. package/lib/browser/decorations/scm-tab-bar-decorator.d.ts +17 -17
  8. package/lib/browser/decorations/scm-tab-bar-decorator.js +93 -93
  9. package/lib/browser/dirty-diff/content-lines.d.ts +12 -12
  10. package/lib/browser/dirty-diff/content-lines.js +106 -106
  11. package/lib/browser/dirty-diff/content-lines.spec.d.ts +1 -1
  12. package/lib/browser/dirty-diff/content-lines.spec.js +39 -39
  13. package/lib/browser/dirty-diff/diff-computer.d.ts +29 -29
  14. package/lib/browser/dirty-diff/diff-computer.js +102 -102
  15. package/lib/browser/dirty-diff/diff-computer.spec.d.ts +1 -1
  16. package/lib/browser/dirty-diff/diff-computer.spec.js +315 -315
  17. package/lib/browser/dirty-diff/dirty-diff-decorator.d.ts +14 -14
  18. package/lib/browser/dirty-diff/dirty-diff-decorator.js +98 -98
  19. package/lib/browser/dirty-diff/dirty-diff-module.d.ts +3 -3
  20. package/lib/browser/dirty-diff/dirty-diff-module.js +24 -24
  21. package/lib/browser/scm-amend-component.d.ts +123 -123
  22. package/lib/browser/scm-amend-component.js +423 -423
  23. package/lib/browser/scm-amend-widget.d.ts +20 -20
  24. package/lib/browser/scm-amend-widget.js +101 -101
  25. package/lib/browser/scm-avatar-service.d.ts +3 -3
  26. package/lib/browser/scm-avatar-service.js +36 -36
  27. package/lib/browser/scm-commit-widget.d.ts +52 -52
  28. package/lib/browser/scm-commit-widget.js +199 -199
  29. package/lib/browser/scm-context-key-service.d.ts +10 -10
  30. package/lib/browser/scm-context-key-service.js +58 -58
  31. package/lib/browser/scm-contribution.d.ts +83 -83
  32. package/lib/browser/scm-contribution.js +353 -353
  33. package/lib/browser/scm-frontend-module.d.ts +6 -6
  34. package/lib/browser/scm-frontend-module.js +130 -130
  35. package/lib/browser/scm-groups-tree-model.d.ts +14 -14
  36. package/lib/browser/scm-groups-tree-model.js +97 -97
  37. package/lib/browser/scm-input.d.ts +53 -53
  38. package/lib/browser/scm-input.js +127 -127
  39. package/lib/browser/scm-layout-migrations.d.ts +9 -9
  40. package/lib/browser/scm-layout-migrations.js +79 -79
  41. package/lib/browser/scm-no-repository-widget.d.ts +8 -8
  42. package/lib/browser/scm-no-repository-widget.js +49 -49
  43. package/lib/browser/scm-preferences.d.ts +11 -11
  44. package/lib/browser/scm-preferences.js +51 -51
  45. package/lib/browser/scm-provider.d.ts +56 -56
  46. package/lib/browser/scm-provider.js +19 -19
  47. package/lib/browser/scm-quick-open-service.d.ts +11 -11
  48. package/lib/browser/scm-quick-open-service.js +73 -73
  49. package/lib/browser/scm-repository.d.ts +17 -17
  50. package/lib/browser/scm-repository.js +41 -41
  51. package/lib/browser/scm-service.d.ts +26 -26
  52. package/lib/browser/scm-service.js +108 -108
  53. package/lib/browser/scm-tree-label-provider.d.ts +7 -7
  54. package/lib/browser/scm-tree-label-provider.js +57 -57
  55. package/lib/browser/scm-tree-model.d.ts +74 -74
  56. package/lib/browser/scm-tree-model.js +348 -348
  57. package/lib/browser/scm-tree-widget.d.ts +201 -201
  58. package/lib/browser/scm-tree-widget.js +664 -664
  59. package/lib/browser/scm-widget.d.ts +40 -40
  60. package/lib/browser/scm-widget.js +218 -218
  61. package/package.json +6 -6
  62. package/src/browser/decorations/scm-decorations-service.ts +78 -78
  63. package/src/browser/decorations/scm-navigator-decorator.ts +121 -121
  64. package/src/browser/decorations/scm-tab-bar-decorator.ts +83 -83
  65. package/src/browser/dirty-diff/content-lines.spec.ts +42 -42
  66. package/src/browser/dirty-diff/content-lines.ts +112 -112
  67. package/src/browser/dirty-diff/diff-computer.spec.ts +387 -387
  68. package/src/browser/dirty-diff/diff-computer.ts +129 -129
  69. package/src/browser/dirty-diff/dirty-diff-decorator.ts +107 -107
  70. package/src/browser/dirty-diff/dirty-diff-module.ts +24 -24
  71. package/src/browser/scm-amend-component.tsx +600 -600
  72. package/src/browser/scm-amend-widget.tsx +77 -77
  73. package/src/browser/scm-avatar-service.ts +27 -27
  74. package/src/browser/scm-commit-widget.tsx +215 -215
  75. package/src/browser/scm-context-key-service.ts +46 -46
  76. package/src/browser/scm-contribution.ts +361 -361
  77. package/src/browser/scm-frontend-module.ts +149 -149
  78. package/src/browser/scm-groups-tree-model.ts +78 -78
  79. package/src/browser/scm-input.ts +164 -164
  80. package/src/browser/scm-layout-migrations.ts +64 -64
  81. package/src/browser/scm-no-repository-widget.tsx +41 -41
  82. package/src/browser/scm-preferences.ts +63 -63
  83. package/src/browser/scm-provider.ts +89 -89
  84. package/src/browser/scm-quick-open-service.ts +48 -48
  85. package/src/browser/scm-repository.ts +52 -52
  86. package/src/browser/scm-service.ts +108 -108
  87. package/src/browser/scm-tree-label-provider.ts +44 -44
  88. package/src/browser/scm-tree-model.ts +405 -405
  89. package/src/browser/scm-tree-widget.tsx +809 -809
  90. package/src/browser/scm-widget.tsx +204 -204
  91. package/src/browser/style/dirty-diff-decorator.css +52 -52
  92. package/src/browser/style/dirty-diff.css +50 -50
  93. package/src/browser/style/index.css +267 -267
  94. package/src/browser/style/scm-amend-component.css +94 -94
  95. package/src/browser/style/scm.svg +4 -4
@@ -1,18 +1,18 @@
1
- import { Event, Emitter } from '@theia/core/lib/common/event';
2
- import { ScmService } from '../scm-service';
3
- import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator';
4
- import { Title, Widget } from '@theia/core/lib/browser';
5
- import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';
6
- export declare class ScmTabBarDecorator implements TabBarDecorator {
7
- readonly id = "theia-scm-tabbar-decorator";
8
- protected readonly emitter: Emitter<void>;
9
- private readonly toDispose;
10
- private readonly toDisposeOnDidChange;
11
- protected readonly scmService: ScmService;
12
- protected init(): void;
13
- decorate(title: Title<Widget>): WidgetDecoration.Data[];
14
- protected collectChangesCount(): number;
15
- get onDidChangeDecorations(): Event<void>;
16
- protected fireDidChangeDecorations(): void;
17
- }
1
+ import { Event, Emitter } from '@theia/core/lib/common/event';
2
+ import { ScmService } from '../scm-service';
3
+ import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator';
4
+ import { Title, Widget } from '@theia/core/lib/browser';
5
+ import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';
6
+ export declare class ScmTabBarDecorator implements TabBarDecorator {
7
+ readonly id = "theia-scm-tabbar-decorator";
8
+ protected readonly emitter: Emitter<void>;
9
+ private readonly toDispose;
10
+ private readonly toDisposeOnDidChange;
11
+ protected readonly scmService: ScmService;
12
+ protected init(): void;
13
+ decorate(title: Title<Widget>): WidgetDecoration.Data[];
14
+ protected collectChangesCount(): number;
15
+ get onDidChangeDecorations(): Event<void>;
16
+ protected fireDidChangeDecorations(): void;
17
+ }
18
18
  //# sourceMappingURL=scm-tab-bar-decorator.d.ts.map
@@ -1,94 +1,94 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2020 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.ScmTabBarDecorator = void 0;
28
- const inversify_1 = require("@theia/core/shared/inversify");
29
- const event_1 = require("@theia/core/lib/common/event");
30
- const scm_service_1 = require("../scm-service");
31
- const browser_1 = require("@theia/core/lib/browser");
32
- const disposable_1 = require("@theia/core/lib/common/disposable");
33
- const scm_widget_1 = require("../scm-widget");
34
- let ScmTabBarDecorator = class ScmTabBarDecorator {
35
- constructor() {
36
- this.id = 'theia-scm-tabbar-decorator';
37
- this.emitter = new event_1.Emitter();
38
- this.toDispose = new disposable_1.DisposableCollection();
39
- this.toDisposeOnDidChange = new disposable_1.DisposableCollection();
40
- }
41
- init() {
42
- this.toDispose.push(this.scmService.onDidChangeSelectedRepository(repository => {
43
- this.toDisposeOnDidChange.dispose();
44
- if (repository) {
45
- this.toDisposeOnDidChange.push(repository.provider.onDidChange(() => this.fireDidChangeDecorations()));
46
- }
47
- this.fireDidChangeDecorations();
48
- }));
49
- }
50
- decorate(title) {
51
- const { owner } = title;
52
- if (owner instanceof browser_1.ViewContainer && owner.getParts().find(part => part.wrapped instanceof scm_widget_1.ScmWidget)) {
53
- const changes = this.collectChangesCount();
54
- return changes > 0 ? [{ badge: changes }] : [];
55
- }
56
- else {
57
- return [];
58
- }
59
- }
60
- collectChangesCount() {
61
- const repository = this.scmService.selectedRepository;
62
- let changes = 0;
63
- if (!repository) {
64
- return 0;
65
- }
66
- repository.provider.groups.map(group => {
67
- if (group.id === 'index' || group.id === 'workingTree') {
68
- changes += group.resources.length;
69
- }
70
- });
71
- return changes;
72
- }
73
- get onDidChangeDecorations() {
74
- return this.emitter.event;
75
- }
76
- fireDidChangeDecorations() {
77
- this.emitter.fire(undefined);
78
- }
79
- };
80
- __decorate([
81
- (0, inversify_1.inject)(scm_service_1.ScmService),
82
- __metadata("design:type", scm_service_1.ScmService)
83
- ], ScmTabBarDecorator.prototype, "scmService", void 0);
84
- __decorate([
85
- (0, inversify_1.postConstruct)(),
86
- __metadata("design:type", Function),
87
- __metadata("design:paramtypes", []),
88
- __metadata("design:returntype", void 0)
89
- ], ScmTabBarDecorator.prototype, "init", null);
90
- ScmTabBarDecorator = __decorate([
91
- (0, inversify_1.injectable)()
92
- ], ScmTabBarDecorator);
93
- exports.ScmTabBarDecorator = ScmTabBarDecorator;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2020 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.ScmTabBarDecorator = void 0;
28
+ const inversify_1 = require("@theia/core/shared/inversify");
29
+ const event_1 = require("@theia/core/lib/common/event");
30
+ const scm_service_1 = require("../scm-service");
31
+ const browser_1 = require("@theia/core/lib/browser");
32
+ const disposable_1 = require("@theia/core/lib/common/disposable");
33
+ const scm_widget_1 = require("../scm-widget");
34
+ let ScmTabBarDecorator = class ScmTabBarDecorator {
35
+ constructor() {
36
+ this.id = 'theia-scm-tabbar-decorator';
37
+ this.emitter = new event_1.Emitter();
38
+ this.toDispose = new disposable_1.DisposableCollection();
39
+ this.toDisposeOnDidChange = new disposable_1.DisposableCollection();
40
+ }
41
+ init() {
42
+ this.toDispose.push(this.scmService.onDidChangeSelectedRepository(repository => {
43
+ this.toDisposeOnDidChange.dispose();
44
+ if (repository) {
45
+ this.toDisposeOnDidChange.push(repository.provider.onDidChange(() => this.fireDidChangeDecorations()));
46
+ }
47
+ this.fireDidChangeDecorations();
48
+ }));
49
+ }
50
+ decorate(title) {
51
+ const { owner } = title;
52
+ if (owner instanceof browser_1.ViewContainer && owner.getParts().find(part => part.wrapped instanceof scm_widget_1.ScmWidget)) {
53
+ const changes = this.collectChangesCount();
54
+ return changes > 0 ? [{ badge: changes }] : [];
55
+ }
56
+ else {
57
+ return [];
58
+ }
59
+ }
60
+ collectChangesCount() {
61
+ const repository = this.scmService.selectedRepository;
62
+ let changes = 0;
63
+ if (!repository) {
64
+ return 0;
65
+ }
66
+ repository.provider.groups.map(group => {
67
+ if (group.id === 'index' || group.id === 'workingTree') {
68
+ changes += group.resources.length;
69
+ }
70
+ });
71
+ return changes;
72
+ }
73
+ get onDidChangeDecorations() {
74
+ return this.emitter.event;
75
+ }
76
+ fireDidChangeDecorations() {
77
+ this.emitter.fire(undefined);
78
+ }
79
+ };
80
+ __decorate([
81
+ (0, inversify_1.inject)(scm_service_1.ScmService),
82
+ __metadata("design:type", scm_service_1.ScmService)
83
+ ], ScmTabBarDecorator.prototype, "scmService", void 0);
84
+ __decorate([
85
+ (0, inversify_1.postConstruct)(),
86
+ __metadata("design:type", Function),
87
+ __metadata("design:paramtypes", []),
88
+ __metadata("design:returntype", void 0)
89
+ ], ScmTabBarDecorator.prototype, "init", null);
90
+ ScmTabBarDecorator = __decorate([
91
+ (0, inversify_1.injectable)()
92
+ ], ScmTabBarDecorator);
93
+ exports.ScmTabBarDecorator = ScmTabBarDecorator;
94
94
  //# sourceMappingURL=scm-tab-bar-decorator.js.map
@@ -1,13 +1,13 @@
1
- export interface ContentLines extends ArrayLike<string> {
2
- readonly length: number;
3
- getLineContent: (line: number) => string;
4
- }
5
- export interface ContentLinesArrayLike extends ContentLines, ArrayLike<string> {
6
- [Symbol.iterator]: () => IterableIterator<string>;
7
- readonly [n: number]: string;
8
- }
9
- export declare namespace ContentLines {
10
- function fromString(content: string): ContentLines;
11
- function arrayLike(lines: ContentLines): ContentLinesArrayLike;
12
- }
1
+ export interface ContentLines extends ArrayLike<string> {
2
+ readonly length: number;
3
+ getLineContent: (line: number) => string;
4
+ }
5
+ export interface ContentLinesArrayLike extends ContentLines, ArrayLike<string> {
6
+ [Symbol.iterator]: () => IterableIterator<string>;
7
+ readonly [n: number]: string;
8
+ }
9
+ export declare namespace ContentLines {
10
+ function fromString(content: string): ContentLines;
11
+ function arrayLike(lines: ContentLines): ContentLinesArrayLike;
12
+ }
13
13
  //# sourceMappingURL=content-lines.d.ts.map
@@ -1,107 +1,107 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ContentLines = void 0;
19
- var ContentLines;
20
- (function (ContentLines) {
21
- const NL = '\n'.charCodeAt(0);
22
- const CR = '\r'.charCodeAt(0);
23
- function fromString(content) {
24
- const computeLineStarts = s => {
25
- const result = [0];
26
- for (let i = 0; i < s.length; i++) {
27
- const chr = s.charCodeAt(i);
28
- if (chr === CR) {
29
- if (i + 1 < s.length && s.charCodeAt(i + 1) === NL) {
30
- result[result.length] = i + 2;
31
- i++;
32
- }
33
- else {
34
- result[result.length] = i + 1;
35
- }
36
- }
37
- else if (chr === NL) {
38
- result[result.length] = i + 1;
39
- }
40
- }
41
- return result;
42
- };
43
- const lineStarts = computeLineStarts(content);
44
- return {
45
- length: lineStarts.length,
46
- getLineContent: line => {
47
- if (line >= lineStarts.length) {
48
- throw new Error('line index out of bounds');
49
- }
50
- const start = lineStarts[line];
51
- let end = (line === lineStarts.length - 1) ? undefined : lineStarts[line + 1] - 1;
52
- if (!!end && content.charCodeAt(end - 1) === CR) {
53
- end--; // ignore CR at the end
54
- }
55
- const lineContent = content.substring(start, end);
56
- return lineContent;
57
- }
58
- };
59
- }
60
- ContentLines.fromString = fromString;
61
- function arrayLike(lines) {
62
- return new Proxy(lines, getProxyHandler());
63
- }
64
- ContentLines.arrayLike = arrayLike;
65
- function getProxyHandler() {
66
- return {
67
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- get(target, p) {
69
- switch (p) {
70
- case 'prototype':
71
- return undefined;
72
- case 'length':
73
- return target.length;
74
- case 'slice':
75
- return (start, end) => {
76
- if (start !== undefined) {
77
- return [start, (end !== undefined ? end - 1 : target.length - 1)];
78
- }
79
- return [0, target.length - 1];
80
- };
81
- case Symbol.iterator:
82
- return function* () {
83
- for (let i = 0; i < target.length; i++) {
84
- yield target.getLineContent(i);
85
- }
86
- };
87
- }
88
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
- const index = Number.parseInt(p);
90
- if (Number.isInteger(index)) {
91
- if (index >= 0 && index < target.length) {
92
- const value = target.getLineContent(index);
93
- if (value === undefined) {
94
- console.log(target);
95
- }
96
- return value;
97
- }
98
- else {
99
- return undefined;
100
- }
101
- }
102
- throw new Error(`get ${String(p)} not implemented`);
103
- }
104
- };
105
- }
106
- })(ContentLines = exports.ContentLines || (exports.ContentLines = {}));
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ContentLines = void 0;
19
+ var ContentLines;
20
+ (function (ContentLines) {
21
+ const NL = '\n'.charCodeAt(0);
22
+ const CR = '\r'.charCodeAt(0);
23
+ function fromString(content) {
24
+ const computeLineStarts = s => {
25
+ const result = [0];
26
+ for (let i = 0; i < s.length; i++) {
27
+ const chr = s.charCodeAt(i);
28
+ if (chr === CR) {
29
+ if (i + 1 < s.length && s.charCodeAt(i + 1) === NL) {
30
+ result[result.length] = i + 2;
31
+ i++;
32
+ }
33
+ else {
34
+ result[result.length] = i + 1;
35
+ }
36
+ }
37
+ else if (chr === NL) {
38
+ result[result.length] = i + 1;
39
+ }
40
+ }
41
+ return result;
42
+ };
43
+ const lineStarts = computeLineStarts(content);
44
+ return {
45
+ length: lineStarts.length,
46
+ getLineContent: line => {
47
+ if (line >= lineStarts.length) {
48
+ throw new Error('line index out of bounds');
49
+ }
50
+ const start = lineStarts[line];
51
+ let end = (line === lineStarts.length - 1) ? undefined : lineStarts[line + 1] - 1;
52
+ if (!!end && content.charCodeAt(end - 1) === CR) {
53
+ end--; // ignore CR at the end
54
+ }
55
+ const lineContent = content.substring(start, end);
56
+ return lineContent;
57
+ }
58
+ };
59
+ }
60
+ ContentLines.fromString = fromString;
61
+ function arrayLike(lines) {
62
+ return new Proxy(lines, getProxyHandler());
63
+ }
64
+ ContentLines.arrayLike = arrayLike;
65
+ function getProxyHandler() {
66
+ return {
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ get(target, p) {
69
+ switch (p) {
70
+ case 'prototype':
71
+ return undefined;
72
+ case 'length':
73
+ return target.length;
74
+ case 'slice':
75
+ return (start, end) => {
76
+ if (start !== undefined) {
77
+ return [start, (end !== undefined ? end - 1 : target.length - 1)];
78
+ }
79
+ return [0, target.length - 1];
80
+ };
81
+ case Symbol.iterator:
82
+ return function* () {
83
+ for (let i = 0; i < target.length; i++) {
84
+ yield target.getLineContent(i);
85
+ }
86
+ };
87
+ }
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ const index = Number.parseInt(p);
90
+ if (Number.isInteger(index)) {
91
+ if (index >= 0 && index < target.length) {
92
+ const value = target.getLineContent(index);
93
+ if (value === undefined) {
94
+ console.log(target);
95
+ }
96
+ return value;
97
+ }
98
+ else {
99
+ return undefined;
100
+ }
101
+ }
102
+ throw new Error(`get ${String(p)} not implemented`);
103
+ }
104
+ };
105
+ }
106
+ })(ContentLines = exports.ContentLines || (exports.ContentLines = {}));
107
107
  //# sourceMappingURL=content-lines.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=content-lines.spec.d.ts.map
@@ -1,40 +1,40 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const chai = require("chai");
19
- const content_lines_1 = require("./content-lines");
20
- const chai_1 = require("chai");
21
- chai.use(require('chai-string'));
22
- describe('content-lines', () => {
23
- it('array-like access of lines without splitting', () => {
24
- const raw = 'abc\ndef\n123\n456';
25
- const linesArray = content_lines_1.ContentLines.arrayLike(content_lines_1.ContentLines.fromString(raw));
26
- (0, chai_1.expect)(linesArray[0]).to.be.equal('abc');
27
- (0, chai_1.expect)(linesArray[1]).to.be.equal('def');
28
- (0, chai_1.expect)(linesArray[2]).to.be.equal('123');
29
- (0, chai_1.expect)(linesArray[3]).to.be.equal('456');
30
- });
31
- it('works with CRLF', () => {
32
- const raw = 'abc\ndef\r\n123\r456';
33
- const linesArray = content_lines_1.ContentLines.arrayLike(content_lines_1.ContentLines.fromString(raw));
34
- (0, chai_1.expect)(linesArray[0]).to.be.equal('abc');
35
- (0, chai_1.expect)(linesArray[1]).to.be.equal('def');
36
- (0, chai_1.expect)(linesArray[2]).to.be.equal('123');
37
- (0, chai_1.expect)(linesArray[3]).to.be.equal('456');
38
- });
39
- });
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const chai = require("chai");
19
+ const content_lines_1 = require("./content-lines");
20
+ const chai_1 = require("chai");
21
+ chai.use(require('chai-string'));
22
+ describe('content-lines', () => {
23
+ it('array-like access of lines without splitting', () => {
24
+ const raw = 'abc\ndef\n123\n456';
25
+ const linesArray = content_lines_1.ContentLines.arrayLike(content_lines_1.ContentLines.fromString(raw));
26
+ (0, chai_1.expect)(linesArray[0]).to.be.equal('abc');
27
+ (0, chai_1.expect)(linesArray[1]).to.be.equal('def');
28
+ (0, chai_1.expect)(linesArray[2]).to.be.equal('123');
29
+ (0, chai_1.expect)(linesArray[3]).to.be.equal('456');
30
+ });
31
+ it('works with CRLF', () => {
32
+ const raw = 'abc\ndef\r\n123\r456';
33
+ const linesArray = content_lines_1.ContentLines.arrayLike(content_lines_1.ContentLines.fromString(raw));
34
+ (0, chai_1.expect)(linesArray[0]).to.be.equal('abc');
35
+ (0, chai_1.expect)(linesArray[1]).to.be.equal('def');
36
+ (0, chai_1.expect)(linesArray[2]).to.be.equal('123');
37
+ (0, chai_1.expect)(linesArray[3]).to.be.equal('456');
38
+ });
39
+ });
40
40
  //# sourceMappingURL=content-lines.spec.js.map
@@ -1,30 +1,30 @@
1
- import { ContentLinesArrayLike } from './content-lines';
2
- export declare class DiffComputer {
3
- computeDiff(previous: ContentLinesArrayLike, current: ContentLinesArrayLike): DiffResult[];
4
- computeDirtyDiff(previous: ContentLinesArrayLike, current: ContentLinesArrayLike): DirtyDiff;
5
- }
6
- export interface DiffResult {
7
- value: [number, number];
8
- count?: number;
9
- added?: boolean;
10
- removed?: boolean;
11
- }
12
- export interface DirtyDiff {
13
- /**
14
- * Lines added by comparison to previous revision.
15
- */
16
- readonly added: LineRange[];
17
- /**
18
- * Lines, after which lines were removed by comparison to previous revision.
19
- */
20
- readonly removed: number[];
21
- /**
22
- * Lines modified by comparison to previous revision.
23
- */
24
- readonly modified: LineRange[];
25
- }
26
- export interface LineRange {
27
- start: number;
28
- end: number;
29
- }
1
+ import { ContentLinesArrayLike } from './content-lines';
2
+ export declare class DiffComputer {
3
+ computeDiff(previous: ContentLinesArrayLike, current: ContentLinesArrayLike): DiffResult[];
4
+ computeDirtyDiff(previous: ContentLinesArrayLike, current: ContentLinesArrayLike): DirtyDiff;
5
+ }
6
+ export interface DiffResult {
7
+ value: [number, number];
8
+ count?: number;
9
+ added?: boolean;
10
+ removed?: boolean;
11
+ }
12
+ export interface DirtyDiff {
13
+ /**
14
+ * Lines added by comparison to previous revision.
15
+ */
16
+ readonly added: LineRange[];
17
+ /**
18
+ * Lines, after which lines were removed by comparison to previous revision.
19
+ */
20
+ readonly removed: number[];
21
+ /**
22
+ * Lines modified by comparison to previous revision.
23
+ */
24
+ readonly modified: LineRange[];
25
+ }
26
+ export interface LineRange {
27
+ start: number;
28
+ end: number;
29
+ }
30
30
  //# sourceMappingURL=diff-computer.d.ts.map