@theia/workspace 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.
- package/LICENSE +641 -641
- package/README.md +30 -30
- package/lib/browser/diff-service.d.ts +10 -10
- package/lib/browser/diff-service.js +85 -85
- package/lib/browser/index.d.ts +6 -6
- package/lib/browser/index.js +33 -33
- package/lib/browser/quick-open-workspace.d.ts +25 -25
- package/lib/browser/quick-open-workspace.js +137 -137
- package/lib/browser/untitled-workspace-exit-dialog.d.ts +19 -19
- package/lib/browser/untitled-workspace-exit-dialog.js +74 -74
- package/lib/browser/workspace-breadcrumbs-contribution.d.ts +10 -10
- package/lib/browser/workspace-breadcrumbs-contribution.js +66 -66
- package/lib/browser/workspace-commands.d.ts +117 -117
- package/lib/browser/workspace-commands.js +593 -593
- package/lib/browser/workspace-commands.spec.d.ts +1 -1
- package/lib/browser/workspace-commands.spec.js +127 -127
- package/lib/browser/workspace-compare-handler.d.ts +26 -26
- package/lib/browser/workspace-compare-handler.js +66 -66
- package/lib/browser/workspace-delete-handler.d.ts +75 -75
- package/lib/browser/workspace-delete-handler.js +214 -214
- package/lib/browser/workspace-duplicate-handler.d.ts +30 -30
- package/lib/browser/workspace-duplicate-handler.js +86 -86
- package/lib/browser/workspace-frontend-contribution.d.ts +135 -135
- package/lib/browser/workspace-frontend-contribution.js +568 -568
- package/lib/browser/workspace-frontend-contribution.spec.d.ts +1 -1
- package/lib/browser/workspace-frontend-contribution.spec.js +53 -53
- package/lib/browser/workspace-frontend-module.d.ts +3 -3
- package/lib/browser/workspace-frontend-module.js +88 -88
- package/lib/browser/workspace-input-dialog.d.ts +19 -19
- package/lib/browser/workspace-input-dialog.js +73 -73
- package/lib/browser/workspace-preferences.d.ts +11 -11
- package/lib/browser/workspace-preferences.js +46 -46
- package/lib/browser/workspace-schema-updater.d.ts +32 -32
- package/lib/browser/workspace-schema-updater.js +148 -148
- package/lib/browser/workspace-service.d.ts +182 -182
- package/lib/browser/workspace-service.js +729 -729
- package/lib/browser/workspace-storage-service.d.ts +15 -15
- package/lib/browser/workspace-storage-service.js +80 -80
- package/lib/browser/workspace-trust-preferences.d.ts +21 -21
- package/lib/browser/workspace-trust-preferences.js +65 -65
- package/lib/browser/workspace-trust-service.d.ts +26 -26
- package/lib/browser/workspace-trust-service.js +149 -149
- package/lib/browser/workspace-uri-contribution.d.ts +20 -20
- package/lib/browser/workspace-uri-contribution.js +113 -113
- package/lib/browser/workspace-uri-contribution.spec.d.ts +1 -1
- package/lib/browser/workspace-uri-contribution.spec.js +169 -169
- package/lib/browser/workspace-user-working-directory-provider.d.ts +12 -12
- package/lib/browser/workspace-user-working-directory-provider.js +62 -62
- package/lib/browser/workspace-utils.d.ts +15 -15
- package/lib/browser/workspace-utils.js +54 -54
- package/lib/browser/workspace-variable-contribution.d.ts +23 -23
- package/lib/browser/workspace-variable-contribution.js +237 -237
- package/lib/browser/workspace-window-title-updater.d.ts +7 -7
- package/lib/browser/workspace-window-title-updater.js +57 -57
- package/lib/common/index.d.ts +2 -2
- package/lib/common/index.js +29 -29
- package/lib/common/test/mock-workspace-server.d.ts +7 -7
- package/lib/common/test/mock-workspace-server.js +35 -35
- package/lib/common/utils.d.ts +21 -21
- package/lib/common/utils.js +73 -73
- package/lib/common/workspace-protocol.d.ts +26 -26
- package/lib/common/workspace-protocol.js +23 -23
- package/lib/node/default-workspace-server.d.ts +64 -64
- package/lib/node/default-workspace-server.js +248 -248
- package/lib/node/default-workspace-server.spec.d.ts +1 -1
- package/lib/node/default-workspace-server.spec.js +84 -84
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +29 -29
- package/lib/node/workspace-backend-module.d.ts +3 -3
- package/lib/node/workspace-backend-module.js +32 -32
- package/package.json +6 -6
- package/src/browser/diff-service.ts +62 -62
- package/src/browser/index.ts +22 -22
- package/src/browser/quick-open-workspace.ts +112 -112
- package/src/browser/untitled-workspace-exit-dialog.ts +70 -70
- package/src/browser/workspace-breadcrumbs-contribution.ts +56 -56
- package/src/browser/workspace-commands.spec.ts +153 -153
- package/src/browser/workspace-commands.ts +586 -586
- package/src/browser/workspace-compare-handler.ts +56 -56
- package/src/browser/workspace-delete-handler.ts +212 -212
- package/src/browser/workspace-duplicate-handler.ts +75 -75
- package/src/browser/workspace-frontend-contribution.spec.ts +63 -63
- package/src/browser/workspace-frontend-contribution.ts +558 -558
- package/src/browser/workspace-frontend-module.ts +115 -115
- package/src/browser/workspace-input-dialog.ts +60 -60
- package/src/browser/workspace-preferences.ts +58 -58
- package/src/browser/workspace-schema-updater.ts +148 -148
- package/src/browser/workspace-service.ts +772 -772
- package/src/browser/workspace-storage-service.ts +67 -67
- package/src/browser/workspace-trust-preferences.ts +76 -76
- package/src/browser/workspace-trust-service.ts +143 -143
- package/src/browser/workspace-uri-contribution.spec.ts +191 -191
- package/src/browser/workspace-uri-contribution.ts +97 -97
- package/src/browser/workspace-user-working-directory-provider.ts +48 -48
- package/src/browser/workspace-utils.ts +45 -45
- package/src/browser/workspace-variable-contribution.ts +222 -222
- package/src/browser/workspace-window-title-updater.ts +45 -45
- package/src/common/index.ts +18 -18
- package/src/common/test/mock-workspace-server.ts +29 -29
- package/src/common/utils.ts +69 -69
- package/src/common/workspace-protocol.ts +47 -47
- package/src/node/default-workspace-server.spec.ts +99 -99
- package/src/node/default-workspace-server.ts +242 -242
- package/src/node/index.ts +18 -18
- package/src/node/workspace-backend-module.ts +37 -37
|
@@ -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 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 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
|
+
}
|
package/src/common/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
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 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
export * from './workspace-protocol';
|
|
18
|
-
export * from './utils';
|
|
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 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
export * from './workspace-protocol';
|
|
18
|
+
export * from './utils';
|
|
@@ -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 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 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
|
+
}
|
package/src/common/utils.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
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 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
// TODO get rid of util files, replace with methods in a responsible class
|
|
18
|
-
|
|
19
|
-
import URI from '@theia/core/lib/common/uri';
|
|
20
|
-
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
21
|
-
import { injectable } from '@theia/core/shared/inversify';
|
|
22
|
-
import { FileStat } from '@theia/filesystem/lib/common/files';
|
|
23
|
-
import { MaybePromise } from '@theia/core';
|
|
24
|
-
|
|
25
|
-
export const THEIA_EXT = 'theia-workspace';
|
|
26
|
-
export const VSCODE_EXT = 'code-workspace';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated since 1.4.0 - because of https://github.com/eclipse-theia/theia/tree/master/doc/coding-guidelines.md#di-function-export,
|
|
30
|
-
* use `WorkspaceService.getUntitledWorkspace` instead
|
|
31
|
-
*/
|
|
32
|
-
export async function getTemporaryWorkspaceFileUri(envVariableServer: EnvVariablesServer): Promise<URI> {
|
|
33
|
-
const configDirUri = await envVariableServer.getConfigDirUri();
|
|
34
|
-
return new URI(configDirUri).resolve(`Untitled.${THEIA_EXT}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@injectable()
|
|
38
|
-
export class CommonWorkspaceUtils {
|
|
39
|
-
/**
|
|
40
|
-
* Check if the file should be considered as a workspace file.
|
|
41
|
-
*
|
|
42
|
-
* Example: We should not try to read the contents of an .exe file.
|
|
43
|
-
*/
|
|
44
|
-
isWorkspaceFile(candidate: FileStat | URI): boolean {
|
|
45
|
-
const uri = FileStat.is(candidate) ? candidate.resource : candidate;
|
|
46
|
-
return uri.path.ext === `.${THEIA_EXT}` || uri.path.ext === `.${VSCODE_EXT}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
isUntitledWorkspace(candidate?: URI): boolean {
|
|
50
|
-
return !!candidate && this.isWorkspaceFile(candidate) && candidate.path.base.startsWith('Untitled');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async getUntitledWorkspaceUri(configDirUri: URI, isAcceptable: (candidate: URI) => MaybePromise<boolean>, warnOnHits?: () => unknown): Promise<URI> {
|
|
54
|
-
const parentDir = configDirUri.resolve('workspaces');
|
|
55
|
-
let uri;
|
|
56
|
-
let attempts = 0;
|
|
57
|
-
do {
|
|
58
|
-
attempts++;
|
|
59
|
-
uri = parentDir.resolve(`Untitled-${Math.round(Math.random() * 1000)}.${THEIA_EXT}`);
|
|
60
|
-
if (attempts === 10) {
|
|
61
|
-
warnOnHits?.();
|
|
62
|
-
}
|
|
63
|
-
if (attempts === 50) {
|
|
64
|
-
throw new Error('Workspace Service: too many attempts to find unused filename.');
|
|
65
|
-
}
|
|
66
|
-
} while (!(await isAcceptable(uri)));
|
|
67
|
-
return uri;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
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 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
// TODO get rid of util files, replace with methods in a responsible class
|
|
18
|
+
|
|
19
|
+
import URI from '@theia/core/lib/common/uri';
|
|
20
|
+
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
21
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
22
|
+
import { FileStat } from '@theia/filesystem/lib/common/files';
|
|
23
|
+
import { MaybePromise } from '@theia/core';
|
|
24
|
+
|
|
25
|
+
export const THEIA_EXT = 'theia-workspace';
|
|
26
|
+
export const VSCODE_EXT = 'code-workspace';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated since 1.4.0 - because of https://github.com/eclipse-theia/theia/tree/master/doc/coding-guidelines.md#di-function-export,
|
|
30
|
+
* use `WorkspaceService.getUntitledWorkspace` instead
|
|
31
|
+
*/
|
|
32
|
+
export async function getTemporaryWorkspaceFileUri(envVariableServer: EnvVariablesServer): Promise<URI> {
|
|
33
|
+
const configDirUri = await envVariableServer.getConfigDirUri();
|
|
34
|
+
return new URI(configDirUri).resolve(`Untitled.${THEIA_EXT}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@injectable()
|
|
38
|
+
export class CommonWorkspaceUtils {
|
|
39
|
+
/**
|
|
40
|
+
* Check if the file should be considered as a workspace file.
|
|
41
|
+
*
|
|
42
|
+
* Example: We should not try to read the contents of an .exe file.
|
|
43
|
+
*/
|
|
44
|
+
isWorkspaceFile(candidate: FileStat | URI): boolean {
|
|
45
|
+
const uri = FileStat.is(candidate) ? candidate.resource : candidate;
|
|
46
|
+
return uri.path.ext === `.${THEIA_EXT}` || uri.path.ext === `.${VSCODE_EXT}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isUntitledWorkspace(candidate?: URI): boolean {
|
|
50
|
+
return !!candidate && this.isWorkspaceFile(candidate) && candidate.path.base.startsWith('Untitled');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async getUntitledWorkspaceUri(configDirUri: URI, isAcceptable: (candidate: URI) => MaybePromise<boolean>, warnOnHits?: () => unknown): Promise<URI> {
|
|
54
|
+
const parentDir = configDirUri.resolve('workspaces');
|
|
55
|
+
let uri;
|
|
56
|
+
let attempts = 0;
|
|
57
|
+
do {
|
|
58
|
+
attempts++;
|
|
59
|
+
uri = parentDir.resolve(`Untitled-${Math.round(Math.random() * 1000)}.${THEIA_EXT}`);
|
|
60
|
+
if (attempts === 10) {
|
|
61
|
+
warnOnHits?.();
|
|
62
|
+
}
|
|
63
|
+
if (attempts === 50) {
|
|
64
|
+
throw new Error('Workspace Service: too many attempts to find unused filename.');
|
|
65
|
+
}
|
|
66
|
+
} while (!(await isAcceptable(uri)));
|
|
67
|
+
return uri;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,47 +1,47 @@
|
|
|
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 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
export const workspacePath = '/services/workspace';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The JSON-RPC workspace interface.
|
|
21
|
-
*/
|
|
22
|
-
export const WorkspaceServer = Symbol('WorkspaceServer');
|
|
23
|
-
export interface WorkspaceServer {
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Returns with a promise that resolves to the most recently used workspace folder URI as a string.
|
|
27
|
-
* Resolves to `undefined` if the workspace folder is not yet set.
|
|
28
|
-
*/
|
|
29
|
-
getMostRecentlyUsedWorkspace(): Promise<string | undefined>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Sets the desired string representation of the URI as the most recently used workspace folder.
|
|
33
|
-
*/
|
|
34
|
-
setMostRecentlyUsedWorkspace(uri: string): Promise<void>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Removes a workspace from the list of recently opened workspaces.
|
|
38
|
-
*
|
|
39
|
-
* @param uri the workspace uri.
|
|
40
|
-
*/
|
|
41
|
-
removeRecentWorkspace(uri: string): Promise<void>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Returns list of recently opened workspaces as an array.
|
|
45
|
-
*/
|
|
46
|
-
getRecentWorkspaces(): Promise<string[]>
|
|
47
|
-
}
|
|
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 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
export const workspacePath = '/services/workspace';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The JSON-RPC workspace interface.
|
|
21
|
+
*/
|
|
22
|
+
export const WorkspaceServer = Symbol('WorkspaceServer');
|
|
23
|
+
export interface WorkspaceServer {
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns with a promise that resolves to the most recently used workspace folder URI as a string.
|
|
27
|
+
* Resolves to `undefined` if the workspace folder is not yet set.
|
|
28
|
+
*/
|
|
29
|
+
getMostRecentlyUsedWorkspace(): Promise<string | undefined>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sets the desired string representation of the URI as the most recently used workspace folder.
|
|
33
|
+
*/
|
|
34
|
+
setMostRecentlyUsedWorkspace(uri: string): Promise<void>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Removes a workspace from the list of recently opened workspaces.
|
|
38
|
+
*
|
|
39
|
+
* @param uri the workspace uri.
|
|
40
|
+
*/
|
|
41
|
+
removeRecentWorkspace(uri: string): Promise<void>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns list of recently opened workspaces as an array.
|
|
45
|
+
*/
|
|
46
|
+
getRecentWorkspaces(): Promise<string[]>
|
|
47
|
+
}
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2022 Alexander Flammer 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 { Container } from '@theia/core/shared/inversify';
|
|
18
|
-
import { MockEnvVariablesServerImpl } from '@theia/core/lib/browser/test/mock-env-variables-server';
|
|
19
|
-
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
20
|
-
import URI from '@theia/core/lib/common/uri';
|
|
21
|
-
import { FileUri } from '@theia/core/lib/node';
|
|
22
|
-
import { CommonWorkspaceUtils } from '../common';
|
|
23
|
-
import { DefaultWorkspaceServer, WorkspaceCliContribution } from './default-workspace-server';
|
|
24
|
-
import { expect } from 'chai';
|
|
25
|
-
import * as temp from 'temp';
|
|
26
|
-
import * as fs from 'fs';
|
|
27
|
-
|
|
28
|
-
describe('DefaultWorkspaceServer', function (): void {
|
|
29
|
-
|
|
30
|
-
describe('getRecentWorkspaces()', async () => {
|
|
31
|
-
let workspaceServer: DefaultWorkspaceServer;
|
|
32
|
-
let tmpConfigDir: URI;
|
|
33
|
-
let recentWorkspaceFile: string;
|
|
34
|
-
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
// create a temporary directory
|
|
37
|
-
const tempDirPath = temp.track().mkdirSync();
|
|
38
|
-
tmpConfigDir = FileUri.create(fs.realpathSync(tempDirPath));
|
|
39
|
-
recentWorkspaceFile = FileUri.fsPath(tmpConfigDir.resolve('recentworkspace.json'));
|
|
40
|
-
|
|
41
|
-
// create a container with the necessary bindings for the DefaultWorkspaceServer
|
|
42
|
-
const container = new Container();
|
|
43
|
-
container.bind(WorkspaceCliContribution).toSelf().inSingletonScope();
|
|
44
|
-
container.bind(CommonWorkspaceUtils).toSelf().inSingletonScope();
|
|
45
|
-
container.bind(DefaultWorkspaceServer).toSelf().inSingletonScope();
|
|
46
|
-
container.bind(EnvVariablesServer).toConstantValue(new MockEnvVariablesServerImpl(tmpConfigDir));
|
|
47
|
-
|
|
48
|
-
workspaceServer = container.get(DefaultWorkspaceServer);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should return empty list of workspaces if no recent workspaces file is existing', async function (): Promise<void> {
|
|
52
|
-
const recent = await workspaceServer.getRecentWorkspaces();
|
|
53
|
-
expect(recent).to.be.empty;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should not return non-existing workspaces from recent workspaces file', async function (): Promise<void> {
|
|
57
|
-
fs.writeFileSync(recentWorkspaceFile, JSON.stringify({
|
|
58
|
-
recentRoots: [
|
|
59
|
-
tmpConfigDir.resolve('somethingNotExisting').toString(),
|
|
60
|
-
tmpConfigDir.resolve('somethingElseNotExisting').toString()
|
|
61
|
-
]
|
|
62
|
-
}));
|
|
63
|
-
|
|
64
|
-
const recent = await workspaceServer.getRecentWorkspaces();
|
|
65
|
-
|
|
66
|
-
expect(recent).to.be.empty;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should return only existing workspaces from recent workspaces file', async function (): Promise<void> {
|
|
70
|
-
fs.writeFileSync(recentWorkspaceFile, JSON.stringify({
|
|
71
|
-
recentRoots: [
|
|
72
|
-
tmpConfigDir.toString(),
|
|
73
|
-
tmpConfigDir.resolve('somethingNotExisting').toString()
|
|
74
|
-
]
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
const recent = await workspaceServer.getRecentWorkspaces();
|
|
78
|
-
|
|
79
|
-
expect(recent).to.have.members([tmpConfigDir.toString()]);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should ignore non-string array entries but return remaining existing file paths', async function (): Promise<void> {
|
|
83
|
-
// previously caused: 'TypeError: Cannot read property 'fsPath' of undefined', see issue #10250
|
|
84
|
-
fs.writeFileSync(recentWorkspaceFile, JSON.stringify({
|
|
85
|
-
recentRoots: [
|
|
86
|
-
[tmpConfigDir.toString()],
|
|
87
|
-
{},
|
|
88
|
-
12345678,
|
|
89
|
-
undefined,
|
|
90
|
-
tmpConfigDir.toString(),
|
|
91
|
-
]
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
const recent = await workspaceServer.getRecentWorkspaces();
|
|
95
|
-
|
|
96
|
-
expect(recent).to.have.members([tmpConfigDir.toString()]);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 Alexander Flammer 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 { Container } from '@theia/core/shared/inversify';
|
|
18
|
+
import { MockEnvVariablesServerImpl } from '@theia/core/lib/browser/test/mock-env-variables-server';
|
|
19
|
+
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
20
|
+
import URI from '@theia/core/lib/common/uri';
|
|
21
|
+
import { FileUri } from '@theia/core/lib/node';
|
|
22
|
+
import { CommonWorkspaceUtils } from '../common';
|
|
23
|
+
import { DefaultWorkspaceServer, WorkspaceCliContribution } from './default-workspace-server';
|
|
24
|
+
import { expect } from 'chai';
|
|
25
|
+
import * as temp from 'temp';
|
|
26
|
+
import * as fs from 'fs';
|
|
27
|
+
|
|
28
|
+
describe('DefaultWorkspaceServer', function (): void {
|
|
29
|
+
|
|
30
|
+
describe('getRecentWorkspaces()', async () => {
|
|
31
|
+
let workspaceServer: DefaultWorkspaceServer;
|
|
32
|
+
let tmpConfigDir: URI;
|
|
33
|
+
let recentWorkspaceFile: string;
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
// create a temporary directory
|
|
37
|
+
const tempDirPath = temp.track().mkdirSync();
|
|
38
|
+
tmpConfigDir = FileUri.create(fs.realpathSync(tempDirPath));
|
|
39
|
+
recentWorkspaceFile = FileUri.fsPath(tmpConfigDir.resolve('recentworkspace.json'));
|
|
40
|
+
|
|
41
|
+
// create a container with the necessary bindings for the DefaultWorkspaceServer
|
|
42
|
+
const container = new Container();
|
|
43
|
+
container.bind(WorkspaceCliContribution).toSelf().inSingletonScope();
|
|
44
|
+
container.bind(CommonWorkspaceUtils).toSelf().inSingletonScope();
|
|
45
|
+
container.bind(DefaultWorkspaceServer).toSelf().inSingletonScope();
|
|
46
|
+
container.bind(EnvVariablesServer).toConstantValue(new MockEnvVariablesServerImpl(tmpConfigDir));
|
|
47
|
+
|
|
48
|
+
workspaceServer = container.get(DefaultWorkspaceServer);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should return empty list of workspaces if no recent workspaces file is existing', async function (): Promise<void> {
|
|
52
|
+
const recent = await workspaceServer.getRecentWorkspaces();
|
|
53
|
+
expect(recent).to.be.empty;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should not return non-existing workspaces from recent workspaces file', async function (): Promise<void> {
|
|
57
|
+
fs.writeFileSync(recentWorkspaceFile, JSON.stringify({
|
|
58
|
+
recentRoots: [
|
|
59
|
+
tmpConfigDir.resolve('somethingNotExisting').toString(),
|
|
60
|
+
tmpConfigDir.resolve('somethingElseNotExisting').toString()
|
|
61
|
+
]
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const recent = await workspaceServer.getRecentWorkspaces();
|
|
65
|
+
|
|
66
|
+
expect(recent).to.be.empty;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should return only existing workspaces from recent workspaces file', async function (): Promise<void> {
|
|
70
|
+
fs.writeFileSync(recentWorkspaceFile, JSON.stringify({
|
|
71
|
+
recentRoots: [
|
|
72
|
+
tmpConfigDir.toString(),
|
|
73
|
+
tmpConfigDir.resolve('somethingNotExisting').toString()
|
|
74
|
+
]
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
const recent = await workspaceServer.getRecentWorkspaces();
|
|
78
|
+
|
|
79
|
+
expect(recent).to.have.members([tmpConfigDir.toString()]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should ignore non-string array entries but return remaining existing file paths', async function (): Promise<void> {
|
|
83
|
+
// previously caused: 'TypeError: Cannot read property 'fsPath' of undefined', see issue #10250
|
|
84
|
+
fs.writeFileSync(recentWorkspaceFile, JSON.stringify({
|
|
85
|
+
recentRoots: [
|
|
86
|
+
[tmpConfigDir.toString()],
|
|
87
|
+
{},
|
|
88
|
+
12345678,
|
|
89
|
+
undefined,
|
|
90
|
+
tmpConfigDir.toString(),
|
|
91
|
+
]
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
const recent = await workspaceServer.getRecentWorkspaces();
|
|
95
|
+
|
|
96
|
+
expect(recent).to.have.members([tmpConfigDir.toString()]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|