@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.
- package/README.md +30 -30
- package/lib/browser/canonical-uri-service.d.ts +11 -11
- package/lib/browser/canonical-uri-service.js +59 -59
- package/lib/browser/diff-service.d.ts +10 -10
- package/lib/browser/diff-service.js +85 -85
- package/lib/browser/index.d.ts +7 -7
- package/lib/browser/index.js +34 -34
- 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 +601 -601
- 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 +110 -110
- package/lib/browser/workspace-frontend-contribution.js +546 -546
- package/lib/browser/workspace-frontend-contribution.js.map +1 -1
- package/lib/browser/workspace-frontend-module.d.ts +3 -3
- package/lib/browser/workspace-frontend-module.js +91 -91
- package/lib/browser/workspace-input-dialog.d.ts +19 -19
- package/lib/browser/workspace-input-dialog.js +74 -74
- 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 +34 -34
- package/lib/browser/workspace-schema-updater.js +153 -153
- package/lib/browser/workspace-service.d.ts +184 -184
- package/lib/browser/workspace-service.js +739 -739
- 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 +27 -27
- package/lib/browser/workspace-trust-service.js +152 -152
- 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/browser-only/browser-only-workspace-server.d.ts +13 -0
- package/lib/browser-only/browser-only-workspace-server.d.ts.map +1 -0
- package/lib/browser-only/browser-only-workspace-server.js +81 -0
- package/lib/browser-only/browser-only-workspace-server.js.map +1 -0
- package/lib/browser-only/workspace-frontend-only-module.d.ts +4 -0
- package/lib/browser-only/workspace-frontend-only-module.d.ts.map +1 -0
- package/lib/browser-only/workspace-frontend-only-module.js +30 -0
- package/lib/browser-only/workspace-frontend-only-module.js.map +1 -0
- package/lib/common/index.d.ts +3 -3
- package/lib/common/index.js +30 -30
- package/lib/common/test/mock-workspace-server.d.ts +7 -7
- package/lib/common/test/mock-workspace-server.js +35 -35
- package/lib/common/untitled-workspace-service.d.ts +8 -8
- package/lib/common/untitled-workspace-service.js +60 -60
- package/lib/common/workspace-file-service.d.ts +26 -26
- package/lib/common/workspace-file-service.js +71 -71
- 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 +65 -65
- 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 +85 -85
- 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 +33 -33
- package/package.json +9 -6
- package/src/browser/canonical-uri-service.ts +57 -57
- package/src/browser/diff-service.ts +62 -62
- package/src/browser/index.ts +23 -23
- 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 +588 -588
- 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.ts +537 -537
- package/src/browser/workspace-frontend-module.ts +118 -118
- package/src/browser/workspace-input-dialog.ts +61 -61
- package/src/browser/workspace-preferences.ts +58 -58
- package/src/browser/workspace-schema-updater.ts +150 -150
- package/src/browser/workspace-service.ts +780 -780
- 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 +147 -147
- 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 +49 -49
- 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/browser-only/browser-only-workspace-server.ts +69 -0
- package/src/browser-only/workspace-frontend-only-module.ts +28 -0
- package/src/common/index.ts +19 -19
- package/src/common/test/mock-workspace-server.ts +29 -29
- package/src/common/untitled-workspace-service.ts +50 -50
- package/src/common/workspace-file-service.ts +72 -72
- package/src/common/workspace-protocol.ts +47 -47
- package/src/node/default-workspace-server.spec.ts +100 -100
- package/src/node/default-workspace-server.ts +244 -244
- package/src/node/index.ts +18 -18
- package/src/node/workspace-backend-module.ts +38 -38
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2022 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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import { UserWorkingDirectoryProvider } from '@theia/core/lib/browser/user-working-directory-provider';
|
|
19
|
-
import URI from '@theia/core/lib/common/uri';
|
|
20
|
-
import { WorkspaceService } from './workspace-service';
|
|
21
|
-
import { MaybePromise } from '@theia/core';
|
|
22
|
-
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
23
|
-
|
|
24
|
-
@injectable()
|
|
25
|
-
export class WorkspaceUserWorkingDirectoryProvider extends UserWorkingDirectoryProvider {
|
|
26
|
-
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
|
|
27
|
-
@inject(FileService) protected readonly fileService: FileService;
|
|
28
|
-
|
|
29
|
-
override async getUserWorkingDir(): Promise<URI> {
|
|
30
|
-
return await this.getFromSelection()
|
|
31
|
-
?? await this.getFromLastOpenResource()
|
|
32
|
-
?? await this.getFromWorkspace()
|
|
33
|
-
?? this.getFromUserHome();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
protected getFromWorkspace(): MaybePromise<URI | undefined> {
|
|
37
|
-
return this.workspaceService.tryGetRoots()[0]?.resource;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected override async ensureIsDirectory(uri?: URI): Promise<URI | undefined> {
|
|
41
|
-
if (uri) {
|
|
42
|
-
const asFile = uri.withScheme('file');
|
|
43
|
-
const stat = await this.fileService.resolve(asFile)
|
|
44
|
-
.catch(() => this.fileService.resolve(asFile.parent))
|
|
45
|
-
.catch(() => undefined);
|
|
46
|
-
return stat?.isDirectory ? stat.resource : stat?.resource.parent;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { UserWorkingDirectoryProvider } from '@theia/core/lib/browser/user-working-directory-provider';
|
|
19
|
+
import URI from '@theia/core/lib/common/uri';
|
|
20
|
+
import { WorkspaceService } from './workspace-service';
|
|
21
|
+
import { MaybePromise } from '@theia/core';
|
|
22
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
23
|
+
|
|
24
|
+
@injectable()
|
|
25
|
+
export class WorkspaceUserWorkingDirectoryProvider extends UserWorkingDirectoryProvider {
|
|
26
|
+
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
|
|
27
|
+
@inject(FileService) protected readonly fileService: FileService;
|
|
28
|
+
|
|
29
|
+
override async getUserWorkingDir(): Promise<URI> {
|
|
30
|
+
return await this.getFromSelection()
|
|
31
|
+
?? await this.getFromLastOpenResource()
|
|
32
|
+
?? await this.getFromWorkspace()
|
|
33
|
+
?? this.getFromUserHome();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected getFromWorkspace(): MaybePromise<URI | undefined> {
|
|
37
|
+
return this.workspaceService.tryGetRoots()[0]?.resource;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected override async ensureIsDirectory(uri?: URI): Promise<URI | undefined> {
|
|
41
|
+
if (uri) {
|
|
42
|
+
const asFile = uri.withScheme('file');
|
|
43
|
+
const stat = await this.fileService.resolve(asFile)
|
|
44
|
+
.catch(() => this.fileService.resolve(asFile.parent))
|
|
45
|
+
.catch(() => undefined);
|
|
46
|
+
return stat?.isDirectory ? stat.resource : stat?.resource.parent;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2018 Ericsson and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
|
|
18
|
-
// TODO get rid of util files, replace with methods in a responsible class
|
|
19
|
-
|
|
20
|
-
import URI from '@theia/core/lib/common/uri';
|
|
21
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
22
|
-
import { WorkspaceService } from './workspace-service';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Collection of workspace utility functions
|
|
26
|
-
* @class
|
|
27
|
-
*/
|
|
28
|
-
@injectable()
|
|
29
|
-
export class WorkspaceUtils {
|
|
30
|
-
|
|
31
|
-
@inject(WorkspaceService)
|
|
32
|
-
protected readonly workspaceService: WorkspaceService;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Determine if root directory exists
|
|
36
|
-
* for a given array of URIs
|
|
37
|
-
* @param uris
|
|
38
|
-
*/
|
|
39
|
-
containsRootDirectory(uris: URI[]): boolean {
|
|
40
|
-
// obtain all roots URIs for a given workspace
|
|
41
|
-
const rootUris = this.workspaceService.tryGetRoots().map(root => root.resource);
|
|
42
|
-
// return true if at least a single URI is a root directory
|
|
43
|
-
return rootUris.some(rootUri => uris.some(uri => uri.isEqualOrParent(rootUri)));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2018 Ericsson and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
|
|
18
|
+
// TODO get rid of util files, replace with methods in a responsible class
|
|
19
|
+
|
|
20
|
+
import URI from '@theia/core/lib/common/uri';
|
|
21
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
22
|
+
import { WorkspaceService } from './workspace-service';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Collection of workspace utility functions
|
|
26
|
+
* @class
|
|
27
|
+
*/
|
|
28
|
+
@injectable()
|
|
29
|
+
export class WorkspaceUtils {
|
|
30
|
+
|
|
31
|
+
@inject(WorkspaceService)
|
|
32
|
+
protected readonly workspaceService: WorkspaceService;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Determine if root directory exists
|
|
36
|
+
* for a given array of URIs
|
|
37
|
+
* @param uris
|
|
38
|
+
*/
|
|
39
|
+
containsRootDirectory(uris: URI[]): boolean {
|
|
40
|
+
// obtain all roots URIs for a given workspace
|
|
41
|
+
const rootUris = this.workspaceService.tryGetRoots().map(root => root.resource);
|
|
42
|
+
// return true if at least a single URI is a root directory
|
|
43
|
+
return rootUris.some(rootUri => uris.some(uri => uri.isEqualOrParent(rootUri)));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,222 +1,222 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
-
import URI from '@theia/core/lib/common/uri';
|
|
19
|
-
import { Path } from '@theia/core/lib/common/path';
|
|
20
|
-
import { ApplicationShell, NavigatableWidget, WidgetManager } from '@theia/core/lib/browser';
|
|
21
|
-
import { VariableContribution, VariableRegistry, Variable } from '@theia/variable-resolver/lib/browser';
|
|
22
|
-
import { WorkspaceService } from './workspace-service';
|
|
23
|
-
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
24
|
-
|
|
25
|
-
@injectable()
|
|
26
|
-
export class WorkspaceVariableContribution implements VariableContribution {
|
|
27
|
-
|
|
28
|
-
@inject(WorkspaceService)
|
|
29
|
-
protected readonly workspaceService: WorkspaceService;
|
|
30
|
-
@inject(ApplicationShell)
|
|
31
|
-
protected readonly shell: ApplicationShell;
|
|
32
|
-
@inject(FileService)
|
|
33
|
-
protected readonly fileService: FileService;
|
|
34
|
-
@inject(WidgetManager)
|
|
35
|
-
protected readonly widgetManager: WidgetManager;
|
|
36
|
-
|
|
37
|
-
protected currentWidget: NavigatableWidget | undefined;
|
|
38
|
-
|
|
39
|
-
@postConstruct()
|
|
40
|
-
protected init(): void {
|
|
41
|
-
this.shell.onDidChangeCurrentWidget(() => this.updateCurrentWidget());
|
|
42
|
-
this.widgetManager.onDidCreateWidget(({ widget }) => {
|
|
43
|
-
if (NavigatableWidget.is(widget)) {
|
|
44
|
-
widget.onDidChangeVisibility(() => {
|
|
45
|
-
if (widget.isVisible) {
|
|
46
|
-
this.addRecentlyVisible(widget);
|
|
47
|
-
} else {
|
|
48
|
-
this.removeRecentlyVisible(widget);
|
|
49
|
-
}
|
|
50
|
-
this.updateCurrentWidget();
|
|
51
|
-
});
|
|
52
|
-
widget.onDidDispose(() => {
|
|
53
|
-
this.removeRecentlyVisible(widget);
|
|
54
|
-
this.updateCurrentWidget();
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
for (const widget of this.shell.widgets) {
|
|
59
|
-
if (NavigatableWidget.is(widget) && widget.isVisible) {
|
|
60
|
-
this.addRecentlyVisible(widget);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
this.updateCurrentWidget();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
protected readonly recentlyVisibleIds: string[] = [];
|
|
67
|
-
protected get recentlyVisible(): NavigatableWidget | undefined {
|
|
68
|
-
const id = this.recentlyVisibleIds[0];
|
|
69
|
-
const widget = id && this.shell.getWidgetById(id) || undefined;
|
|
70
|
-
if (NavigatableWidget.is(widget)) {
|
|
71
|
-
return widget;
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
protected addRecentlyVisible(widget: NavigatableWidget): void {
|
|
76
|
-
this.removeRecentlyVisible(widget);
|
|
77
|
-
this.recentlyVisibleIds.unshift(widget.id);
|
|
78
|
-
}
|
|
79
|
-
protected removeRecentlyVisible(widget: NavigatableWidget): void {
|
|
80
|
-
const index = this.recentlyVisibleIds.indexOf(widget.id);
|
|
81
|
-
if (index !== -1) {
|
|
82
|
-
this.recentlyVisibleIds.splice(index, 1);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
protected updateCurrentWidget(): void {
|
|
87
|
-
const { currentWidget } = this.shell;
|
|
88
|
-
if (NavigatableWidget.is(currentWidget)) {
|
|
89
|
-
this.currentWidget = currentWidget;
|
|
90
|
-
} else if (!this.currentWidget || !this.currentWidget.isVisible) {
|
|
91
|
-
this.currentWidget = this.recentlyVisible;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
registerVariables(variables: VariableRegistry): void {
|
|
96
|
-
this.registerWorkspaceRootVariables(variables);
|
|
97
|
-
|
|
98
|
-
variables.registerVariable({
|
|
99
|
-
name: 'file',
|
|
100
|
-
description: 'The path of the currently opened file',
|
|
101
|
-
resolve: () => {
|
|
102
|
-
const uri = this.getResourceUri();
|
|
103
|
-
return uri && this.fileService.fsPath(uri);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
variables.registerVariable({
|
|
107
|
-
name: 'fileBasename',
|
|
108
|
-
description: 'The basename of the currently opened file',
|
|
109
|
-
resolve: () => {
|
|
110
|
-
const uri = this.getResourceUri();
|
|
111
|
-
return uri && uri.path.base;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
variables.registerVariable({
|
|
115
|
-
name: 'fileBasenameNoExtension',
|
|
116
|
-
description: "The currently opened file's name without extension",
|
|
117
|
-
resolve: () => {
|
|
118
|
-
const uri = this.getResourceUri();
|
|
119
|
-
return uri && uri.path.name;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
variables.registerVariable({
|
|
123
|
-
name: 'fileDirname',
|
|
124
|
-
description: "The name of the currently opened file's directory",
|
|
125
|
-
resolve: () => {
|
|
126
|
-
const uri = this.getResourceUri();
|
|
127
|
-
return uri && uri.path.dir.toString();
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
variables.registerVariable({
|
|
131
|
-
name: 'fileExtname',
|
|
132
|
-
description: 'The extension of the currently opened file',
|
|
133
|
-
resolve: () => {
|
|
134
|
-
const uri = this.getResourceUri();
|
|
135
|
-
return uri && uri.path.ext;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
protected registerWorkspaceRootVariables(variables: VariableRegistry): void {
|
|
141
|
-
const scoped = (variable: Variable): Variable => ({
|
|
142
|
-
name: variable.name,
|
|
143
|
-
description: variable.description,
|
|
144
|
-
resolve: (context, workspaceRootName) => {
|
|
145
|
-
const workspaceRoot = workspaceRootName && this.workspaceService.tryGetRoots().find(r => r.resource.path.name === workspaceRootName);
|
|
146
|
-
return variable.resolve(workspaceRoot ? workspaceRoot.resource : context);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
variables.registerVariable(scoped({
|
|
150
|
-
name: 'workspaceRoot',
|
|
151
|
-
description: 'The path of the workspace root folder',
|
|
152
|
-
resolve: (context?: URI) => {
|
|
153
|
-
const uri = this.getWorkspaceRootUri(context);
|
|
154
|
-
return uri && this.fileService.fsPath(uri);
|
|
155
|
-
}
|
|
156
|
-
}));
|
|
157
|
-
variables.registerVariable(scoped({
|
|
158
|
-
name: 'workspaceFolder',
|
|
159
|
-
description: 'The path of the workspace root folder',
|
|
160
|
-
resolve: (context?: URI) => {
|
|
161
|
-
const uri = this.getWorkspaceRootUri(context);
|
|
162
|
-
return uri && this.fileService.fsPath(uri);
|
|
163
|
-
}
|
|
164
|
-
}));
|
|
165
|
-
variables.registerVariable(scoped({
|
|
166
|
-
name: 'workspaceRootFolderName',
|
|
167
|
-
description: 'The name of the workspace root folder',
|
|
168
|
-
resolve: (context?: URI) => {
|
|
169
|
-
const uri = this.getWorkspaceRootUri(context);
|
|
170
|
-
return uri && uri.displayName;
|
|
171
|
-
}
|
|
172
|
-
}));
|
|
173
|
-
variables.registerVariable(scoped({
|
|
174
|
-
name: 'workspaceFolderBasename',
|
|
175
|
-
description: 'The name of the workspace root folder',
|
|
176
|
-
resolve: (context?: URI) => {
|
|
177
|
-
const uri = this.getWorkspaceRootUri(context);
|
|
178
|
-
return uri && uri.displayName;
|
|
179
|
-
}
|
|
180
|
-
}));
|
|
181
|
-
variables.registerVariable(scoped({
|
|
182
|
-
name: 'cwd',
|
|
183
|
-
description: "The task runner's current working directory on startup",
|
|
184
|
-
resolve: (context?: URI) => {
|
|
185
|
-
const uri = this.getWorkspaceRootUri(context);
|
|
186
|
-
return (uri && this.fileService.fsPath(uri)) || '';
|
|
187
|
-
}
|
|
188
|
-
}));
|
|
189
|
-
variables.registerVariable(scoped({
|
|
190
|
-
name: 'relativeFile',
|
|
191
|
-
description: "The currently opened file's path relative to the workspace root",
|
|
192
|
-
resolve: (context?: URI) => {
|
|
193
|
-
const uri = this.getResourceUri();
|
|
194
|
-
return uri && this.getWorkspaceRelativePath(uri, context);
|
|
195
|
-
}
|
|
196
|
-
}));
|
|
197
|
-
variables.registerVariable(scoped({
|
|
198
|
-
name: 'relativeFileDirname',
|
|
199
|
-
description: "The current opened file's dirname relative to ${workspaceFolder}",
|
|
200
|
-
resolve: (context?: URI) => {
|
|
201
|
-
const uri = this.getResourceUri();
|
|
202
|
-
const relativePath = uri && this.getWorkspaceRelativePath(uri, context);
|
|
203
|
-
return relativePath && new Path(relativePath).dir.toString();
|
|
204
|
-
}
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
getWorkspaceRootUri(uri: URI | undefined = this.getResourceUri()): URI | undefined {
|
|
209
|
-
return this.workspaceService.getWorkspaceRootUri(uri);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
getResourceUri(): URI | undefined {
|
|
213
|
-
return this.currentWidget && this.currentWidget.getResourceUri();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
getWorkspaceRelativePath(uri: URI, context?: URI): string | undefined {
|
|
217
|
-
const workspaceRootUri = this.getWorkspaceRootUri(context || uri);
|
|
218
|
-
const path = workspaceRootUri && workspaceRootUri.path.relative(uri.path);
|
|
219
|
-
return path && path.toString();
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
+
import URI from '@theia/core/lib/common/uri';
|
|
19
|
+
import { Path } from '@theia/core/lib/common/path';
|
|
20
|
+
import { ApplicationShell, NavigatableWidget, WidgetManager } from '@theia/core/lib/browser';
|
|
21
|
+
import { VariableContribution, VariableRegistry, Variable } from '@theia/variable-resolver/lib/browser';
|
|
22
|
+
import { WorkspaceService } from './workspace-service';
|
|
23
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
24
|
+
|
|
25
|
+
@injectable()
|
|
26
|
+
export class WorkspaceVariableContribution implements VariableContribution {
|
|
27
|
+
|
|
28
|
+
@inject(WorkspaceService)
|
|
29
|
+
protected readonly workspaceService: WorkspaceService;
|
|
30
|
+
@inject(ApplicationShell)
|
|
31
|
+
protected readonly shell: ApplicationShell;
|
|
32
|
+
@inject(FileService)
|
|
33
|
+
protected readonly fileService: FileService;
|
|
34
|
+
@inject(WidgetManager)
|
|
35
|
+
protected readonly widgetManager: WidgetManager;
|
|
36
|
+
|
|
37
|
+
protected currentWidget: NavigatableWidget | undefined;
|
|
38
|
+
|
|
39
|
+
@postConstruct()
|
|
40
|
+
protected init(): void {
|
|
41
|
+
this.shell.onDidChangeCurrentWidget(() => this.updateCurrentWidget());
|
|
42
|
+
this.widgetManager.onDidCreateWidget(({ widget }) => {
|
|
43
|
+
if (NavigatableWidget.is(widget)) {
|
|
44
|
+
widget.onDidChangeVisibility(() => {
|
|
45
|
+
if (widget.isVisible) {
|
|
46
|
+
this.addRecentlyVisible(widget);
|
|
47
|
+
} else {
|
|
48
|
+
this.removeRecentlyVisible(widget);
|
|
49
|
+
}
|
|
50
|
+
this.updateCurrentWidget();
|
|
51
|
+
});
|
|
52
|
+
widget.onDidDispose(() => {
|
|
53
|
+
this.removeRecentlyVisible(widget);
|
|
54
|
+
this.updateCurrentWidget();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
for (const widget of this.shell.widgets) {
|
|
59
|
+
if (NavigatableWidget.is(widget) && widget.isVisible) {
|
|
60
|
+
this.addRecentlyVisible(widget);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
this.updateCurrentWidget();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected readonly recentlyVisibleIds: string[] = [];
|
|
67
|
+
protected get recentlyVisible(): NavigatableWidget | undefined {
|
|
68
|
+
const id = this.recentlyVisibleIds[0];
|
|
69
|
+
const widget = id && this.shell.getWidgetById(id) || undefined;
|
|
70
|
+
if (NavigatableWidget.is(widget)) {
|
|
71
|
+
return widget;
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
protected addRecentlyVisible(widget: NavigatableWidget): void {
|
|
76
|
+
this.removeRecentlyVisible(widget);
|
|
77
|
+
this.recentlyVisibleIds.unshift(widget.id);
|
|
78
|
+
}
|
|
79
|
+
protected removeRecentlyVisible(widget: NavigatableWidget): void {
|
|
80
|
+
const index = this.recentlyVisibleIds.indexOf(widget.id);
|
|
81
|
+
if (index !== -1) {
|
|
82
|
+
this.recentlyVisibleIds.splice(index, 1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected updateCurrentWidget(): void {
|
|
87
|
+
const { currentWidget } = this.shell;
|
|
88
|
+
if (NavigatableWidget.is(currentWidget)) {
|
|
89
|
+
this.currentWidget = currentWidget;
|
|
90
|
+
} else if (!this.currentWidget || !this.currentWidget.isVisible) {
|
|
91
|
+
this.currentWidget = this.recentlyVisible;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
registerVariables(variables: VariableRegistry): void {
|
|
96
|
+
this.registerWorkspaceRootVariables(variables);
|
|
97
|
+
|
|
98
|
+
variables.registerVariable({
|
|
99
|
+
name: 'file',
|
|
100
|
+
description: 'The path of the currently opened file',
|
|
101
|
+
resolve: () => {
|
|
102
|
+
const uri = this.getResourceUri();
|
|
103
|
+
return uri && this.fileService.fsPath(uri);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
variables.registerVariable({
|
|
107
|
+
name: 'fileBasename',
|
|
108
|
+
description: 'The basename of the currently opened file',
|
|
109
|
+
resolve: () => {
|
|
110
|
+
const uri = this.getResourceUri();
|
|
111
|
+
return uri && uri.path.base;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
variables.registerVariable({
|
|
115
|
+
name: 'fileBasenameNoExtension',
|
|
116
|
+
description: "The currently opened file's name without extension",
|
|
117
|
+
resolve: () => {
|
|
118
|
+
const uri = this.getResourceUri();
|
|
119
|
+
return uri && uri.path.name;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
variables.registerVariable({
|
|
123
|
+
name: 'fileDirname',
|
|
124
|
+
description: "The name of the currently opened file's directory",
|
|
125
|
+
resolve: () => {
|
|
126
|
+
const uri = this.getResourceUri();
|
|
127
|
+
return uri && uri.path.dir.toString();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
variables.registerVariable({
|
|
131
|
+
name: 'fileExtname',
|
|
132
|
+
description: 'The extension of the currently opened file',
|
|
133
|
+
resolve: () => {
|
|
134
|
+
const uri = this.getResourceUri();
|
|
135
|
+
return uri && uri.path.ext;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
protected registerWorkspaceRootVariables(variables: VariableRegistry): void {
|
|
141
|
+
const scoped = (variable: Variable): Variable => ({
|
|
142
|
+
name: variable.name,
|
|
143
|
+
description: variable.description,
|
|
144
|
+
resolve: (context, workspaceRootName) => {
|
|
145
|
+
const workspaceRoot = workspaceRootName && this.workspaceService.tryGetRoots().find(r => r.resource.path.name === workspaceRootName);
|
|
146
|
+
return variable.resolve(workspaceRoot ? workspaceRoot.resource : context);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
variables.registerVariable(scoped({
|
|
150
|
+
name: 'workspaceRoot',
|
|
151
|
+
description: 'The path of the workspace root folder',
|
|
152
|
+
resolve: (context?: URI) => {
|
|
153
|
+
const uri = this.getWorkspaceRootUri(context);
|
|
154
|
+
return uri && this.fileService.fsPath(uri);
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
157
|
+
variables.registerVariable(scoped({
|
|
158
|
+
name: 'workspaceFolder',
|
|
159
|
+
description: 'The path of the workspace root folder',
|
|
160
|
+
resolve: (context?: URI) => {
|
|
161
|
+
const uri = this.getWorkspaceRootUri(context);
|
|
162
|
+
return uri && this.fileService.fsPath(uri);
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
variables.registerVariable(scoped({
|
|
166
|
+
name: 'workspaceRootFolderName',
|
|
167
|
+
description: 'The name of the workspace root folder',
|
|
168
|
+
resolve: (context?: URI) => {
|
|
169
|
+
const uri = this.getWorkspaceRootUri(context);
|
|
170
|
+
return uri && uri.displayName;
|
|
171
|
+
}
|
|
172
|
+
}));
|
|
173
|
+
variables.registerVariable(scoped({
|
|
174
|
+
name: 'workspaceFolderBasename',
|
|
175
|
+
description: 'The name of the workspace root folder',
|
|
176
|
+
resolve: (context?: URI) => {
|
|
177
|
+
const uri = this.getWorkspaceRootUri(context);
|
|
178
|
+
return uri && uri.displayName;
|
|
179
|
+
}
|
|
180
|
+
}));
|
|
181
|
+
variables.registerVariable(scoped({
|
|
182
|
+
name: 'cwd',
|
|
183
|
+
description: "The task runner's current working directory on startup",
|
|
184
|
+
resolve: (context?: URI) => {
|
|
185
|
+
const uri = this.getWorkspaceRootUri(context);
|
|
186
|
+
return (uri && this.fileService.fsPath(uri)) || '';
|
|
187
|
+
}
|
|
188
|
+
}));
|
|
189
|
+
variables.registerVariable(scoped({
|
|
190
|
+
name: 'relativeFile',
|
|
191
|
+
description: "The currently opened file's path relative to the workspace root",
|
|
192
|
+
resolve: (context?: URI) => {
|
|
193
|
+
const uri = this.getResourceUri();
|
|
194
|
+
return uri && this.getWorkspaceRelativePath(uri, context);
|
|
195
|
+
}
|
|
196
|
+
}));
|
|
197
|
+
variables.registerVariable(scoped({
|
|
198
|
+
name: 'relativeFileDirname',
|
|
199
|
+
description: "The current opened file's dirname relative to ${workspaceFolder}",
|
|
200
|
+
resolve: (context?: URI) => {
|
|
201
|
+
const uri = this.getResourceUri();
|
|
202
|
+
const relativePath = uri && this.getWorkspaceRelativePath(uri, context);
|
|
203
|
+
return relativePath && new Path(relativePath).dir.toString();
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
getWorkspaceRootUri(uri: URI | undefined = this.getResourceUri()): URI | undefined {
|
|
209
|
+
return this.workspaceService.getWorkspaceRootUri(uri);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
getResourceUri(): URI | undefined {
|
|
213
|
+
return this.currentWidget && this.currentWidget.getResourceUri();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
getWorkspaceRelativePath(uri: URI, context?: URI): string | undefined {
|
|
217
|
+
const workspaceRootUri = this.getWorkspaceRootUri(context || uri);
|
|
218
|
+
const path = workspaceRootUri && workspaceRootUri.path.relative(uri.path);
|
|
219
|
+
return path && path.toString();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
}
|