@theia/workspace 1.45.1 → 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.
Files changed (118) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/canonical-uri-service.d.ts +11 -11
  3. package/lib/browser/canonical-uri-service.js +59 -59
  4. package/lib/browser/diff-service.d.ts +10 -10
  5. package/lib/browser/diff-service.js +85 -85
  6. package/lib/browser/index.d.ts +7 -7
  7. package/lib/browser/index.js +34 -34
  8. package/lib/browser/quick-open-workspace.d.ts +25 -25
  9. package/lib/browser/quick-open-workspace.js +137 -137
  10. package/lib/browser/untitled-workspace-exit-dialog.d.ts +19 -19
  11. package/lib/browser/untitled-workspace-exit-dialog.js +74 -74
  12. package/lib/browser/workspace-breadcrumbs-contribution.d.ts +10 -10
  13. package/lib/browser/workspace-breadcrumbs-contribution.js +66 -66
  14. package/lib/browser/workspace-commands.d.ts +117 -117
  15. package/lib/browser/workspace-commands.js +601 -601
  16. package/lib/browser/workspace-commands.spec.d.ts +1 -1
  17. package/lib/browser/workspace-commands.spec.js +127 -127
  18. package/lib/browser/workspace-compare-handler.d.ts +26 -26
  19. package/lib/browser/workspace-compare-handler.js +66 -66
  20. package/lib/browser/workspace-delete-handler.d.ts +75 -75
  21. package/lib/browser/workspace-delete-handler.js +214 -214
  22. package/lib/browser/workspace-duplicate-handler.d.ts +30 -30
  23. package/lib/browser/workspace-duplicate-handler.js +86 -86
  24. package/lib/browser/workspace-frontend-contribution.d.ts +110 -110
  25. package/lib/browser/workspace-frontend-contribution.js +546 -546
  26. package/lib/browser/workspace-frontend-contribution.js.map +1 -1
  27. package/lib/browser/workspace-frontend-module.d.ts +3 -3
  28. package/lib/browser/workspace-frontend-module.js +91 -91
  29. package/lib/browser/workspace-input-dialog.d.ts +19 -19
  30. package/lib/browser/workspace-input-dialog.js +74 -74
  31. package/lib/browser/workspace-preferences.d.ts +11 -11
  32. package/lib/browser/workspace-preferences.js +46 -46
  33. package/lib/browser/workspace-schema-updater.d.ts +34 -34
  34. package/lib/browser/workspace-schema-updater.js +153 -153
  35. package/lib/browser/workspace-service.d.ts +184 -184
  36. package/lib/browser/workspace-service.js +739 -739
  37. package/lib/browser/workspace-storage-service.d.ts +15 -15
  38. package/lib/browser/workspace-storage-service.js +80 -80
  39. package/lib/browser/workspace-trust-preferences.d.ts +21 -21
  40. package/lib/browser/workspace-trust-preferences.js +65 -65
  41. package/lib/browser/workspace-trust-service.d.ts +27 -27
  42. package/lib/browser/workspace-trust-service.js +152 -152
  43. package/lib/browser/workspace-uri-contribution.d.ts +20 -20
  44. package/lib/browser/workspace-uri-contribution.js +113 -113
  45. package/lib/browser/workspace-uri-contribution.spec.d.ts +1 -1
  46. package/lib/browser/workspace-uri-contribution.spec.js +169 -169
  47. package/lib/browser/workspace-user-working-directory-provider.d.ts +12 -12
  48. package/lib/browser/workspace-user-working-directory-provider.js +62 -62
  49. package/lib/browser/workspace-utils.d.ts +15 -15
  50. package/lib/browser/workspace-utils.js +54 -54
  51. package/lib/browser/workspace-variable-contribution.d.ts +23 -23
  52. package/lib/browser/workspace-variable-contribution.js +237 -237
  53. package/lib/browser/workspace-window-title-updater.d.ts +7 -7
  54. package/lib/browser/workspace-window-title-updater.js +57 -57
  55. package/lib/browser-only/browser-only-workspace-server.d.ts +13 -0
  56. package/lib/browser-only/browser-only-workspace-server.d.ts.map +1 -0
  57. package/lib/browser-only/browser-only-workspace-server.js +81 -0
  58. package/lib/browser-only/browser-only-workspace-server.js.map +1 -0
  59. package/lib/browser-only/workspace-frontend-only-module.d.ts +4 -0
  60. package/lib/browser-only/workspace-frontend-only-module.d.ts.map +1 -0
  61. package/lib/browser-only/workspace-frontend-only-module.js +30 -0
  62. package/lib/browser-only/workspace-frontend-only-module.js.map +1 -0
  63. package/lib/common/index.d.ts +3 -3
  64. package/lib/common/index.js +30 -30
  65. package/lib/common/test/mock-workspace-server.d.ts +7 -7
  66. package/lib/common/test/mock-workspace-server.js +35 -35
  67. package/lib/common/untitled-workspace-service.d.ts +8 -8
  68. package/lib/common/untitled-workspace-service.js +60 -60
  69. package/lib/common/workspace-file-service.d.ts +26 -26
  70. package/lib/common/workspace-file-service.js +71 -71
  71. package/lib/common/workspace-protocol.d.ts +26 -26
  72. package/lib/common/workspace-protocol.js +23 -23
  73. package/lib/node/default-workspace-server.d.ts +65 -65
  74. package/lib/node/default-workspace-server.js +248 -248
  75. package/lib/node/default-workspace-server.spec.d.ts +1 -1
  76. package/lib/node/default-workspace-server.spec.js +85 -85
  77. package/lib/node/index.d.ts +2 -2
  78. package/lib/node/index.js +29 -29
  79. package/lib/node/workspace-backend-module.d.ts +3 -3
  80. package/lib/node/workspace-backend-module.js +33 -33
  81. package/package.json +9 -6
  82. package/src/browser/canonical-uri-service.ts +57 -57
  83. package/src/browser/diff-service.ts +62 -62
  84. package/src/browser/index.ts +23 -23
  85. package/src/browser/quick-open-workspace.ts +112 -112
  86. package/src/browser/untitled-workspace-exit-dialog.ts +70 -70
  87. package/src/browser/workspace-breadcrumbs-contribution.ts +56 -56
  88. package/src/browser/workspace-commands.spec.ts +153 -153
  89. package/src/browser/workspace-commands.ts +588 -588
  90. package/src/browser/workspace-compare-handler.ts +56 -56
  91. package/src/browser/workspace-delete-handler.ts +212 -212
  92. package/src/browser/workspace-duplicate-handler.ts +75 -75
  93. package/src/browser/workspace-frontend-contribution.ts +537 -537
  94. package/src/browser/workspace-frontend-module.ts +118 -118
  95. package/src/browser/workspace-input-dialog.ts +61 -61
  96. package/src/browser/workspace-preferences.ts +58 -58
  97. package/src/browser/workspace-schema-updater.ts +150 -150
  98. package/src/browser/workspace-service.ts +780 -780
  99. package/src/browser/workspace-storage-service.ts +67 -67
  100. package/src/browser/workspace-trust-preferences.ts +76 -76
  101. package/src/browser/workspace-trust-service.ts +147 -147
  102. package/src/browser/workspace-uri-contribution.spec.ts +191 -191
  103. package/src/browser/workspace-uri-contribution.ts +97 -97
  104. package/src/browser/workspace-user-working-directory-provider.ts +49 -49
  105. package/src/browser/workspace-utils.ts +45 -45
  106. package/src/browser/workspace-variable-contribution.ts +222 -222
  107. package/src/browser/workspace-window-title-updater.ts +45 -45
  108. package/src/browser-only/browser-only-workspace-server.ts +69 -0
  109. package/src/browser-only/workspace-frontend-only-module.ts +28 -0
  110. package/src/common/index.ts +19 -19
  111. package/src/common/test/mock-workspace-server.ts +29 -29
  112. package/src/common/untitled-workspace-service.ts +50 -50
  113. package/src/common/workspace-file-service.ts +72 -72
  114. package/src/common/workspace-protocol.ts +47 -47
  115. package/src/node/default-workspace-server.spec.ts +100 -100
  116. package/src/node/default-workspace-server.ts +244 -244
  117. package/src/node/index.ts +18 -18
  118. package/src/node/workspace-backend-module.ts +38 -38
