@theia/workspace 1.53.0-next.5 → 1.53.0-next.55

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 (43) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/workspace-commands.js +2 -2
  3. package/lib/browser/workspace-commands.js.map +1 -1
  4. package/lib/browser/workspace-service.js +1 -1
  5. package/lib/browser/workspace-service.js.map +1 -1
  6. package/package.json +6 -6
  7. package/src/browser/canonical-uri-service.ts +57 -57
  8. package/src/browser/diff-service.ts +62 -62
  9. package/src/browser/index.ts +23 -23
  10. package/src/browser/quick-open-workspace.ts +112 -112
  11. package/src/browser/untitled-workspace-exit-dialog.ts +70 -70
  12. package/src/browser/workspace-breadcrumbs-contribution.ts +56 -56
  13. package/src/browser/workspace-commands.spec.ts +153 -153
  14. package/src/browser/workspace-commands.ts +557 -557
  15. package/src/browser/workspace-compare-handler.ts +56 -56
  16. package/src/browser/workspace-delete-handler.ts +212 -212
  17. package/src/browser/workspace-duplicate-handler.ts +75 -75
  18. package/src/browser/workspace-frontend-contribution.ts +537 -537
  19. package/src/browser/workspace-frontend-module.ts +118 -118
  20. package/src/browser/workspace-input-dialog.ts +61 -61
  21. package/src/browser/workspace-preferences.ts +58 -58
  22. package/src/browser/workspace-schema-updater.ts +150 -150
  23. package/src/browser/workspace-service.ts +780 -780
  24. package/src/browser/workspace-storage-service.ts +67 -67
  25. package/src/browser/workspace-trust-preferences.ts +76 -76
  26. package/src/browser/workspace-trust-service.ts +152 -152
  27. package/src/browser/workspace-uri-contribution.spec.ts +191 -191
  28. package/src/browser/workspace-uri-contribution.ts +97 -97
  29. package/src/browser/workspace-user-working-directory-provider.ts +49 -49
  30. package/src/browser/workspace-utils.ts +45 -45
  31. package/src/browser/workspace-variable-contribution.ts +222 -222
  32. package/src/browser/workspace-window-title-updater.ts +45 -45
  33. package/src/browser-only/browser-only-workspace-server.ts +69 -69
  34. package/src/browser-only/workspace-frontend-only-module.ts +28 -28
  35. package/src/common/index.ts +19 -19
  36. package/src/common/test/mock-workspace-server.ts +29 -29
  37. package/src/common/untitled-workspace-service.ts +50 -50
  38. package/src/common/workspace-file-service.ts +72 -72
  39. package/src/common/workspace-protocol.ts +47 -47
  40. package/src/node/default-workspace-server.spec.ts +100 -100
  41. package/src/node/default-workspace-server.ts +244 -244
  42. package/src/node/index.ts +18 -18
  43. package/src/node/workspace-backend-module.ts +38 -38
