@theia/workspace 1.53.0-next.4 → 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,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
+ }