@@ -1,191 +1,191 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
18
- const disableJSDOM = enableJSDOM();
19
-
20
- import { expect } from 'chai';
21
- import * as sinon from 'sinon';
22
- import { Container } from '@theia/core/shared/inversify';
23
- import { Event } from '@theia/core/lib/common/event';
24
- import { ApplicationShell, WidgetManager } from '@theia/core/lib/browser';
25
- import { DefaultUriLabelProviderContribution } from '@theia/core/lib/browser/label-provider';
26
- import { WorkspaceUriLabelProviderContribution } from './workspace-uri-contribution';
27
- import URI from '@theia/core/lib/common/uri';
28
- import { WorkspaceVariableContribution } from './workspace-variable-contribution';
29
- import { WorkspaceService } from './workspace-service';
30
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
31
- import { FileStat } from '@theia/filesystem/lib/common/files';
32
- import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
33
- import { MockEnvVariablesServerImpl } from '@theia/core/lib/browser/test/mock-env-variables-server';
34
- import { FileUri } from '@theia/core/lib/node';
35
- import { OS } from '@theia/core/lib/common/os';
36
- import * as temp from 'temp';
37
-
38
- after(() => disableJSDOM());
39
-
40
- let container: Container;
41
- let labelProvider: WorkspaceUriLabelProviderContribution;
42
- let roots: FileStat[];
43
- beforeEach(() => {
44
- roots = [FileStat.dir('file:///workspace')];
45
-
46
- container = new Container();
47
- container.bind(ApplicationShell).toConstantValue({
48
- onDidChangeCurrentWidget: () => undefined,
49
- widgets: []
50
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- } as any);
52
- container.bind(WidgetManager).toConstantValue({
53
- onDidCreateWidget: Event.None
54
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
- } as any);
56
- const workspaceService = new WorkspaceService();
57
- workspaceService.tryGetRoots = () => roots;
58
- container.bind(WorkspaceService).toConstantValue(workspaceService);
59
- container.bind(WorkspaceVariableContribution).toSelf().inSingletonScope();
60
- container.bind(WorkspaceUriLabelProviderContribution).toSelf().inSingletonScope();
61
- container.bind(FileService).toConstantValue({} as FileService);
62
- container.bind(EnvVariablesServer).toConstantValue(new MockEnvVariablesServerImpl(FileUri.create(temp.track().mkdirSync())));
63
- labelProvider = container.get(WorkspaceUriLabelProviderContribution);
64
- });
65
-
66
- afterEach(() => {
67
- roots = undefined!;
68
- labelProvider = undefined!;
69
- container = undefined!;
70
- });
71
-
72
- describe('WorkspaceUriLabelProviderContribution class', () => {
73
- const stubs: sinon.SinonStub[] = [];
74
-
75
- afterEach(() => {
76
- stubs.forEach(s => s.restore());
77
- stubs.length = 0;
78
- });
79
-
80
- describe('canHandle()', () => {
81
- it('should return 0 if the passed in argument is not a FileStat or URI with the "file" scheme', () => {
82
- expect(labelProvider.canHandle(new URI('user-storage:settings.json'))).eq(0);
83
- expect(labelProvider.canHandle({ uri: 'file:///home/settings.json' })).eq(0);
84
- });
85
-
86
- it('should return 10 if the passed in argument is a FileStat or URI with the "file" scheme', () => {
87
- expect(labelProvider.canHandle(new URI('file:///home/settings.json'))).eq(10);
88
- expect(labelProvider.canHandle(FileStat.file('file:///home/settings.json'))).eq(10);
89
- });
90
- });
91
-
92
- describe('getIcon()', () => {
93
- it('should return folder icon from the FileStat of a folder', async () => {
94
- expect(labelProvider.getIcon(FileStat.dir('file:///home/'))).eq(labelProvider.defaultFolderIcon);
95
- });
96
-
97
- it('should return file icon from a non-folder FileStat', async () => {
98
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
- stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(undefined));
100
- expect(labelProvider.getIcon(FileStat.file('file:///home/test'))).eq(labelProvider.defaultFileIcon);
101
- });
102
-
103
- it('should return folder icon from a folder FileStat', async () => {
104
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
- stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(undefined));
106
- expect(labelProvider.getIcon(FileStat.dir('file:///home/test'))).eq(labelProvider.defaultFolderIcon);
107
- });
108
-
109
- it('should return file icon from a file FileStat', async () => {
110
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
- stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(undefined));
112
- expect(labelProvider.getIcon(FileStat.file('file:///home/test'))).eq(labelProvider.defaultFileIcon);
113
- });
114
-
115
- it('should return what getFileIcon() returns from a URI or non-folder FileStat, if getFileIcon() does not return null or undefined', async () => {
116
- const ret = 'TestString';
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(ret));
119
- expect(labelProvider.getIcon(new URI('file:///home/test'))).eq(ret);
120
- expect(labelProvider.getIcon(FileStat.file('file:///home/test'))).eq(ret);
121
- });
122
-
123
- it('should return the default folder icon for a URI or file stat that corresponds to a workspace root', () => {
124
- expect(labelProvider.getIcon(new URI('file:///workspace'))).eq(labelProvider.defaultFolderIcon);
125
- expect(labelProvider.getIcon(FileStat.dir('file:///workspace'))).eq(labelProvider.defaultFolderIcon);
126
- });
127
- });
128
-
129
- describe('getName()', () => {
130
- it('should return the display name of a file from its URI', () => {
131
- const file = new URI('file:///workspace-2/jacques.doc');
132
- const name = labelProvider.getName(file);
133
- expect(name).eq('jacques.doc');
134
- });
135
-
136
- it('should return the display name of a file from its FileStat', () => {
137
- const file: FileStat = FileStat.file('file:///workspace-2/jacques.doc');
138
- const name = labelProvider.getName(file);
139
- expect(name).eq('jacques.doc');
140
- });
141
- });
142
-
143
- describe('getLongName()', () => {
144
- it('should return the path of a file relative to the workspace from the file\'s URI if the file is in the workspace', () => {
145
- const file = new URI('file:///workspace/some/very-long/path.js');
146
- const longName = labelProvider.getLongName(file);
147
- expect(longName).eq('some/very-long/path.js');
148
- });
149
-
150
- it('should return the path of a file relative to the workspace from the file\'s FileStat if the file is in the workspace', () => {
151
- const file: FileStat = FileStat.file('file:///workspace/some/very-long/path.js');
152
- const longName = labelProvider.getLongName(file);
153
- expect(longName).eq('some/very-long/path.js');
154
- });
155
-
156
- it('should return the absolute path of a file from the file\'s URI if the file is not in the workspace', () => {
157
- const file = new URI('file:///tmp/prout.txt');
158
- const longName = labelProvider.getLongName(file);
159
-
160
- if (OS.backend.isWindows) {
161
- expect(longName).eq('\\tmp\\prout.txt');
162
- } else {
163
- expect(longName).eq('/tmp/prout.txt');
164
- }
165
- });
166
-
167
- it('should return the absolute path of a file from the file\'s FileStat if the file is not in the workspace', () => {
168
- const file: FileStat = FileStat.file('file:///tmp/prout.txt');
169
- const longName = labelProvider.getLongName(file);
170
-
171
- if (OS.backend.isWindows) {
172
- expect(longName).eq('\\tmp\\prout.txt');
173
- } else {
174
- expect(longName).eq('/tmp/prout.txt');
175
- }
176
- });
177
-
178
- it('should return the path of a file if WorkspaceService returns no roots', () => {
179
- roots = [];
180
- const file = new URI('file:///tmp/prout.txt');
181
- const longName = labelProvider.getLongName(file);
182
-
183
- if (OS.backend.isWindows) {
184
- expect(longName).eq('\\tmp\\prout.txt');
185
- } else {
186
- expect(longName).eq('/tmp/prout.txt');
187
- }
188
- });
189
- });
190
-
191
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
18
+ const disableJSDOM = enableJSDOM();
19
+
20
+ import { expect } from 'chai';
21
+ import * as sinon from 'sinon';
22
+ import { Container } from '@theia/core/shared/inversify';
23
+ import { Event } from '@theia/core/lib/common/event';
24
+ import { ApplicationShell, WidgetManager } from '@theia/core/lib/browser';
25
+ import { DefaultUriLabelProviderContribution } from '@theia/core/lib/browser/label-provider';
26
+ import { WorkspaceUriLabelProviderContribution } from './workspace-uri-contribution';
27
+ import URI from '@theia/core/lib/common/uri';
28
+ import { WorkspaceVariableContribution } from './workspace-variable-contribution';
29
+ import { WorkspaceService } from './workspace-service';
30
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
31
+ import { FileStat } from '@theia/filesystem/lib/common/files';
32
+ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
33
+ import { MockEnvVariablesServerImpl } from '@theia/core/lib/browser/test/mock-env-variables-server';
34
+ import { FileUri } from '@theia/core/lib/node';
35
+ import { OS } from '@theia/core/lib/common/os';
36
+ import * as temp from 'temp';
37
+
38
+ after(() => disableJSDOM());
39
+
40
+ let container: Container;
41
+ let labelProvider: WorkspaceUriLabelProviderContribution;
42
+ let roots: FileStat[];
43
+ beforeEach(() => {
44
+ roots = [FileStat.dir('file:///workspace')];
45
+
46
+ container = new Container();
47
+ container.bind(ApplicationShell).toConstantValue({
48
+ onDidChangeCurrentWidget: () => undefined,
49
+ widgets: []
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ } as any);
52
+ container.bind(WidgetManager).toConstantValue({
53
+ onDidCreateWidget: Event.None
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ } as any);
56
+ const workspaceService = new WorkspaceService();
57
+ workspaceService.tryGetRoots = () => roots;
58
+ container.bind(WorkspaceService).toConstantValue(workspaceService);
59
+ container.bind(WorkspaceVariableContribution).toSelf().inSingletonScope();
60
+ container.bind(WorkspaceUriLabelProviderContribution).toSelf().inSingletonScope();
61
+ container.bind(FileService).toConstantValue({} as FileService);
62
+ container.bind(EnvVariablesServer).toConstantValue(new MockEnvVariablesServerImpl(FileUri.create(temp.track().mkdirSync())));
63
+ labelProvider = container.get(WorkspaceUriLabelProviderContribution);
64
+ });
65
+
66
+ afterEach(() => {
67
+ roots = undefined!;
68
+ labelProvider = undefined!;
69
+ container = undefined!;
70
+ });
71
+
72
+ describe('WorkspaceUriLabelProviderContribution class', () => {
73
+ const stubs: sinon.SinonStub[] = [];
74
+
75
+ afterEach(() => {
76
+ stubs.forEach(s => s.restore());
77
+ stubs.length = 0;
78
+ });
79
+
80
+ describe('canHandle()', () => {
81
+ it('should return 0 if the passed in argument is not a FileStat or URI with the "file" scheme', () => {
82
+ expect(labelProvider.canHandle(new URI('user-storage:settings.json'))).eq(0);
83
+ expect(labelProvider.canHandle({ uri: 'file:///home/settings.json' })).eq(0);
84
+ });
85
+
86
+ it('should return 10 if the passed in argument is a FileStat or URI with the "file" scheme', () => {
87
+ expect(labelProvider.canHandle(new URI('file:///home/settings.json'))).eq(10);
88
+ expect(labelProvider.canHandle(FileStat.file('file:///home/settings.json'))).eq(10);
89
+ });
90
+ });
91
+
92
+ describe('getIcon()', () => {
93
+ it('should return folder icon from the FileStat of a folder', async () => {
94
+ expect(labelProvider.getIcon(FileStat.dir('file:///home/'))).eq(labelProvider.defaultFolderIcon);
95
+ });
96
+
97
+ it('should return file icon from a non-folder FileStat', async () => {
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(undefined));
100
+ expect(labelProvider.getIcon(FileStat.file('file:///home/test'))).eq(labelProvider.defaultFileIcon);
101
+ });
102
+
103
+ it('should return folder icon from a folder FileStat', async () => {
104
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
+ stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(undefined));
106
+ expect(labelProvider.getIcon(FileStat.dir('file:///home/test'))).eq(labelProvider.defaultFolderIcon);
107
+ });
108
+
109
+ it('should return file icon from a file FileStat', async () => {
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(undefined));
112
+ expect(labelProvider.getIcon(FileStat.file('file:///home/test'))).eq(labelProvider.defaultFileIcon);
113
+ });
114
+
115
+ it('should return what getFileIcon() returns from a URI or non-folder FileStat, if getFileIcon() does not return null or undefined', async () => {
116
+ const ret = 'TestString';
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
+ stubs.push(sinon.stub(DefaultUriLabelProviderContribution.prototype, <any>'getFileIcon').returns(ret));
119
+ expect(labelProvider.getIcon(new URI('file:///home/test'))).eq(ret);
120
+ expect(labelProvider.getIcon(FileStat.file('file:///home/test'))).eq(ret);
121
+ });
122
+
123
+ it('should return the default folder icon for a URI or file stat that corresponds to a workspace root', () => {
124
+ expect(labelProvider.getIcon(new URI('file:///workspace'))).eq(labelProvider.defaultFolderIcon);
125
+ expect(labelProvider.getIcon(FileStat.dir('file:///workspace'))).eq(labelProvider.defaultFolderIcon);
126
+ });
127
+ });
128
+
129
+ describe('getName()', () => {
130
+ it('should return the display name of a file from its URI', () => {
131
+ const file = new URI('file:///workspace-2/jacques.doc');
132
+ const name = labelProvider.getName(file);
133
+ expect(name).eq('jacques.doc');
134
+ });
135
+
136
+ it('should return the display name of a file from its FileStat', () => {
137
+ const file: FileStat = FileStat.file('file:///workspace-2/jacques.doc');
138
+ const name = labelProvider.getName(file);
139
+ expect(name).eq('jacques.doc');
140
+ });
141
+ });
142
+
143
+ describe('getLongName()', () => {
144
+ it('should return the path of a file relative to the workspace from the file\'s URI if the file is in the workspace', () => {
145
+ const file = new URI('file:///workspace/some/very-long/path.js');
146
+ const longName = labelProvider.getLongName(file);
147
+ expect(longName).eq('some/very-long/path.js');
148
+ });
149
+
150
+ it('should return the path of a file relative to the workspace from the file\'s FileStat if the file is in the workspace', () => {
151
+ const file: FileStat = FileStat.file('file:///workspace/some/very-long/path.js');
152
+ const longName = labelProvider.getLongName(file);
153
+ expect(longName).eq('some/very-long/path.js');
154
+ });
155
+
156
+ it('should return the absolute path of a file from the file\'s URI if the file is not in the workspace', () => {
157
+ const file = new URI('file:///tmp/prout.txt');
158
+ const longName = labelProvider.getLongName(file);
159
+
160
+ if (OS.backend.isWindows) {
161
+ expect(longName).eq('\\tmp\\prout.txt');
162
+ } else {
163
+ expect(longName).eq('/tmp/prout.txt');
164
+ }
165
+ });
166
+
167
+ it('should return the absolute path of a file from the file\'s FileStat if the file is not in the workspace', () => {
168
+ const file: FileStat = FileStat.file('file:///tmp/prout.txt');
169
+ const longName = labelProvider.getLongName(file);
170
+
171
+ if (OS.backend.isWindows) {
172
+ expect(longName).eq('\\tmp\\prout.txt');
173
+ } else {
174
+ expect(longName).eq('/tmp/prout.txt');
175
+ }
176
+ });
177
+
178
+ it('should return the path of a file if WorkspaceService returns no roots', () => {
179
+ roots = [];
180
+ const file = new URI('file:///tmp/prout.txt');
181
+ const longName = labelProvider.getLongName(file);
182
+
183
+ if (OS.backend.isWindows) {
184
+ expect(longName).eq('\\tmp\\prout.txt');
185
+ } else {
186
+ expect(longName).eq('/tmp/prout.txt');
187
+ }
188
+ });
189
+ });
190
+
191
+ });
@@ -1,97 +1,97 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 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 { DefaultUriLabelProviderContribution, URIIconReference } from '@theia/core/lib/browser/label-provider';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
20
- import { FileStat } from '@theia/filesystem/lib/common/files';
21
- import { WorkspaceService } from './workspace-service';
22
- import { WorkspaceVariableContribution } from './workspace-variable-contribution';
23
-
24
- @injectable()
25
- export class WorkspaceUriLabelProviderContribution extends DefaultUriLabelProviderContribution {
26
-
27
- @inject(WorkspaceVariableContribution) protected readonly workspaceVariable: WorkspaceVariableContribution;
28
- @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
29
-
30
- @postConstruct()
31
- override init(): void {
32
- // no-op, backward compatibility
33
- }
34
-
35
- override canHandle(element: object): number {
36
- if ((element instanceof URI && element.scheme === 'file' || URIIconReference.is(element) || FileStat.is(element))) {
37
- return 10;
38
- }
39
- return 0;
40
- }
41
-
42
- override getIcon(element: URI | URIIconReference | FileStat): string {
43
- return super.getIcon(this.asURIIconReference(element));
44
- }
45
-
46
- override getName(element: URI | URIIconReference | FileStat): string | undefined {
47
- return super.getName(this.asURIIconReference(element));
48
- }
49
-
50
- /**
51
- * trims the workspace root from a file uri, if it is a child.
52
- */
53
- override getLongName(element: URI | URIIconReference | FileStat): string | undefined {
54
- const uri = this.getUri(element);
55
- if (uri) {
56
- const formatting = this.findFormatting(uri);
57
- if (formatting) {
58
- return this.formatUri(uri, formatting);
59
- }
60
- }
61
- const relativePath = uri && this.workspaceVariable.getWorkspaceRelativePath(uri);
62
- return relativePath || super.getLongName(this.asURIIconReference(element));
63
- }
64
-
65
- override getDetails(element: URI | URIIconReference | FileStat): string | undefined {
66
- const uri = this.getUri(element);
67
- if (!uri) {
68
- return this.getLongName(element);
69
- }
70
- // Parent in order to omit the name - that's what comes out of `getName`, and `getDetails` should supplement, not duplicate.
71
- const relativePath = uri && this.workspaceVariable.getWorkspaceRelativePath(uri.parent);
72
- if (relativePath !== undefined) {
73
- const prefix = this.workspaceService.tryGetRoots().length > 1 ? this.getName(this.workspaceVariable.getWorkspaceRootUri(uri)!) : '';
74
- const separator = prefix && relativePath ? ' • ' : '';
75
- return prefix + separator + relativePath;
76
- }
77
- return this.getLongName(uri.parent);
78
- }
79
-
80
- protected asURIIconReference(element: URI | URIIconReference | FileStat): URI | URIIconReference {
81
- if (FileStat.is(element)) {
82
- return URIIconReference.create(element.isDirectory ? 'folder' : 'file', element.resource);
83
- }
84
- const uri = this.getUri(element);
85
- if (uri && this.workspaceVariable.getWorkspaceRootUri(uri)?.isEqual(uri)) {
86
- return URIIconReference.create('folder', uri);
87
- }
88
- return element;
89
- }
90
-
91
- protected override getUri(element: URI | URIIconReference | FileStat): URI | undefined {
92
- if (FileStat.is(element)) {
93
- return element.resource;
94
- }
95
- return super.getUri(element);
96
- }
97
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 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 { DefaultUriLabelProviderContribution, URIIconReference } from '@theia/core/lib/browser/label-provider';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
20
+ import { FileStat } from '@theia/filesystem/lib/common/files';
21
+ import { WorkspaceService } from './workspace-service';
22
+ import { WorkspaceVariableContribution } from './workspace-variable-contribution';
23
+
24
+ @injectable()
25
+ export class WorkspaceUriLabelProviderContribution extends DefaultUriLabelProviderContribution {
26
+
27
+ @inject(WorkspaceVariableContribution) protected readonly workspaceVariable: WorkspaceVariableContribution;
28
+ @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
29
+
30
+ @postConstruct()
31
+ override init(): void {
32
+ // no-op, backward compatibility
33
+ }
34
+
35
+ override canHandle(element: object): number {
36
+ if ((element instanceof URI && element.scheme === 'file' || URIIconReference.is(element) || FileStat.is(element))) {
37
+ return 10;
38
+ }
39
+ return 0;
40
+ }
41
+
42
+ override getIcon(element: URI | URIIconReference | FileStat): string {
43
+ return super.getIcon(this.asURIIconReference(element));
44
+ }
45
+
46
+ override getName(element: URI | URIIconReference | FileStat): string | undefined {
47
+ return super.getName(this.asURIIconReference(element));
48
+ }
49
+
50
+ /**
51
+ * trims the workspace root from a file uri, if it is a child.
52
+ */
53
+ override getLongName(element: URI | URIIconReference | FileStat): string | undefined {
54
+ const uri = this.getUri(element);
55
+ if (uri) {
56
+ const formatting = this.findFormatting(uri);
57
+ if (formatting) {
58
+ return this.formatUri(uri, formatting);
59
+ }
60
+ }
61
+ const relativePath = uri && this.workspaceVariable.getWorkspaceRelativePath(uri);
62
+ return relativePath || super.getLongName(this.asURIIconReference(element));
63
+ }
64
+
65
+ override getDetails(element: URI | URIIconReference | FileStat): string | undefined {
66
+ const uri = this.getUri(element);
67
+ if (!uri) {
68
+ return this.getLongName(element);
69
+ }
70
+ // Parent in order to omit the name - that's what comes out of `getName`, and `getDetails` should supplement, not duplicate.
71
+ const relativePath = uri && this.workspaceVariable.getWorkspaceRelativePath(uri.parent);
72
+ if (relativePath !== undefined) {
73
+ const prefix = this.workspaceService.tryGetRoots().length > 1 ? this.getName(this.workspaceVariable.getWorkspaceRootUri(uri)!) : '';
74
+ const separator = prefix && relativePath ? ' • ' : '';
75
+ return prefix + separator + relativePath;
76
+ }
77
+ return this.getLongName(uri.parent);
78
+ }
79
+
80
+ protected asURIIconReference(element: URI | URIIconReference | FileStat): URI | URIIconReference {
81
+ if (FileStat.is(element)) {
82
+ return URIIconReference.create(element.isDirectory ? 'folder' : 'file', element.resource);
83
+ }
84
+ const uri = this.getUri(element);
85
+ if (uri && this.workspaceVariable.getWorkspaceRootUri(uri)?.isEqual(uri)) {
86
+ return URIIconReference.create('folder', uri);
87
+ }
88
+ return element;
89
+ }
90
+
91
+ protected override getUri(element: URI | URIIconReference | FileStat): URI | undefined {
92
+ if (FileStat.is(element)) {
93
+ return element.resource;
94
+ }
95
+ return super.getUri(element);
96
+ }
97
+ }