@@ -1,45 +1,45 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 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 { WindowTitleUpdater } from '@theia/core/lib/browser/window/window-title-updater';
18
- import { inject, injectable } from '@theia/core/shared/inversify';
19
- import { Widget } from '@theia/core/lib/browser/widgets/widget';
20
- import { WorkspaceService } from './workspace-service';
21
- import { Navigatable } from '@theia/core/lib/browser/navigatable';
22
-
23
- @injectable()
24
- export class WorkspaceWindowTitleUpdater extends WindowTitleUpdater {
25
-
26
- @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
27
-
28
- protected override updateTitleWidget(widget?: Widget): void {
29
- super.updateTitleWidget(widget);
30
- let folderName: string | undefined;
31
- let folderPath: string | undefined;
32
- if (Navigatable.is(widget)) {
33
- const folder = this.workspaceService.getWorkspaceRootUri(widget.getResourceUri());
34
- if (folder) {
35
- folderName = this.labelProvider.getName(folder);
36
- folderPath = folder.path.toString();
37
- }
38
- }
39
- this.windowTitleService.update({
40
- folderName,
41
- folderPath
42
- });
43
- }
44
-
45
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 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 { WindowTitleUpdater } from '@theia/core/lib/browser/window/window-title-updater';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { Widget } from '@theia/core/lib/browser/widgets/widget';
20
+ import { WorkspaceService } from './workspace-service';
21
+ import { Navigatable } from '@theia/core/lib/browser/navigatable';
22
+
23
+ @injectable()
24
+ export class WorkspaceWindowTitleUpdater extends WindowTitleUpdater {
25
+
26
+ @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
27
+
28
+ protected override updateTitleWidget(widget?: Widget): void {
29
+ super.updateTitleWidget(widget);
30
+ let folderName: string | undefined;
31
+ let folderPath: string | undefined;
32
+ if (Navigatable.is(widget)) {
33
+ const folder = this.workspaceService.getWorkspaceRootUri(widget.getResourceUri());
34
+ if (folder) {
35
+ folderName = this.labelProvider.getName(folder);
36
+ folderPath = folder.path.toString();
37
+ }
38
+ }
39
+ this.windowTitleService.update({
40
+ folderName,
41
+ folderPath
42
+ });
43
+ }
44
+
45
+ }
@@ -1,69 +1,69 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 EclipseSource 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
- import { inject, injectable } from '@theia/core/shared/inversify';
17
- import { WorkspaceServer } from '../common/workspace-protocol';
18
- import { ILogger, isStringArray } from '@theia/core';
19
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
20
-
21
- export const RECENT_WORKSPACES_LOCAL_STORAGE_KEY = 'workspaces';
22
-
23
- @injectable()
24
- export class BrowserOnlyWorkspaceServer implements WorkspaceServer {
25
-
26
- @inject(ILogger)
27
- protected logger: ILogger;
28
-
29
- @inject(FileService)
30
- protected readonly fileService: FileService;
31
-
32
- async getRecentWorkspaces(): Promise<string[]> {
33
- const storedWorkspaces = localStorage.getItem(RECENT_WORKSPACES_LOCAL_STORAGE_KEY);
34
- if (!storedWorkspaces) {
35
- return [];
36
- }
37
- try {
38
- const parsedWorkspaces = JSON.parse(storedWorkspaces);
39
- if (isStringArray(parsedWorkspaces)) {
40
- return parsedWorkspaces;
41
- }
42
- } catch (e) {
43
- this.logger.error(e);
44
- return [];
45
- }
46
- return [];
47
- }
48
-
49
- async getMostRecentlyUsedWorkspace(): Promise<string | undefined> {
50
- const workspaces = await this.getRecentWorkspaces();
51
- return workspaces[0];
52
- }
53
-
54
- async setMostRecentlyUsedWorkspace(uri: string): Promise<void> {
55
- const workspaces = await this.getRecentWorkspaces();
56
- if (workspaces.includes(uri)) {
57
- workspaces.splice(workspaces.indexOf(uri), 1);
58
- }
59
- localStorage.setItem(RECENT_WORKSPACES_LOCAL_STORAGE_KEY, JSON.stringify([uri, ...workspaces]));
60
- }
61
-
62
- async removeRecentWorkspace(uri: string): Promise<void> {
63
- const workspaces = await this.getRecentWorkspaces();
64
- if (workspaces.includes(uri)) {
65
- workspaces.splice(workspaces.indexOf(uri), 1);
66
- }
67
- localStorage.setItem(RECENT_WORKSPACES_LOCAL_STORAGE_KEY, JSON.stringify(workspaces));
68
- }
69
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 EclipseSource 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
+ import { inject, injectable } from '@theia/core/shared/inversify';
17
+ import { WorkspaceServer } from '../common/workspace-protocol';
18
+ import { ILogger, isStringArray } from '@theia/core';
19
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
20
+
21
+ export const RECENT_WORKSPACES_LOCAL_STORAGE_KEY = 'workspaces';
22
+
23
+ @injectable()
24
+ export class BrowserOnlyWorkspaceServer implements WorkspaceServer {
25
+
26
+ @inject(ILogger)
27
+ protected logger: ILogger;
28
+
29
+ @inject(FileService)
30
+ protected readonly fileService: FileService;
31
+
32
+ async getRecentWorkspaces(): Promise<string[]> {
33
+ const storedWorkspaces = localStorage.getItem(RECENT_WORKSPACES_LOCAL_STORAGE_KEY);
34
+ if (!storedWorkspaces) {
35
+ return [];
36
+ }
37
+ try {
38
+ const parsedWorkspaces = JSON.parse(storedWorkspaces);
39
+ if (isStringArray(parsedWorkspaces)) {
40
+ return parsedWorkspaces;
41
+ }
42
+ } catch (e) {
43
+ this.logger.error(e);
44
+ return [];
45
+ }
46
+ return [];
47
+ }
48
+
49
+ async getMostRecentlyUsedWorkspace(): Promise<string | undefined> {
50
+ const workspaces = await this.getRecentWorkspaces();
51
+ return workspaces[0];
52
+ }
53
+
54
+ async setMostRecentlyUsedWorkspace(uri: string): Promise<void> {
55
+ const workspaces = await this.getRecentWorkspaces();
56
+ if (workspaces.includes(uri)) {
57
+ workspaces.splice(workspaces.indexOf(uri), 1);
58
+ }
59
+ localStorage.setItem(RECENT_WORKSPACES_LOCAL_STORAGE_KEY, JSON.stringify([uri, ...workspaces]));
60
+ }
61
+
62
+ async removeRecentWorkspace(uri: string): Promise<void> {
63
+ const workspaces = await this.getRecentWorkspaces();
64
+ if (workspaces.includes(uri)) {
65
+ workspaces.splice(workspaces.indexOf(uri), 1);
66
+ }
67
+ localStorage.setItem(RECENT_WORKSPACES_LOCAL_STORAGE_KEY, JSON.stringify(workspaces));
68
+ }
69
+ }
@@ -1,28 +1,28 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 EclipseSource 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 { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
- import { BrowserOnlyWorkspaceServer } from './browser-only-workspace-server';
19
- import { WorkspaceServer } from '../common';
20
-
21
- export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
22
- bind(BrowserOnlyWorkspaceServer).toSelf().inSingletonScope();
23
- if (isBound(WorkspaceServer)) {
24
- rebind(WorkspaceServer).toService(BrowserOnlyWorkspaceServer);
25
- } else {
26
- bind(WorkspaceServer).toService(BrowserOnlyWorkspaceServer);
27
- }
28
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 EclipseSource 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 { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
+ import { BrowserOnlyWorkspaceServer } from './browser-only-workspace-server';
19
+ import { WorkspaceServer } from '../common';
20
+
21
+ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
22
+ bind(BrowserOnlyWorkspaceServer).toSelf().inSingletonScope();
23
+ if (isBound(WorkspaceServer)) {
24
+ rebind(WorkspaceServer).toService(BrowserOnlyWorkspaceServer);
25
+ } else {
26
+ bind(WorkspaceServer).toService(BrowserOnlyWorkspaceServer);
27
+ }
28
+ });
@@ -1,19 +1,19 @@
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
- export * from './workspace-protocol';
18
- export * from './workspace-file-service';
19
- export * from './untitled-workspace-service';
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
+ export * from './workspace-protocol';
18
+ export * from './workspace-file-service';
19
+ export * from './untitled-workspace-service';
@@ -1,29 +1,29 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- import { injectable } from '@theia/core/shared/inversify';
17
- import { WorkspaceServer } from '../workspace-protocol';
18
-
19
- @injectable()
20
- export class MockWorkspaceServer implements WorkspaceServer {
21
-
22
- getRecentWorkspaces(): Promise<string[]> { return Promise.resolve([]); }
23
-
24
- getMostRecentlyUsedWorkspace(): Promise<string | undefined> { return Promise.resolve(''); }
25
-
26
- setMostRecentlyUsedWorkspace(uri: string): Promise<void> { return Promise.resolve(); }
27
-
28
- removeRecentWorkspace(uri: string): Promise<void> { return Promise.resolve(); }
29
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+ import { injectable } from '@theia/core/shared/inversify';
17
+ import { WorkspaceServer } from '../workspace-protocol';
18
+
19
+ @injectable()
20
+ export class MockWorkspaceServer implements WorkspaceServer {
21
+
22
+ getRecentWorkspaces(): Promise<string[]> { return Promise.resolve([]); }
23
+
24
+ getMostRecentlyUsedWorkspace(): Promise<string | undefined> { return Promise.resolve(''); }
25
+
26
+ setMostRecentlyUsedWorkspace(uri: string): Promise<void> { return Promise.resolve(); }
27
+
28
+ removeRecentWorkspace(uri: string): Promise<void> { return Promise.resolve(); }
29
+ }
@@ -1,50 +1,50 @@
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 URI from '@theia/core/lib/common/uri';
18
- import { inject, injectable } from '@theia/core/shared/inversify';
19
- import { MaybePromise } from '@theia/core';
20
- import { WorkspaceFileService } from './workspace-file-service';
21
-
22
- @injectable()
23
- export class UntitledWorkspaceService {
24
-
25
- @inject(WorkspaceFileService)
26
- protected readonly workspaceFileService: WorkspaceFileService;
27
-
28
- isUntitledWorkspace(candidate?: URI): boolean {
29
- return !!candidate && this.workspaceFileService.isWorkspaceFile(candidate) && candidate.path.base.startsWith('Untitled');
30
- }
31
-
32
- async getUntitledWorkspaceUri(configDirUri: URI, isAcceptable: (candidate: URI) => MaybePromise<boolean>, warnOnHits?: () => unknown): Promise<URI> {
33
- const parentDir = configDirUri.resolve('workspaces');
34
- const workspaceExtensions = this.workspaceFileService.getWorkspaceFileExtensions();
35
- const defaultFileExtension = workspaceExtensions[this.workspaceFileService.defaultFileTypeIndex];
36
- let uri;
37
- let attempts = 0;
38
- do {
39
- attempts++;
40
- uri = parentDir.resolve(`Untitled-${Math.round(Math.random() * 1000)}.${defaultFileExtension}`);
41
- if (attempts === 10) {
42
- warnOnHits?.();
43
- }
44
- if (attempts === 50) {
45
- throw new Error('Workspace Service: too many attempts to find unused filename.');
46
- }
47
- } while (!(await isAcceptable(uri)));
48
- return uri;
49
- }
50
- }
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 URI from '@theia/core/lib/common/uri';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { MaybePromise } from '@theia/core';
20
+ import { WorkspaceFileService } from './workspace-file-service';
21
+
22
+ @injectable()
23
+ export class UntitledWorkspaceService {
24
+
25
+ @inject(WorkspaceFileService)
26
+ protected readonly workspaceFileService: WorkspaceFileService;
27
+
28
+ isUntitledWorkspace(candidate?: URI): boolean {
29
+ return !!candidate && this.workspaceFileService.isWorkspaceFile(candidate) && candidate.path.base.startsWith('Untitled');
30
+ }
31
+
32
+ async getUntitledWorkspaceUri(configDirUri: URI, isAcceptable: (candidate: URI) => MaybePromise<boolean>, warnOnHits?: () => unknown): Promise<URI> {
33
+ const parentDir = configDirUri.resolve('workspaces');
34
+ const workspaceExtensions = this.workspaceFileService.getWorkspaceFileExtensions();
35
+ const defaultFileExtension = workspaceExtensions[this.workspaceFileService.defaultFileTypeIndex];
36
+ let uri;
37
+ let attempts = 0;
38
+ do {
39
+ attempts++;
40
+ uri = parentDir.resolve(`Untitled-${Math.round(Math.random() * 1000)}.${defaultFileExtension}`);
41
+ if (attempts === 10) {
42
+ warnOnHits?.();
43
+ }
44
+ if (attempts === 50) {
45
+ throw new Error('Workspace Service: too many attempts to find unused filename.');
46
+ }
47
+ } while (!(await isAcceptable(uri)));
48
+ return uri;
49
+ }
50
+ }
@@ -1,72 +1,72 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 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 { URI } from '@theia/core';
18
- import { injectable } from '@theia/core/shared/inversify';
19
- import { FileStat } from '@theia/filesystem/lib/common/files';
20
-
21
- export interface WorkspaceFileType {
22
- extension: string
23
- name: string
24
- }
25
-
26
- /**
27
- * @deprecated Since 1.39.0. Use `WorkspaceFileService#getWorkspaceFileTypes` instead.
28
- */
29
- export const THEIA_EXT = 'theia-workspace';
30
- /**
31
- * @deprecated Since 1.39.0. Use `WorkspaceFileService#getWorkspaceFileTypes` instead.
32
- */
33
- export const VSCODE_EXT = 'code-workspace';
34
-
35
- @injectable()
36
- export class WorkspaceFileService {
37
-
38
- protected _defaultFileTypeIndex = 0;
39
-
40
- get defaultFileTypeIndex(): number {
41
- return this._defaultFileTypeIndex;
42
- }
43
-
44
- /**
45
- * Check if the file should be considered as a workspace file.
46
- *
47
- * Example: We should not try to read the contents of an .exe file.
48
- */
49
- isWorkspaceFile(candidate: FileStat | URI): boolean {
50
- const uri = FileStat.is(candidate) ? candidate.resource : candidate;
51
- const extensions = this.getWorkspaceFileExtensions(true);
52
- return extensions.includes(uri.path.ext);
53
- }
54
-
55
- getWorkspaceFileTypes(): WorkspaceFileType[] {
56
- return [
57
- {
58
- name: 'Theia',
59
- extension: THEIA_EXT
60
- },
61
- {
62
- name: 'Visual Studio Code',
63
- extension: VSCODE_EXT
64
- }
65
- ];
66
- }
67
-
68
- getWorkspaceFileExtensions(dot?: boolean): string[] {
69
- return this.getWorkspaceFileTypes().map(type => dot ? `.${type.extension}` : type.extension);
70
- }
71
-
72
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 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 { URI } from '@theia/core';
18
+ import { injectable } from '@theia/core/shared/inversify';
19
+ import { FileStat } from '@theia/filesystem/lib/common/files';
20
+
21
+ export interface WorkspaceFileType {
22
+ extension: string
23
+ name: string
24
+ }
25
+
26
+ /**
27
+ * @deprecated Since 1.39.0. Use `WorkspaceFileService#getWorkspaceFileTypes` instead.
28
+ */
29
+ export const THEIA_EXT = 'theia-workspace';
30
+ /**
31
+ * @deprecated Since 1.39.0. Use `WorkspaceFileService#getWorkspaceFileTypes` instead.
32
+ */
33
+ export const VSCODE_EXT = 'code-workspace';
34
+
35
+ @injectable()
36
+ export class WorkspaceFileService {
37
+
38
+ protected _defaultFileTypeIndex = 0;
39
+
40
+ get defaultFileTypeIndex(): number {
41
+ return this._defaultFileTypeIndex;
42
+ }
43
+
44
+ /**
45
+ * Check if the file should be considered as a workspace file.
46
+ *
47
+ * Example: We should not try to read the contents of an .exe file.
48
+ */
49
+ isWorkspaceFile(candidate: FileStat | URI): boolean {
50
+ const uri = FileStat.is(candidate) ? candidate.resource : candidate;
51
+ const extensions = this.getWorkspaceFileExtensions(true);
52
+ return extensions.includes(uri.path.ext);
53
+ }
54
+
55
+ getWorkspaceFileTypes(): WorkspaceFileType[] {
56
+ return [
57
+ {
58
+ name: 'Theia',
59
+ extension: THEIA_EXT
60
+ },
61
+ {
62
+ name: 'Visual Studio Code',
63
+ extension: VSCODE_EXT
64
+ }
65
+ ];
66
+ }
67
+
68
+ getWorkspaceFileExtensions(dot?: boolean): string[] {
69
+ return this.getWorkspaceFileTypes().map(type => dot ? `.${type.extension}` : type.extension);
70
+ }
71
+
72
+ }