@theia/editor 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 (100) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +30 -30
  3. package/lib/browser/decorations/editor-decoration-style.d.ts +8 -8
  4. package/lib/browser/decorations/editor-decoration-style.js +36 -36
  5. package/lib/browser/decorations/editor-decoration.d.ts +106 -106
  6. package/lib/browser/decorations/editor-decoration.js +37 -37
  7. package/lib/browser/decorations/editor-decorator.d.ts +6 -6
  8. package/lib/browser/decorations/editor-decorator.js +43 -43
  9. package/lib/browser/decorations/index.d.ts +3 -3
  10. package/lib/browser/decorations/index.js +30 -30
  11. package/lib/browser/diff-navigator.d.ts +10 -10
  12. package/lib/browser/diff-navigator.js +19 -19
  13. package/lib/browser/editor-command.d.ts +102 -102
  14. package/lib/browser/editor-command.js +426 -426
  15. package/lib/browser/editor-contribution.d.ts +26 -26
  16. package/lib/browser/editor-contribution.js +198 -198
  17. package/lib/browser/editor-frontend-module.d.ts +5 -5
  18. package/lib/browser/editor-frontend-module.js +74 -74
  19. package/lib/browser/editor-generated-preference-schema.d.ts +249 -249
  20. package/lib/browser/editor-generated-preference-schema.js +2316 -2316
  21. package/lib/browser/editor-keybinding-contexts.d.ts +35 -35
  22. package/lib/browser/editor-keybinding-contexts.js +98 -98
  23. package/lib/browser/editor-keybinding.d.ts +5 -5
  24. package/lib/browser/editor-keybinding.js +55 -55
  25. package/lib/browser/editor-manager.d.ts +113 -113
  26. package/lib/browser/editor-manager.js +412 -412
  27. package/lib/browser/editor-menu.d.ts +48 -48
  28. package/lib/browser/editor-menu.js +210 -210
  29. package/lib/browser/editor-navigation-contribution.d.ts +67 -67
  30. package/lib/browser/editor-navigation-contribution.js +331 -331
  31. package/lib/browser/editor-preferences.d.ts +40 -40
  32. package/lib/browser/editor-preferences.js +165 -165
  33. package/lib/browser/editor-variable-contribution.d.ts +8 -8
  34. package/lib/browser/editor-variable-contribution.js +64 -64
  35. package/lib/browser/editor-widget-factory.d.ts +17 -17
  36. package/lib/browser/editor-widget-factory.js +91 -91
  37. package/lib/browser/editor-widget.d.ts +20 -20
  38. package/lib/browser/editor-widget.js +87 -87
  39. package/lib/browser/editor.d.ts +293 -293
  40. package/lib/browser/editor.js +103 -103
  41. package/lib/browser/index.d.ts +10 -10
  42. package/lib/browser/index.js +37 -37
  43. package/lib/browser/language-status/editor-language-status-service.d.ts +77 -77
  44. package/lib/browser/language-status/editor-language-status-service.js +251 -251
  45. package/lib/browser/navigation/navigation-location-service.d.ts +103 -103
  46. package/lib/browser/navigation/navigation-location-service.js +281 -281
  47. package/lib/browser/navigation/navigation-location-service.spec.d.ts +1 -1
  48. package/lib/browser/navigation/navigation-location-service.spec.js +184 -184
  49. package/lib/browser/navigation/navigation-location-similarity.d.ts +15 -15
  50. package/lib/browser/navigation/navigation-location-similarity.js +62 -62
  51. package/lib/browser/navigation/navigation-location-similarity.spec.d.ts +1 -1
  52. package/lib/browser/navigation/navigation-location-similarity.spec.js +32 -32
  53. package/lib/browser/navigation/navigation-location-updater.d.ts +35 -35
  54. package/lib/browser/navigation/navigation-location-updater.js +210 -210
  55. package/lib/browser/navigation/navigation-location-updater.spec.d.ts +1 -1
  56. package/lib/browser/navigation/navigation-location-updater.spec.js +177 -177
  57. package/lib/browser/navigation/navigation-location.d.ts +191 -191
  58. package/lib/browser/navigation/navigation-location.js +300 -300
  59. package/lib/browser/navigation/test/mock-navigation-location-updater.d.ts +15 -15
  60. package/lib/browser/navigation/test/mock-navigation-location-updater.js +38 -38
  61. package/lib/browser/quick-editor-service.d.ts +16 -16
  62. package/lib/browser/quick-editor-service.js +109 -109
  63. package/lib/common/language-selector.d.ts +13 -13
  64. package/lib/common/language-selector.js +90 -90
  65. package/lib/package.spec.js +25 -25
  66. package/package.json +5 -5
  67. package/src/browser/decorations/editor-decoration-style.ts +41 -41
  68. package/src/browser/decorations/editor-decoration.ts +127 -127
  69. package/src/browser/decorations/editor-decorator.ts +36 -36
  70. package/src/browser/decorations/index.ts +19 -19
  71. package/src/browser/diff-navigator.ts +28 -28
  72. package/src/browser/editor-command.ts +414 -414
  73. package/src/browser/editor-contribution.ts +185 -185
  74. package/src/browser/editor-frontend-module.ts +85 -85
  75. package/src/browser/editor-generated-preference-schema.ts +2539 -2539
  76. package/src/browser/editor-keybinding-contexts.ts +87 -87
  77. package/src/browser/editor-keybinding.ts +55 -55
  78. package/src/browser/editor-manager.ts +429 -429
  79. package/src/browser/editor-menu.ts +224 -224
  80. package/src/browser/editor-navigation-contribution.ts +331 -331
  81. package/src/browser/editor-preferences.ts +220 -220
  82. package/src/browser/editor-variable-contribution.ts +54 -54
  83. package/src/browser/editor-widget-factory.ts +82 -82
  84. package/src/browser/editor-widget.ts +98 -98
  85. package/src/browser/editor.ts +358 -358
  86. package/src/browser/index.ts +26 -26
  87. package/src/browser/language-status/editor-language-status-service.ts +271 -271
  88. package/src/browser/language-status/editor-language-status.css +98 -98
  89. package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
  90. package/src/browser/navigation/navigation-location-service.ts +284 -284
  91. package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
  92. package/src/browser/navigation/navigation-location-similarity.ts +58 -58
  93. package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
  94. package/src/browser/navigation/navigation-location-updater.ts +220 -220
  95. package/src/browser/navigation/navigation-location.ts +418 -418
  96. package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
  97. package/src/browser/quick-editor-service.ts +94 -94
  98. package/src/browser/style/index.css +19 -19
  99. package/src/common/language-selector.ts +104 -104
  100. package/src/package.spec.ts +28 -28
@@ -1,41 +1,41 @@
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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Range } from '../navigation-location';
18
- import { NavigationLocationUpdater } from '../navigation-location-updater';
19
-
20
- /**
21
- * Navigation location updater with increased method visibility for testing.
22
- */
23
- export class MockNavigationLocationUpdater extends NavigationLocationUpdater {
24
-
25
- override contained(subRange: Range, range: Range): boolean {
26
- return super.contained(subRange, range);
27
- }
28
-
29
- }
30
-
31
- /**
32
- * NOOP navigation location updater for testing. Use this, if you want to avoid any
33
- * location updates during the tests.
34
- */
35
- export class NoopNavigationLocationUpdater extends NavigationLocationUpdater {
36
-
37
- override affects(): false {
38
- return false;
39
- }
40
-
41
- }
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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Range } from '../navigation-location';
18
+ import { NavigationLocationUpdater } from '../navigation-location-updater';
19
+
20
+ /**
21
+ * Navigation location updater with increased method visibility for testing.
22
+ */
23
+ export class MockNavigationLocationUpdater extends NavigationLocationUpdater {
24
+
25
+ override contained(subRange: Range, range: Range): boolean {
26
+ return super.contained(subRange, range);
27
+ }
28
+
29
+ }
30
+
31
+ /**
32
+ * NOOP navigation location updater for testing. Use this, if you want to avoid any
33
+ * location updates during the tests.
34
+ */
35
+ export class NoopNavigationLocationUpdater extends NavigationLocationUpdater {
36
+
37
+ override affects(): false {
38
+ return false;
39
+ }
40
+
41
+ }
@@ -1,94 +1,94 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 SAP SE or an SAP affiliate company 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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject } from '@theia/core/shared/inversify';
18
- import { CancellationToken, nls, QuickPickItemOrSeparator } from '@theia/core/lib/common';
19
- import { LabelProvider } from '@theia/core/lib/browser/label-provider';
20
- import { QuickAccessProvider, QuickAccessRegistry, QuickAccessContribution } from '@theia/core/lib/browser/quick-input/quick-access';
21
- import { filterItems, QuickPickItem, QuickPickSeparator } from '@theia/core/lib/browser/quick-input/quick-input-service';
22
- import { ApplicationShell, NavigatableWidget, TabBar, Widget } from '@theia/core/lib/browser';
23
-
24
- @injectable()
25
- export class QuickEditorService implements QuickAccessContribution, QuickAccessProvider {
26
- static PREFIX = 'edt ';
27
-
28
- @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
29
- @inject(QuickAccessRegistry) protected readonly quickAccessRegistry: QuickAccessRegistry;
30
- @inject(ApplicationShell) protected readonly shell: ApplicationShell;
31
-
32
- protected groupLocalizations: string[] = [];
33
-
34
- registerQuickAccessProvider(): void {
35
- this.quickAccessRegistry.registerQuickAccessProvider({
36
- getInstance: () => this,
37
- prefix: QuickEditorService.PREFIX,
38
- placeholder: '',
39
- helpEntries: [{ description: 'Show All Opened Editors', needsEditor: false }]
40
- });
41
- }
42
-
43
- getPicks(filter: string, token: CancellationToken): (QuickPickItem | QuickPickSeparator)[] {
44
- const editorItems: QuickPickItemOrSeparator[] = [];
45
- const hasUri = (widget: Widget): widget is NavigatableWidget => Boolean(NavigatableWidget.getUri(widget));
46
- const handleWidgets = (widgets: NavigatableWidget[], label: string) => {
47
- if (widgets.length) {
48
- editorItems.push({ type: 'separator', label });
49
- }
50
- editorItems.push(...widgets.map(widget => this.toItem(widget)));
51
- };
52
- const handleSplittableArea = (tabbars: TabBar<Widget>[], labelPrefix: string) => {
53
- tabbars.forEach((tabbar, index) => {
54
- const editorsOnTabbar = tabbar.titles.reduce<NavigatableWidget[]>((widgets, title) => {
55
- if (hasUri(title.owner)) {
56
- widgets.push(title.owner);
57
- }
58
- return widgets;
59
- }, []);
60
- const label = tabbars.length > 1 ? `${labelPrefix} ${this.getGroupLocalization(index)}` : labelPrefix;
61
- handleWidgets(editorsOnTabbar, label);
62
- });
63
- };
64
-
65
- handleSplittableArea(this.shell.mainAreaTabBars, ApplicationShell.areaLabels.main);
66
- handleSplittableArea(this.shell.bottomAreaTabBars, ApplicationShell.areaLabels.bottom);
67
-
68
- for (const area of ['left', 'right'] as ApplicationShell.Area[]) {
69
- const editorsInArea = this.shell.getWidgets(area).filter(hasUri);
70
- handleWidgets(editorsInArea, ApplicationShell.areaLabels[area]);
71
- }
72
-
73
- return filterItems(editorItems.slice(), filter);
74
- }
75
-
76
- protected getGroupLocalization(index: number): string {
77
- return this.groupLocalizations[index] || nls.localizeByDefault('Group {0}', index + 1);
78
- }
79
-
80
- protected toItem(widget: NavigatableWidget): QuickPickItem {
81
- const uri = NavigatableWidget.getUri(widget)!;
82
- const icon = this.labelProvider.getIcon(uri);
83
- const iconClasses = icon === '' ? undefined : [icon + ' file-icon'];
84
-
85
- return {
86
- label: this.labelProvider.getName(uri),
87
- description: this.labelProvider.getDetails(uri),
88
- iconClasses,
89
- ariaLabel: uri.path.fsPath(),
90
- alwaysShow: true,
91
- execute: () => this.shell.activateWidget(widget.id),
92
- };
93
- }
94
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 SAP SE or an SAP affiliate company 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { CancellationToken, nls, QuickPickItemOrSeparator } from '@theia/core/lib/common';
19
+ import { LabelProvider } from '@theia/core/lib/browser/label-provider';
20
+ import { QuickAccessProvider, QuickAccessRegistry, QuickAccessContribution } from '@theia/core/lib/browser/quick-input/quick-access';
21
+ import { filterItems, QuickPickItem, QuickPickSeparator } from '@theia/core/lib/browser/quick-input/quick-input-service';
22
+ import { ApplicationShell, NavigatableWidget, TabBar, Widget } from '@theia/core/lib/browser';
23
+
24
+ @injectable()
25
+ export class QuickEditorService implements QuickAccessContribution, QuickAccessProvider {
26
+ static PREFIX = 'edt ';
27
+
28
+ @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
29
+ @inject(QuickAccessRegistry) protected readonly quickAccessRegistry: QuickAccessRegistry;
30
+ @inject(ApplicationShell) protected readonly shell: ApplicationShell;
31
+
32
+ protected groupLocalizations: string[] = [];
33
+
34
+ registerQuickAccessProvider(): void {
35
+ this.quickAccessRegistry.registerQuickAccessProvider({
36
+ getInstance: () => this,
37
+ prefix: QuickEditorService.PREFIX,
38
+ placeholder: '',
39
+ helpEntries: [{ description: 'Show All Opened Editors', needsEditor: false }]
40
+ });
41
+ }
42
+
43
+ getPicks(filter: string, token: CancellationToken): (QuickPickItem | QuickPickSeparator)[] {
44
+ const editorItems: QuickPickItemOrSeparator[] = [];
45
+ const hasUri = (widget: Widget): widget is NavigatableWidget => Boolean(NavigatableWidget.getUri(widget));
46
+ const handleWidgets = (widgets: NavigatableWidget[], label: string) => {
47
+ if (widgets.length) {
48
+ editorItems.push({ type: 'separator', label });
49
+ }
50
+ editorItems.push(...widgets.map(widget => this.toItem(widget)));
51
+ };
52
+ const handleSplittableArea = (tabbars: TabBar<Widget>[], labelPrefix: string) => {
53
+ tabbars.forEach((tabbar, index) => {
54
+ const editorsOnTabbar = tabbar.titles.reduce<NavigatableWidget[]>((widgets, title) => {
55
+ if (hasUri(title.owner)) {
56
+ widgets.push(title.owner);
57
+ }
58
+ return widgets;
59
+ }, []);
60
+ const label = tabbars.length > 1 ? `${labelPrefix} ${this.getGroupLocalization(index)}` : labelPrefix;
61
+ handleWidgets(editorsOnTabbar, label);
62
+ });
63
+ };
64
+
65
+ handleSplittableArea(this.shell.mainAreaTabBars, ApplicationShell.areaLabels.main);
66
+ handleSplittableArea(this.shell.bottomAreaTabBars, ApplicationShell.areaLabels.bottom);
67
+
68
+ for (const area of ['left', 'right'] as ApplicationShell.Area[]) {
69
+ const editorsInArea = this.shell.getWidgets(area).filter(hasUri);
70
+ handleWidgets(editorsInArea, ApplicationShell.areaLabels[area]);
71
+ }
72
+
73
+ return filterItems(editorItems.slice(), filter);
74
+ }
75
+
76
+ protected getGroupLocalization(index: number): string {
77
+ return this.groupLocalizations[index] || nls.localizeByDefault('Group {0}', index + 1);
78
+ }
79
+
80
+ protected toItem(widget: NavigatableWidget): QuickPickItem {
81
+ const uri = NavigatableWidget.getUri(widget)!;
82
+ const icon = this.labelProvider.getIcon(uri);
83
+ const iconClasses = icon === '' ? undefined : [icon + ' file-icon'];
84
+
85
+ return {
86
+ label: this.labelProvider.getName(uri),
87
+ description: this.labelProvider.getDetails(uri),
88
+ iconClasses,
89
+ ariaLabel: uri.path.fsPath(),
90
+ alwaysShow: true,
91
+ execute: () => this.shell.activateWidget(widget.id),
92
+ };
93
+ }
94
+ }
@@ -1,19 +1,19 @@
1
- /********************************************************************************
2
- * Copyright (C) 2020 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 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- .theia-editor {
18
- height: 100%;
19
- }
1
+ /********************************************************************************
2
+ * Copyright (C) 2020 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 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ .theia-editor {
18
+ height: 100%;
19
+ }
@@ -1,104 +1,104 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 Red Hat, Inc. 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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { match as matchGlobPattern } from '@theia/core/lib/common/glob';
18
-
19
- export interface RelativePattern {
20
- base: string;
21
- pattern: string;
22
- pathToRelative(from: string, to: string): string;
23
- }
24
-
25
- export interface LanguageFilter {
26
- language?: string;
27
- scheme?: string;
28
- pattern?: string | RelativePattern;
29
- hasAccessToAllModels?: boolean;
30
- }
31
- export type LanguageSelector = string | LanguageFilter | (string | LanguageFilter)[];
32
-
33
- export function score(selector: LanguageSelector | undefined, uriScheme: string, path: string, candidateLanguage: string, candidateIsSynchronized: boolean): number {
34
-
35
- if (Array.isArray(selector)) {
36
- let ret = 0;
37
- for (const filter of selector) {
38
- const value = score(filter, uriScheme, path, candidateLanguage, candidateIsSynchronized);
39
- if (value === 10) {
40
- return value;
41
- }
42
- if (value > ret) {
43
- ret = value;
44
- }
45
- }
46
- return ret;
47
-
48
- } else if (typeof selector === 'string') {
49
-
50
- if (!candidateIsSynchronized) {
51
- return 0;
52
- }
53
-
54
- if (selector === '*') {
55
- return 5;
56
- } else if (selector === candidateLanguage) {
57
- return 10;
58
- } else {
59
- return 0;
60
- }
61
-
62
- } else if (selector) {
63
- const { language, pattern, scheme, hasAccessToAllModels } = selector;
64
-
65
- if (!candidateIsSynchronized && !hasAccessToAllModels) {
66
- return 0;
67
- }
68
-
69
- let result = 0;
70
-
71
- if (scheme) {
72
- if (scheme === uriScheme) {
73
- result = 10;
74
- } else if (scheme === '*') {
75
- result = 5;
76
- } else {
77
- return 0;
78
- }
79
- }
80
-
81
- if (language) {
82
- if (language === candidateLanguage) {
83
- result = 10;
84
- } else if (language === '*') {
85
- result = Math.max(result, 5);
86
- } else {
87
- return 0;
88
- }
89
- }
90
-
91
- if (pattern) {
92
- if (pattern === path || matchGlobPattern(pattern, path)) {
93
- result = 10;
94
- } else {
95
- return 0;
96
- }
97
- }
98
-
99
- return result;
100
-
101
- } else {
102
- return 0;
103
- }
104
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2020 Red Hat, Inc. 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { match as matchGlobPattern } from '@theia/core/lib/common/glob';
18
+
19
+ export interface RelativePattern {
20
+ base: string;
21
+ pattern: string;
22
+ pathToRelative(from: string, to: string): string;
23
+ }
24
+
25
+ export interface LanguageFilter {
26
+ language?: string;
27
+ scheme?: string;
28
+ pattern?: string | RelativePattern;
29
+ hasAccessToAllModels?: boolean;
30
+ }
31
+ export type LanguageSelector = string | LanguageFilter | (string | LanguageFilter)[];
32
+
33
+ export function score(selector: LanguageSelector | undefined, uriScheme: string, path: string, candidateLanguage: string, candidateIsSynchronized: boolean): number {
34
+
35
+ if (Array.isArray(selector)) {
36
+ let ret = 0;
37
+ for (const filter of selector) {
38
+ const value = score(filter, uriScheme, path, candidateLanguage, candidateIsSynchronized);
39
+ if (value === 10) {
40
+ return value;
41
+ }
42
+ if (value > ret) {
43
+ ret = value;
44
+ }
45
+ }
46
+ return ret;
47
+
48
+ } else if (typeof selector === 'string') {
49
+
50
+ if (!candidateIsSynchronized) {
51
+ return 0;
52
+ }
53
+
54
+ if (selector === '*') {
55
+ return 5;
56
+ } else if (selector === candidateLanguage) {
57
+ return 10;
58
+ } else {
59
+ return 0;
60
+ }
61
+
62
+ } else if (selector) {
63
+ const { language, pattern, scheme, hasAccessToAllModels } = selector;
64
+
65
+ if (!candidateIsSynchronized && !hasAccessToAllModels) {
66
+ return 0;
67
+ }
68
+
69
+ let result = 0;
70
+
71
+ if (scheme) {
72
+ if (scheme === uriScheme) {
73
+ result = 10;
74
+ } else if (scheme === '*') {
75
+ result = 5;
76
+ } else {
77
+ return 0;
78
+ }
79
+ }
80
+
81
+ if (language) {
82
+ if (language === candidateLanguage) {
83
+ result = 10;
84
+ } else if (language === '*') {
85
+ result = Math.max(result, 5);
86
+ } else {
87
+ return 0;
88
+ }
89
+ }
90
+
91
+ if (pattern) {
92
+ if (pattern === path || matchGlobPattern(pattern, path)) {
93
+ result = 10;
94
+ } else {
95
+ return 0;
96
+ }
97
+ }
98
+
99
+ return result;
100
+
101
+ } else {
102
+ return 0;
103
+ }
104
+ }
@@ -1,28 +1,28 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 Ericsson 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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /* note: this bogus test file is required so that
18
- we are able to run mocha unit tests on this
19
- package, without having any actual unit tests in it.
20
- This way a coverage report will be generated,
21
- showing 0% coverage, instead of no report.
22
- This file can be removed once we have real unit
23
- tests in place. */
24
-
25
- describe('editor package', () => {
26
-
27
- it('support code coverage statistics', () => true);
28
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 Ericsson 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* note: this bogus test file is required so that
18
+ we are able to run mocha unit tests on this
19
+ package, without having any actual unit tests in it.
20
+ This way a coverage report will be generated,
21
+ showing 0% coverage, instead of no report.
22
+ This file can be removed once we have real unit
23
+ tests in place. */
24
+
25
+ describe('editor package', () => {
26
+
27
+ it('support code coverage statistics', () => true);
28
+ });