@theia/workspace 1.77.0-next.0 → 1.77.0-next.101
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/lib/browser/canonical-uri-service.js +12 -16
- package/lib/browser/canonical-uri-service.js.map +1 -1
- package/lib/browser/diff-service.js +23 -29
- package/lib/browser/diff-service.js.map +1 -1
- package/lib/browser/index.d.ts +8 -8
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +8 -11
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/metadata-storage/index.d.ts +2 -2
- package/lib/browser/metadata-storage/index.d.ts.map +1 -1
- package/lib/browser/metadata-storage/index.js +2 -9
- package/lib/browser/metadata-storage/index.js.map +1 -1
- package/lib/browser/metadata-storage/workspace-metadata-storage-service.d.ts +6 -2
- package/lib/browser/metadata-storage/workspace-metadata-storage-service.d.ts.map +1 -1
- package/lib/browser/metadata-storage/workspace-metadata-storage-service.js +34 -36
- package/lib/browser/metadata-storage/workspace-metadata-storage-service.js.map +1 -1
- package/lib/browser/metadata-storage/workspace-metadata-storage-service.spec.js +70 -73
- package/lib/browser/metadata-storage/workspace-metadata-storage-service.spec.js.map +1 -1
- package/lib/browser/metadata-storage/workspace-metadata-store.d.ts +1 -1
- package/lib/browser/metadata-storage/workspace-metadata-store.d.ts.map +1 -1
- package/lib/browser/metadata-storage/workspace-metadata-store.js +19 -28
- package/lib/browser/metadata-storage/workspace-metadata-store.js.map +1 -1
- package/lib/browser/quick-open-workspace.d.ts +2 -2
- package/lib/browser/quick-open-workspace.d.ts.map +1 -1
- package/lib/browser/quick-open-workspace.js +31 -40
- package/lib/browser/quick-open-workspace.js.map +1 -1
- package/lib/browser/test/with-workspace-service-defaults.d.ts +8 -0
- package/lib/browser/test/with-workspace-service-defaults.d.ts.map +1 -0
- package/lib/browser/test/with-workspace-service-defaults.js +25 -0
- package/lib/browser/test/with-workspace-service-defaults.js.map +1 -0
- package/lib/browser/untitled-workspace-exit-dialog.js +13 -17
- package/lib/browser/untitled-workspace-exit-dialog.js.map +1 -1
- package/lib/browser/workspace-breadcrumbs-contribution.d.ts +3 -1
- package/lib/browser/workspace-breadcrumbs-contribution.d.ts.map +1 -1
- package/lib/browser/workspace-breadcrumbs-contribution.js +23 -14
- package/lib/browser/workspace-breadcrumbs-contribution.js.map +1 -1
- package/lib/browser/workspace-commands.d.ts +5 -5
- package/lib/browser/workspace-commands.d.ts.map +1 -1
- package/lib/browser/workspace-commands.js +129 -146
- package/lib/browser/workspace-commands.js.map +1 -1
- package/lib/browser/workspace-commands.spec.js +50 -52
- package/lib/browser/workspace-commands.spec.js.map +1 -1
- package/lib/browser/workspace-compare-handler.d.ts +1 -1
- package/lib/browser/workspace-compare-handler.d.ts.map +1 -1
- package/lib/browser/workspace-compare-handler.js +8 -12
- package/lib/browser/workspace-compare-handler.js.map +1 -1
- package/lib/browser/workspace-delete-handler.d.ts +2 -2
- package/lib/browser/workspace-delete-handler.d.ts.map +1 -1
- package/lib/browser/workspace-delete-handler.js +42 -51
- package/lib/browser/workspace-delete-handler.js.map +1 -1
- package/lib/browser/workspace-duplicate-handler.d.ts +2 -2
- package/lib/browser/workspace-duplicate-handler.d.ts.map +1 -1
- package/lib/browser/workspace-duplicate-handler.js +20 -27
- package/lib/browser/workspace-duplicate-handler.js.map +1 -1
- package/lib/browser/workspace-files-exclude-filter-provider.d.ts +1 -1
- package/lib/browser/workspace-files-exclude-filter-provider.d.ts.map +1 -1
- package/lib/browser/workspace-files-exclude-filter-provider.js +12 -19
- package/lib/browser/workspace-files-exclude-filter-provider.js.map +1 -1
- package/lib/browser/workspace-frontend-contribution.d.ts +4 -4
- package/lib/browser/workspace-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/workspace-frontend-contribution.js +129 -143
- package/lib/browser/workspace-frontend-contribution.js.map +1 -1
- package/lib/browser/workspace-frontend-module.js +85 -87
- package/lib/browser/workspace-frontend-module.js.map +1 -1
- package/lib/browser/workspace-input-dialog.js +13 -18
- package/lib/browser/workspace-input-dialog.js.map +1 -1
- package/lib/browser/workspace-schema-updater.d.ts +1 -1
- package/lib/browser/workspace-schema-updater.d.ts.map +1 -1
- package/lib/browser/workspace-schema-updater.js +36 -40
- package/lib/browser/workspace-schema-updater.js.map +1 -1
- package/lib/browser/workspace-search-filter-service.js +13 -20
- package/lib/browser/workspace-search-filter-service.js.map +1 -1
- package/lib/browser/workspace-search-filter-service.spec.js +18 -20
- package/lib/browser/workspace-search-filter-service.spec.js.map +1 -1
- package/lib/browser/workspace-service.d.ts +134 -5
- package/lib/browser/workspace-service.d.ts.map +1 -1
- package/lib/browser/workspace-service.js +409 -157
- package/lib/browser/workspace-service.js.map +1 -1
- package/lib/browser/workspace-service.spec.d.ts +2 -0
- package/lib/browser/workspace-service.spec.d.ts.map +1 -0
- package/lib/browser/workspace-service.spec.js +425 -0
- package/lib/browser/workspace-service.spec.js.map +1 -0
- package/lib/browser/workspace-storage-service.d.ts +1 -1
- package/lib/browser/workspace-storage-service.d.ts.map +1 -1
- package/lib/browser/workspace-storage-service.js +13 -21
- package/lib/browser/workspace-storage-service.js.map +1 -1
- package/lib/browser/workspace-trust-dialog.js +9 -13
- package/lib/browser/workspace-trust-dialog.js.map +1 -1
- package/lib/browser/workspace-trust-service.d.ts +3 -3
- package/lib/browser/workspace-trust-service.d.ts.map +1 -1
- package/lib/browser/workspace-trust-service.js +106 -127
- package/lib/browser/workspace-trust-service.js.map +1 -1
- package/lib/browser/workspace-trust-service.spec.js +146 -148
- package/lib/browser/workspace-trust-service.spec.js.map +1 -1
- package/lib/browser/workspace-uri-contribution.d.ts +27 -2
- package/lib/browser/workspace-uri-contribution.d.ts.map +1 -1
- package/lib/browser/workspace-uri-contribution.js +79 -32
- package/lib/browser/workspace-uri-contribution.js.map +1 -1
- package/lib/browser/workspace-uri-contribution.spec.js +130 -70
- package/lib/browser/workspace-uri-contribution.spec.js.map +1 -1
- package/lib/browser/workspace-user-working-directory-provider.d.ts +1 -1
- package/lib/browser/workspace-user-working-directory-provider.d.ts.map +1 -1
- package/lib/browser/workspace-user-working-directory-provider.js +13 -18
- package/lib/browser/workspace-user-working-directory-provider.js.map +1 -1
- package/lib/browser/workspace-utils.d.ts +1 -1
- package/lib/browser/workspace-utils.d.ts.map +1 -1
- package/lib/browser/workspace-utils.js +8 -12
- package/lib/browser/workspace-utils.js.map +1 -1
- package/lib/browser/workspace-variable-contribution.d.ts +1 -1
- package/lib/browser/workspace-variable-contribution.d.ts.map +1 -1
- package/lib/browser/workspace-variable-contribution.js +37 -47
- package/lib/browser/workspace-variable-contribution.js.map +1 -1
- package/lib/browser/workspace-window-title-updater.d.ts +1 -1
- package/lib/browser/workspace-window-title-updater.d.ts.map +1 -1
- package/lib/browser/workspace-window-title-updater.js +12 -16
- package/lib/browser/workspace-window-title-updater.js.map +1 -1
- package/lib/browser-only/browser-only-workspace-server.d.ts +1 -1
- package/lib/browser-only/browser-only-workspace-server.d.ts.map +1 -1
- package/lib/browser-only/browser-only-workspace-server.js +17 -22
- package/lib/browser-only/browser-only-workspace-server.js.map +1 -1
- package/lib/browser-only/workspace-frontend-only-module.js +8 -10
- package/lib/browser-only/workspace-frontend-only-module.js.map +1 -1
- package/lib/common/index.d.ts +4 -4
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +4 -7
- package/lib/common/index.js.map +1 -1
- package/lib/common/test/mock-workspace-server.d.ts +1 -1
- package/lib/common/test/mock-workspace-server.d.ts.map +1 -1
- package/lib/common/test/mock-workspace-server.js +5 -8
- package/lib/common/test/mock-workspace-server.js.map +1 -1
- package/lib/common/untitled-workspace-service.d.ts +1 -1
- package/lib/common/untitled-workspace-service.d.ts.map +1 -1
- package/lib/common/untitled-workspace-service.js +8 -12
- package/lib/common/untitled-workspace-service.js.map +1 -1
- package/lib/common/workspace-file-service.js +11 -14
- package/lib/common/workspace-file-service.js.map +1 -1
- package/lib/common/workspace-preferences.js +14 -19
- package/lib/common/workspace-preferences.js.map +1 -1
- package/lib/common/workspace-protocol.js +2 -5
- package/lib/common/workspace-protocol.js.map +1 -1
- package/lib/common/workspace-trust-preferences.js +29 -34
- package/lib/common/workspace-trust-preferences.js.map +1 -1
- package/lib/electron-browser/electron-workspace-contribution.d.ts +1 -1
- package/lib/electron-browser/electron-workspace-contribution.d.ts.map +1 -1
- package/lib/electron-browser/electron-workspace-contribution.js +11 -15
- package/lib/electron-browser/electron-workspace-contribution.js.map +1 -1
- package/lib/electron-browser/electron-workspace-module.js +6 -8
- package/lib/electron-browser/electron-workspace-module.js.map +1 -1
- package/lib/node/default-workspace-server.d.ts +1 -1
- package/lib/node/default-workspace-server.d.ts.map +1 -1
- package/lib/node/default-workspace-server.js +51 -63
- package/lib/node/default-workspace-server.js.map +1 -1
- package/lib/node/default-workspace-server.spec.js +29 -31
- package/lib/node/default-workspace-server.spec.js.map +1 -1
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +2 -5
- package/lib/node/index.js.map +1 -1
- package/lib/node/workspace-backend-module.js +21 -23
- package/lib/node/workspace-backend-module.js.map +1 -1
- package/package.json +17 -5
- package/src/browser/index.ts +8 -8
- package/src/browser/metadata-storage/index.ts +2 -2
- package/src/browser/metadata-storage/workspace-metadata-storage-service.spec.ts +4 -5
- package/src/browser/metadata-storage/workspace-metadata-storage-service.ts +10 -3
- package/src/browser/metadata-storage/workspace-metadata-store.ts +1 -1
- package/src/browser/quick-open-workspace.ts +2 -2
- package/src/browser/test/with-workspace-service-defaults.ts +26 -0
- package/src/browser/workspace-breadcrumbs-contribution.ts +16 -1
- package/src/browser/workspace-commands.spec.ts +6 -6
- package/src/browser/workspace-commands.ts +7 -8
- package/src/browser/workspace-compare-handler.ts +1 -1
- package/src/browser/workspace-delete-handler.ts +2 -2
- package/src/browser/workspace-duplicate-handler.ts +2 -2
- package/src/browser/workspace-files-exclude-filter-provider.ts +1 -1
- package/src/browser/workspace-frontend-contribution.ts +10 -8
- package/src/browser/workspace-frontend-module.ts +25 -25
- package/src/browser/workspace-schema-updater.ts +5 -1
- package/src/browser/workspace-search-filter-service.spec.ts +1 -1
- package/src/browser/workspace-service.spec.ts +508 -0
- package/src/browser/workspace-service.ts +353 -44
- package/src/browser/workspace-storage-service.ts +1 -1
- package/src/browser/workspace-trust-service.spec.ts +2 -2
- package/src/browser/workspace-trust-service.ts +5 -5
- package/src/browser/workspace-uri-contribution.spec.ts +76 -6
- package/src/browser/workspace-uri-contribution.ts +61 -4
- package/src/browser/workspace-user-working-directory-provider.ts +1 -1
- package/src/browser/workspace-utils.ts +1 -1
- package/src/browser/workspace-variable-contribution.ts +1 -1
- package/src/browser/workspace-window-title-updater.ts +1 -1
- package/src/browser-only/browser-only-workspace-server.ts +1 -1
- package/src/browser-only/workspace-frontend-only-module.ts +2 -2
- package/src/common/index.ts +4 -4
- package/src/common/test/mock-workspace-server.ts +1 -1
- package/src/common/untitled-workspace-service.ts +1 -1
- package/src/electron-browser/electron-workspace-contribution.ts +1 -1
- package/src/electron-browser/electron-workspace-module.ts +1 -1
- package/src/node/default-workspace-server.spec.ts +2 -2
- package/src/node/default-workspace-server.ts +1 -1
- package/src/node/index.ts +2 -2
- package/src/node/workspace-backend-module.ts +3 -3
- package/src/typings/valid-filename.d.ts +20 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// *****************************************************************************
|
|
3
2
|
// Copyright (C) 2017 TypeFox and others.
|
|
4
3
|
//
|
|
@@ -14,41 +13,44 @@
|
|
|
14
13
|
//
|
|
15
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
15
|
// *****************************************************************************
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
exports.WorkspaceHandlingContribution = Symbol('WorkspaceHandlingContribution');
|
|
16
|
+
import { __decorate } from "tslib";
|
|
17
|
+
import { injectable, inject, postConstruct, named } 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 { WorkspaceServer, UntitledWorkspaceService, WorkspaceFileService } from '../common/index.js';
|
|
21
|
+
import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
|
22
|
+
import { DEFAULT_WINDOW_HASH } from '@theia/core/lib/common/window';
|
|
23
|
+
import { LabelProvider } from '@theia/core/lib/browser';
|
|
24
|
+
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
25
|
+
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
26
|
+
import { ILogger, Disposable, DisposableCollection, Emitter, environment, MessageService, nls, ContributionProvider } from '@theia/core';
|
|
27
|
+
import { WorkspacePreferences } from '../common/workspace-preferences.js';
|
|
28
|
+
import * as jsoncparser from 'jsonc-parser';
|
|
29
|
+
import Ajv from '@theia/core/shared/ajv';
|
|
30
|
+
import { FileStat } from '@theia/filesystem/lib/common/files';
|
|
31
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
32
|
+
import { WindowTitleService } from '@theia/core/lib/browser/window/window-title-service';
|
|
33
|
+
import { FileSystemPreferences } from '@theia/filesystem/lib/common';
|
|
34
|
+
import { workspaceSchema, WorkspaceSchemaUpdater } from './workspace-schema-updater.js';
|
|
35
|
+
import { StopReason } from '@theia/core/lib/common/frontend-application-state';
|
|
36
|
+
import { PreferenceSchemaService, PreferenceScope, PreferenceService } from '@theia/core/lib/common/preferences';
|
|
37
|
+
export const WorkspaceOpenHandlerContribution = Symbol('WorkspaceOpenHandlerContribution');
|
|
38
|
+
export const WorkspaceHandlingContribution = Symbol('WorkspaceHandlingContribution');
|
|
41
39
|
/**
|
|
42
40
|
* The workspace service.
|
|
43
41
|
*/
|
|
44
42
|
let WorkspaceService = class WorkspaceService {
|
|
45
43
|
constructor() {
|
|
46
44
|
this._roots = [];
|
|
47
|
-
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
45
|
+
/** The names of the roots, published together with `_roots` when `onWorkspaceChanged` fires. */
|
|
46
|
+
this.configuredRootNames = new Map();
|
|
47
|
+
/** The names of the roots read by the last `computeRoots`, not yet published. */
|
|
48
|
+
this.computedRootNames = new Map();
|
|
49
|
+
this.deferredRoots = new Deferred();
|
|
50
|
+
this._ready = new Deferred();
|
|
51
|
+
this.onWorkspaceChangeEmitter = new Emitter();
|
|
52
|
+
this.onWorkspaceLocationChangedEmitter = new Emitter();
|
|
53
|
+
this.toDisposeOnWorkspace = new DisposableCollection();
|
|
52
54
|
this.rootWatchers = new Map();
|
|
53
55
|
}
|
|
54
56
|
get ready() {
|
|
@@ -60,7 +62,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
60
62
|
async doInit() {
|
|
61
63
|
let wsUriString = await this.getDefaultWorkspaceUri();
|
|
62
64
|
if (wsUriString) {
|
|
63
|
-
const wsUri = new
|
|
65
|
+
const wsUri = new URI(wsUriString);
|
|
64
66
|
if (wsUri.scheme !== 'file') {
|
|
65
67
|
let handled = false;
|
|
66
68
|
for (const handler of this.openHandlerContribution.getContributions()) {
|
|
@@ -87,7 +89,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
87
89
|
// No handler could open this non-file URI, or it failed/timed out.
|
|
88
90
|
// Fall back to the most recent local workspace.
|
|
89
91
|
const recents = await this.server.getRecentWorkspaces();
|
|
90
|
-
wsUriString = recents.find(r => new
|
|
92
|
+
wsUriString = recents.find(r => new URI(r).scheme === 'file');
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
let wsStat = await this.toFileStat(wsUriString);
|
|
@@ -96,7 +98,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
96
98
|
// to a path that doesn't exist locally. Fall back to the most recent
|
|
97
99
|
// local workspace.
|
|
98
100
|
const recents = await this.server.getRecentWorkspaces();
|
|
99
|
-
const fallback = recents.find(r => new
|
|
101
|
+
const fallback = recents.find(r => new URI(r).scheme === 'file');
|
|
100
102
|
if (fallback) {
|
|
101
103
|
wsStat = await this.toFileStat(fallback);
|
|
102
104
|
}
|
|
@@ -130,7 +132,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
130
132
|
async doGetDefaultWorkspaceUri() {
|
|
131
133
|
// If an empty window is explicitly requested do not restore a previous workspace.
|
|
132
134
|
// Note: `window.location.hash` includes leading "#" if non-empty.
|
|
133
|
-
if (window.location.hash === `#${
|
|
135
|
+
if (window.location.hash === `#${DEFAULT_WINDOW_HASH}`) {
|
|
134
136
|
window.location.hash = '';
|
|
135
137
|
return undefined;
|
|
136
138
|
}
|
|
@@ -144,10 +146,10 @@ let WorkspaceService = class WorkspaceService {
|
|
|
144
146
|
const firstSlash = unc.indexOf('/');
|
|
145
147
|
const authority = firstSlash >= 0 ? unc.slice(0, firstSlash) : unc;
|
|
146
148
|
const path = firstSlash >= 0 ? unc.slice(firstSlash) : '/';
|
|
147
|
-
workspaceUri = new
|
|
149
|
+
workspaceUri = new URI().withPath(path).withAuthority(authority).withScheme('file');
|
|
148
150
|
}
|
|
149
151
|
else {
|
|
150
|
-
workspaceUri = new
|
|
152
|
+
workspaceUri = new URI().withPath(wpPath).withScheme('file');
|
|
151
153
|
}
|
|
152
154
|
let workspaceStat;
|
|
153
155
|
try {
|
|
@@ -155,7 +157,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
155
157
|
}
|
|
156
158
|
catch { }
|
|
157
159
|
if (workspaceStat && !workspaceStat.isDirectory && !this.isWorkspaceFile(workspaceStat)) {
|
|
158
|
-
this.messageService.error(
|
|
160
|
+
this.messageService.error(nls.localize('theia/workspace/notWorkspaceFile', 'Not a valid workspace file: {0}', this.labelProvider.getLongName(workspaceUri)));
|
|
159
161
|
return undefined;
|
|
160
162
|
}
|
|
161
163
|
return workspaceUri.toString();
|
|
@@ -225,7 +227,9 @@ let WorkspaceService = class WorkspaceService {
|
|
|
225
227
|
}
|
|
226
228
|
async updateRoots() {
|
|
227
229
|
const newRoots = await this.computeRoots();
|
|
228
|
-
|
|
230
|
+
const newRootNames = this.computedRootNames;
|
|
231
|
+
// Compare against the published names, so that overlapping calls fire only once for a rename
|
|
232
|
+
let rootsChanged = !this.areConfiguredRootNamesEqual(this.configuredRootNames, newRootNames);
|
|
229
233
|
if (newRoots.length !== this._roots.length || newRoots.length === 0) {
|
|
230
234
|
rootsChanged = true;
|
|
231
235
|
}
|
|
@@ -239,33 +243,50 @@ let WorkspaceService = class WorkspaceService {
|
|
|
239
243
|
}
|
|
240
244
|
if (rootsChanged) {
|
|
241
245
|
this._roots = newRoots;
|
|
246
|
+
this.configuredRootNames = newRootNames;
|
|
247
|
+
this.rootNamesCache = undefined;
|
|
242
248
|
this.deferredRoots.resolve(this._roots); // in order to resolve first
|
|
243
|
-
this.deferredRoots = new
|
|
249
|
+
this.deferredRoots = new Deferred();
|
|
244
250
|
this.deferredRoots.resolve(this._roots);
|
|
245
251
|
this.onWorkspaceChangeEmitter.fire(this._roots);
|
|
246
252
|
}
|
|
247
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Computes the workspace roots. Also sets `computedRootNames` to the names given to the roots in the workspace file,
|
|
256
|
+
* which `updateRoots` publishes with the roots, see `getConfiguredRootName`.
|
|
257
|
+
* An override that does not call `super` has to set `computedRootNames` itself, otherwise the names of the previous roots remain.
|
|
258
|
+
*/
|
|
248
259
|
async computeRoots() {
|
|
249
260
|
const roots = [];
|
|
261
|
+
const rootNames = new Map();
|
|
250
262
|
if (this._workspace) {
|
|
251
263
|
if (this._workspace.isDirectory) {
|
|
264
|
+
this.computedRootNames = rootNames;
|
|
252
265
|
return [this._workspace];
|
|
253
266
|
}
|
|
254
267
|
const workspaceData = await this.getWorkspaceDataFromFile();
|
|
255
268
|
if (workspaceData) {
|
|
256
|
-
for (const { path } of workspaceData.folders) {
|
|
269
|
+
for (const { path, name } of workspaceData.folders) {
|
|
257
270
|
const valid = await this.toValidRoot(path);
|
|
258
271
|
if (valid) {
|
|
259
272
|
roots.push(valid);
|
|
260
273
|
}
|
|
261
274
|
else {
|
|
262
|
-
roots.push(
|
|
275
|
+
roots.push(FileStat.dir(path));
|
|
276
|
+
}
|
|
277
|
+
// `getWorkspaceDataFromFile` already drops invalid names, but an override of it may not
|
|
278
|
+
if (typeof name === 'string' && name) {
|
|
279
|
+
rootNames.set(WorkspaceData.normalizeFolderUri(path), name);
|
|
263
280
|
}
|
|
264
281
|
}
|
|
265
282
|
}
|
|
266
283
|
}
|
|
284
|
+
this.computedRootNames = rootNames;
|
|
267
285
|
return roots;
|
|
268
286
|
}
|
|
287
|
+
areConfiguredRootNamesEqual(names, otherNames) {
|
|
288
|
+
return names.size === otherNames.size && Array.from(names).every(([root, name]) => otherNames.get(root) === name);
|
|
289
|
+
}
|
|
269
290
|
async getWorkspaceDataFromFile() {
|
|
270
291
|
if (this._workspace && await this.fileService.exists(this._workspace.resource)) {
|
|
271
292
|
if (this._workspace.isDirectory) {
|
|
@@ -295,7 +316,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
295
316
|
const fullName = this._workspace.resource.path.toString();
|
|
296
317
|
if (this.isWorkspaceFile(this._workspace)) {
|
|
297
318
|
if (this.isUntitledWorkspace(this._workspace.resource)) {
|
|
298
|
-
const untitled =
|
|
319
|
+
const untitled = nls.localizeByDefault('Untitled (Workspace)');
|
|
299
320
|
rootName = untitled;
|
|
300
321
|
rootPath = untitled;
|
|
301
322
|
}
|
|
@@ -324,12 +345,12 @@ let WorkspaceService = class WorkspaceService {
|
|
|
324
345
|
* In Electron, we use `onWillStop` so the workspace is persisted before the window closes.
|
|
325
346
|
*/
|
|
326
347
|
onStop() {
|
|
327
|
-
if (!
|
|
348
|
+
if (!environment.electron.is()) {
|
|
328
349
|
this.setMostRecentlyUsedWorkspace();
|
|
329
350
|
}
|
|
330
351
|
}
|
|
331
352
|
onWillStop() {
|
|
332
|
-
if (
|
|
353
|
+
if (environment.electron.is() && this.workspace) {
|
|
333
354
|
return {
|
|
334
355
|
reason: 'Set workspace root as most recently used',
|
|
335
356
|
action: async () => {
|
|
@@ -404,7 +425,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
404
425
|
const stat = await this.toFileStat(uri);
|
|
405
426
|
if (stat) {
|
|
406
427
|
if (!stat.isDirectory && !this.isWorkspaceFile(stat)) {
|
|
407
|
-
const message =
|
|
428
|
+
const message = nls.localize('theia/workspace/notWorkspaceFile', 'Not a valid workspace file: {0}', this.labelProvider.getLongName(uri));
|
|
408
429
|
this.messageService.error(message);
|
|
409
430
|
throw new Error(message);
|
|
410
431
|
}
|
|
@@ -441,6 +462,11 @@ let WorkspaceService = class WorkspaceService {
|
|
|
441
462
|
await this.updateWorkspace();
|
|
442
463
|
}
|
|
443
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Removes `deleteCount` roots starting at `start` and inserts the given roots there, and writes the result to the workspace file.
|
|
467
|
+
* A root to add can be given a name, which is written to the workspace file as the `name` of its folder entry.
|
|
468
|
+
* @returns the URIs of the removed roots
|
|
469
|
+
*/
|
|
444
470
|
async spliceRoots(start, deleteCount, ...rootsToAdd) {
|
|
445
471
|
if (!this._workspace || this._workspace.isDirectory) {
|
|
446
472
|
const untitledWorkspace = await this.getUntitledWorkspace();
|
|
@@ -449,29 +475,41 @@ let WorkspaceService = class WorkspaceService {
|
|
|
449
475
|
throw new Error('Could not create new untitled workspace');
|
|
450
476
|
}
|
|
451
477
|
}
|
|
452
|
-
const
|
|
453
|
-
const
|
|
478
|
+
const roots = this._roots.map(root => root.resource.toString());
|
|
479
|
+
const toRemove = roots.splice(start, deleteCount || 0);
|
|
480
|
+
// Deduplicate against the remaining roots only, so that a root removed by this call can be added again, e.g. to rename it.
|
|
481
|
+
const dedup = new Set(roots);
|
|
454
482
|
const toAdd = [];
|
|
483
|
+
const namesToAdd = new Map();
|
|
455
484
|
for (const root of rootsToAdd) {
|
|
456
|
-
const uri = root
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
485
|
+
const { uri, name } = root instanceof URI ? { uri: root, name: undefined } : root;
|
|
486
|
+
const uriString = uri.toString();
|
|
487
|
+
if (!dedup.has(uriString)) {
|
|
488
|
+
dedup.add(uriString);
|
|
489
|
+
toAdd.push(uriString);
|
|
490
|
+
if (name) {
|
|
491
|
+
namesToAdd.set(uriString, name);
|
|
492
|
+
}
|
|
460
493
|
}
|
|
461
494
|
}
|
|
462
|
-
|
|
495
|
+
roots.splice(start, 0, ...toAdd);
|
|
463
496
|
if (!toRemove.length && !toAdd.length) {
|
|
464
497
|
return [];
|
|
465
498
|
}
|
|
466
499
|
const currentData = await this.getWorkspaceDataFromFile();
|
|
467
|
-
|
|
500
|
+
if (currentData) {
|
|
501
|
+
// A root added by this call only gets the name it is added with, so that adding a root again without a name resets its name
|
|
502
|
+
const added = new Set(toAdd.map(root => WorkspaceData.normalizeFolderUri(root)));
|
|
503
|
+
currentData.folders = currentData.folders.filter(folder => !added.has(WorkspaceData.normalizeFolderUri(folder.path)));
|
|
504
|
+
}
|
|
505
|
+
const newData = WorkspaceData.buildWorkspaceData(roots.map(path => ({ path, name: namesToAdd.get(path) })), currentData);
|
|
468
506
|
await this.writeWorkspaceFile(this._workspace, newData);
|
|
469
507
|
await this.updateWorkspace();
|
|
470
|
-
return toRemove.map(root => new
|
|
508
|
+
return toRemove.map(root => new URI(root));
|
|
471
509
|
}
|
|
472
510
|
async getUntitledWorkspace() {
|
|
473
|
-
const configDirURI = new
|
|
474
|
-
return this.untitledWorkspaceService.getUntitledWorkspaceUri(configDirURI, uri => this.fileService.exists(uri).then(exists => !exists), () => this.messageService.warn(
|
|
511
|
+
const configDirURI = new URI(await this.envVariableServer.getConfigDirUri());
|
|
512
|
+
return this.untitledWorkspaceService.getUntitledWorkspaceUri(configDirURI, uri => this.fileService.exists(uri).then(exists => !exists), () => this.messageService.warn(nls.localize('theia/workspace/untitled-cleanup', 'There appear to be many untitled workspace files. Please check {0} and remove any unused files.', configDirURI.resolve('workspaces').path.fsPath())));
|
|
475
513
|
}
|
|
476
514
|
async writeWorkspaceFile(workspaceFile, workspaceData) {
|
|
477
515
|
if (workspaceFile) {
|
|
@@ -486,10 +524,11 @@ let WorkspaceService = class WorkspaceService {
|
|
|
486
524
|
* Clears current workspace root.
|
|
487
525
|
*/
|
|
488
526
|
async close() {
|
|
489
|
-
if (await this.windowService.isSafeToShutDown(
|
|
527
|
+
if (await this.windowService.isSafeToShutDown(StopReason.Reload)) {
|
|
490
528
|
this.windowService.setSafeToShutDown();
|
|
491
529
|
this._workspace = undefined;
|
|
492
530
|
this._roots.length = 0;
|
|
531
|
+
this.rootNamesCache = undefined;
|
|
493
532
|
if (!this.isRemoteSession()) {
|
|
494
533
|
await this.server.setMostRecentlyUsedWorkspace('');
|
|
495
534
|
}
|
|
@@ -513,12 +552,8 @@ let WorkspaceService = class WorkspaceService {
|
|
|
513
552
|
if (!uri) {
|
|
514
553
|
return undefined;
|
|
515
554
|
}
|
|
516
|
-
let uriStr = uri.toString();
|
|
517
555
|
try {
|
|
518
|
-
|
|
519
|
-
uriStr = uriStr.slice(0, -1);
|
|
520
|
-
}
|
|
521
|
-
const normalizedUri = new uri_1.default(uriStr).normalizePath();
|
|
556
|
+
const normalizedUri = new URI(WorkspaceData.normalizeFolderUri(uri.toString()));
|
|
522
557
|
return await this.fileService.resolve(normalizedUri);
|
|
523
558
|
}
|
|
524
559
|
catch (error) {
|
|
@@ -586,16 +621,16 @@ let WorkspaceService = class WorkspaceService {
|
|
|
586
621
|
* @param uri URI or FileStat of the workspace file
|
|
587
622
|
*/
|
|
588
623
|
async save(uri) {
|
|
589
|
-
const resource = uri instanceof
|
|
624
|
+
const resource = uri instanceof URI ? uri : uri.resource;
|
|
590
625
|
if (!await this.fileService.exists(resource)) {
|
|
591
626
|
await this.fileService.create(resource);
|
|
592
627
|
}
|
|
593
628
|
const workspaceData = { folders: [], settings: {} };
|
|
594
629
|
if (!this.saved) {
|
|
595
|
-
for (const p of Object.keys(this.schemaService.getJSONSchema(
|
|
630
|
+
for (const p of Object.keys(this.schemaService.getJSONSchema(PreferenceScope.Workspace).properties)) {
|
|
596
631
|
// The goal is to ensure that workspace-scoped preferences are preserved in the new workspace.
|
|
597
632
|
// Preferences valid in folder scope will take effect in their folders without being copied.
|
|
598
|
-
if (this.schemaService.isValidInScope(p,
|
|
633
|
+
if (this.schemaService.isValidInScope(p, PreferenceScope.Folder)) {
|
|
599
634
|
continue;
|
|
600
635
|
}
|
|
601
636
|
const preferences = this.preferenceImpl.inspect(p);
|
|
@@ -641,11 +676,11 @@ let WorkspaceService = class WorkspaceService {
|
|
|
641
676
|
return;
|
|
642
677
|
}
|
|
643
678
|
const excludes = this.getExcludes(uriStr);
|
|
644
|
-
const watcher = this.fileService.watch(new
|
|
679
|
+
const watcher = this.fileService.watch(new URI(uriStr), {
|
|
645
680
|
recursive: true,
|
|
646
681
|
excludes
|
|
647
682
|
});
|
|
648
|
-
this.rootWatchers.set(uriStr, new
|
|
683
|
+
this.rootWatchers.set(uriStr, new DisposableCollection(watcher, Disposable.create(() => this.rootWatchers.delete(uriStr))));
|
|
649
684
|
}
|
|
650
685
|
getExcludes(uri) {
|
|
651
686
|
const patterns = this.fsPreferences.get('files.watcherExclude', undefined, uri);
|
|
@@ -674,6 +709,28 @@ let WorkspaceService = class WorkspaceService {
|
|
|
674
709
|
}
|
|
675
710
|
return rootUris.sort((r1, r2) => r2.toString().length - r1.toString().length)[0];
|
|
676
711
|
}
|
|
712
|
+
/**
|
|
713
|
+
* Returns the name given to the workspace root by the `name` property of its folder entry in the workspace file.
|
|
714
|
+
* This is the name shown for the root, as `WorkspaceFolder.name` in VS Code. Unlike the unique names of {@link getRootNames},
|
|
715
|
+
* it is chosen by the user and not used to address files.
|
|
716
|
+
* @param rootUri URI of the workspace root
|
|
717
|
+
* @returns the name of the root, or `undefined` if the root has no name or is not a workspace root
|
|
718
|
+
*/
|
|
719
|
+
getConfiguredRootName(rootUri) {
|
|
720
|
+
if (this.configuredRootNames.size === 0) {
|
|
721
|
+
return undefined;
|
|
722
|
+
}
|
|
723
|
+
// Called for every file label, e.g. by `getDetails`, so normalize each root URI only once per set of names
|
|
724
|
+
if (this.configuredRootNamesByUri?.names !== this.configuredRootNames) {
|
|
725
|
+
this.configuredRootNamesByUri = { names: this.configuredRootNames, byUri: new Map() };
|
|
726
|
+
}
|
|
727
|
+
const key = rootUri.toString();
|
|
728
|
+
const { byUri } = this.configuredRootNamesByUri;
|
|
729
|
+
if (!byUri.has(key)) {
|
|
730
|
+
byUri.set(key, this.configuredRootNames.get(WorkspaceData.normalizeFolderUri(key)));
|
|
731
|
+
}
|
|
732
|
+
return byUri.get(key);
|
|
733
|
+
}
|
|
677
734
|
/**
|
|
678
735
|
* Returns the relative path of the given file to the workspace root.
|
|
679
736
|
* @param uri URI of the file
|
|
@@ -706,13 +763,208 @@ let WorkspaceService = class WorkspaceService {
|
|
|
706
763
|
if (!rootUri) {
|
|
707
764
|
return uri.path.fsPath();
|
|
708
765
|
}
|
|
709
|
-
const rootName = rootUri.path.base;
|
|
766
|
+
const rootName = this.getRootName(rootUri) ?? rootUri.path.base;
|
|
710
767
|
const relative = rootUri.relative(uri);
|
|
711
768
|
if (!relative || relative.toString() === '') {
|
|
712
769
|
return rootName;
|
|
713
770
|
}
|
|
714
771
|
return `${rootName}/${relative.toString()}`;
|
|
715
772
|
}
|
|
773
|
+
/**
|
|
774
|
+
* Returns a unique name for each workspace root, in workspace order.
|
|
775
|
+
*
|
|
776
|
+
* A root is named after its directory basename, e.g. `backend`. Roots that share a basename are
|
|
777
|
+
* treated as peers: each of them is named after the shortest tail of its path that tells them
|
|
778
|
+
* apart, e.g. `alice/app` and `bob/app`. A name that another name starts with, e.g. `alice` next to
|
|
779
|
+
* `alice/app`, is qualified in the same way, e.g. `work/alice`, so that every path resolves to the root
|
|
780
|
+
* it came from. The names are thus always the ending of the real path, so they match what appears in
|
|
781
|
+
* terminal output, compiler errors and the like.
|
|
782
|
+
*
|
|
783
|
+
* These are the root names used by {@link getRootPrefixedPath} and resolved by {@link resolveRootPrefixedPath}.
|
|
784
|
+
*/
|
|
785
|
+
getRootNames() {
|
|
786
|
+
return this.getRootNamesCache().names;
|
|
787
|
+
}
|
|
788
|
+
getRootNamesCache() {
|
|
789
|
+
if (!this.rootNamesCache) {
|
|
790
|
+
const names = this.computeRootNames(this.tryGetRoots());
|
|
791
|
+
const namesByRoot = new Map(Array.from(names, ([name, uri]) => [uri.toString(), name]));
|
|
792
|
+
this.rootNamesCache = { names, namesByRoot };
|
|
793
|
+
}
|
|
794
|
+
return this.rootNamesCache;
|
|
795
|
+
}
|
|
796
|
+
computeRootNames(workspaceRoots) {
|
|
797
|
+
const roots = [];
|
|
798
|
+
for (const root of workspaceRoots) {
|
|
799
|
+
if (!roots.some(other => other.isEqual(root.resource))) {
|
|
800
|
+
roots.push(root.resource);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
const byBasename = new Map();
|
|
804
|
+
for (const root of roots) {
|
|
805
|
+
const peers = byBasename.get(root.path.base) ?? [];
|
|
806
|
+
peers.push(root);
|
|
807
|
+
byBasename.set(root.path.base, peers);
|
|
808
|
+
}
|
|
809
|
+
const names = new Map();
|
|
810
|
+
for (const root of roots) {
|
|
811
|
+
names.set(this.computeRootName(root, byBasename.get(root.path.base)), root);
|
|
812
|
+
}
|
|
813
|
+
return this.qualifyRootNames(names);
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Returns the name of the given workspace root, as assigned by {@link getRootNames}, or
|
|
817
|
+
* `undefined` if the URI is not a workspace root.
|
|
818
|
+
*/
|
|
819
|
+
getRootName(rootUri) {
|
|
820
|
+
return this.getRootNamesCache().namesByRoot.get(rootUri.toString());
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Resolves a path in the format of {@link getRootPrefixedPath}, i.e. `<rootName>/<relativePath>`
|
|
824
|
+
* or a bare `<rootName>`, to a URI. If more than one root name is a prefix of the path, which is
|
|
825
|
+
* the case when a root named `a` has a subfolder `b` and another root is named `a/b`, the longest
|
|
826
|
+
* one wins.
|
|
827
|
+
*
|
|
828
|
+
* @returns `undefined` if the path is absolute, does not start with a root name or leaves its root.
|
|
829
|
+
*/
|
|
830
|
+
resolveRootPrefixedPath(rootPrefixedPath) {
|
|
831
|
+
const path = new Path(Path.normalizePathSeparator(rootPrefixedPath)).normalize();
|
|
832
|
+
if (path.isAbsolute || Path.isDrive(path.toString().split('/')[0])) {
|
|
833
|
+
return undefined;
|
|
834
|
+
}
|
|
835
|
+
const segments = path.toString().split('/').filter(segment => segment.length > 0);
|
|
836
|
+
if (segments.includes('..')) {
|
|
837
|
+
return undefined;
|
|
838
|
+
}
|
|
839
|
+
const match = this.splitRootPrefixedPath(segments.join('/'));
|
|
840
|
+
if (!match) {
|
|
841
|
+
return undefined;
|
|
842
|
+
}
|
|
843
|
+
return match.rest ? match.rootUri.resolve(match.rest) : match.rootUri;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Resolves a path that contains the basename of a workspace root, preceded by nothing or by the
|
|
847
|
+
* trailing segments of the root's parent path, e.g. `bob/app/src` for the root `/home/bob/app`.
|
|
848
|
+
* Unlike {@link resolveRootPrefixedPath}, this does not depend on the current root names, so it
|
|
849
|
+
* also resolves paths that were prefixed with a root name before the workspace roots changed.
|
|
850
|
+
*
|
|
851
|
+
* @returns the distinct candidates in workspace order, which are several if the path is ambiguous,
|
|
852
|
+
* or none if the path is absolute, leaves its root or does not contain the basename of a root.
|
|
853
|
+
*/
|
|
854
|
+
resolveSupraRelativePath(supraRelativePath) {
|
|
855
|
+
const path = new Path(Path.normalizePathSeparator(supraRelativePath)).normalize();
|
|
856
|
+
const segments = path.toString().split('/').filter(segment => segment.length > 0);
|
|
857
|
+
if (path.isAbsolute || Path.isDrive(segments[0] ?? '') || segments.includes('..')) {
|
|
858
|
+
return [];
|
|
859
|
+
}
|
|
860
|
+
const candidates = [];
|
|
861
|
+
for (const root of this.tryGetRoots()) {
|
|
862
|
+
const candidate = this.resolveSupraRelativeSegments(root.resource, segments);
|
|
863
|
+
if (candidate && !candidates.some(other => other.isEqual(candidate))) {
|
|
864
|
+
candidates.push(candidate);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return candidates;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Resolves `segments` against the given root as described in {@link resolveSupraRelativePath}.
|
|
871
|
+
*/
|
|
872
|
+
resolveSupraRelativeSegments(rootUri, segments) {
|
|
873
|
+
const rootBasename = rootUri.path.base;
|
|
874
|
+
const rootPathSegments = rootUri.path.toString().split('/').filter(segment => segment.length > 0);
|
|
875
|
+
const rootPrecedingSegments = rootPathSegments.slice(0, rootPathSegments.length - 1);
|
|
876
|
+
for (let i = 0; i < segments.length; i++) {
|
|
877
|
+
if (segments[i] !== rootBasename) {
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
880
|
+
const pathPrecedingSegments = segments.slice(0, i);
|
|
881
|
+
if (pathPrecedingSegments.length > rootPrecedingSegments.length) {
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
const rootTail = rootPrecedingSegments.slice(rootPrecedingSegments.length - pathPrecedingSegments.length);
|
|
885
|
+
if (pathPrecedingSegments.every((segment, j) => segment === rootTail[j])) {
|
|
886
|
+
const rest = segments.slice(i + 1).join('/');
|
|
887
|
+
return rest ? rootUri.resolve(rest) : rootUri;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return undefined;
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Splits a `/`-separated path that starts with a root name, as in {@link getRootPrefixedPath}, into
|
|
894
|
+
* that root and the rest of the path, which is empty for a bare root name. The rest is not normalized,
|
|
895
|
+
* so it may as well be a glob. If more than one root name is a prefix of the path, the longest one wins.
|
|
896
|
+
*
|
|
897
|
+
* @returns `undefined` if the path does not start with a root name.
|
|
898
|
+
*/
|
|
899
|
+
splitRootPrefixedPath(rootPrefixedPath) {
|
|
900
|
+
const segments = rootPrefixedPath.split('/');
|
|
901
|
+
let match;
|
|
902
|
+
for (const [rootName, rootUri] of this.getRootNames()) {
|
|
903
|
+
const nameSegments = rootName.split('/');
|
|
904
|
+
const matches = nameSegments.length <= segments.length && nameSegments.every((segment, i) => segment === segments[i]);
|
|
905
|
+
if (matches && (!match || nameSegments.length > match.length)) {
|
|
906
|
+
match = { rootName, rootUri, length: nameSegments.length };
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return match && { rootName: match.rootName, rootUri: match.rootUri, rest: segments.slice(match.length).join('/') };
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Computes the name of a root from the roots that share its basename (including itself).
|
|
913
|
+
*/
|
|
914
|
+
computeRootName(root, peers) {
|
|
915
|
+
if (peers.length === 1) {
|
|
916
|
+
return root.path.base || root.path.toString();
|
|
917
|
+
}
|
|
918
|
+
const segmentsOf = (uri) => uri.path.toString().split('/').filter(segment => segment.length > 0);
|
|
919
|
+
const rootSegments = segmentsOf(root);
|
|
920
|
+
const peerSegments = peers.filter(peer => !peer.isEqual(root)).map(segmentsOf);
|
|
921
|
+
// A root with a shorter path than a peer, e.g. `/app` next to `/x/app`, is named by its whole path, `app`.
|
|
922
|
+
const maxLength = Math.max(rootSegments.length, ...peerSegments.map(segments => segments.length));
|
|
923
|
+
for (let length = 2; length <= maxLength; length++) {
|
|
924
|
+
const tail = rootSegments.slice(-length).join('/');
|
|
925
|
+
if (peerSegments.every(segments => segments.slice(-length).join('/') !== tail)) {
|
|
926
|
+
return tail;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
// The paths are the same, e.g. in different URI schemes, so only the full URI tells them apart.
|
|
930
|
+
return root.toString();
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Qualifies a root name that another root name starts with, e.g. `alice` next to `alice/app`, by more
|
|
934
|
+
* segments of its path, as a path in the one root would otherwise resolve to the other. If the root
|
|
935
|
+
* named `alice/app` is the `app` folder of the root named `alice`, the names are left as they are:
|
|
936
|
+
* the nested root is then also the one that {@link getRootPrefixedPath} names its files after.
|
|
937
|
+
*/
|
|
938
|
+
qualifyRootNames(names) {
|
|
939
|
+
const entries = Array.from(names, ([name, root]) => ({ name, root }));
|
|
940
|
+
let qualified = true;
|
|
941
|
+
while (qualified) {
|
|
942
|
+
qualified = false;
|
|
943
|
+
for (const shorter of entries) {
|
|
944
|
+
for (const longer of entries) {
|
|
945
|
+
if (longer.name.startsWith(shorter.name + '/')
|
|
946
|
+
&& !shorter.root.resolve(longer.name.substring(shorter.name.length + 1)).isEqual(longer.root)) {
|
|
947
|
+
qualified = this.qualifyRootName(shorter) || this.qualifyRootName(longer) || qualified;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return new Map(entries.map(({ name, root }) => [name, root]));
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Adds the next parent segment to the name of a root, unless the name is its whole path or its URI already.
|
|
956
|
+
*
|
|
957
|
+
* @returns whether the name was qualified
|
|
958
|
+
*/
|
|
959
|
+
qualifyRootName(entry) {
|
|
960
|
+
const segments = entry.root.path.toString().split('/').filter(segment => segment.length > 0);
|
|
961
|
+
const length = entry.name.split('/').length;
|
|
962
|
+
if (entry.name === entry.root.toString() || length >= segments.length) {
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
entry.name = segments.slice(-(length + 1)).join('/');
|
|
966
|
+
return true;
|
|
967
|
+
}
|
|
716
968
|
areWorkspaceRoots(uris) {
|
|
717
969
|
if (!uris.length) {
|
|
718
970
|
return false;
|
|
@@ -732,7 +984,7 @@ let WorkspaceService = class WorkspaceService {
|
|
|
732
984
|
return this.untitledWorkspaceService.isUntitledWorkspace(candidate);
|
|
733
985
|
}
|
|
734
986
|
async isSafeToReload(withURI) {
|
|
735
|
-
return !withURI || !this.untitledWorkspaceService.isUntitledWorkspace(withURI) || new
|
|
987
|
+
return !withURI || !this.untitledWorkspaceService.isUntitledWorkspace(withURI) || new URI(await this.getDefaultWorkspaceUri()).isEqual(withURI);
|
|
736
988
|
}
|
|
737
989
|
/**
|
|
738
990
|
*
|
|
@@ -743,106 +995,112 @@ let WorkspaceService = class WorkspaceService {
|
|
|
743
995
|
return this.schemaUpdater.updateSchema({ key, schema });
|
|
744
996
|
}
|
|
745
997
|
};
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
(0, inversify_1.inject)(file_service_1.FileService),
|
|
749
|
-
tslib_1.__metadata("design:type", file_service_1.FileService)
|
|
998
|
+
__decorate([
|
|
999
|
+
inject(FileService)
|
|
750
1000
|
], WorkspaceService.prototype, "fileService", void 0);
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
tslib_1.__metadata("design:type", Object)
|
|
1001
|
+
__decorate([
|
|
1002
|
+
inject(WorkspaceServer)
|
|
754
1003
|
], WorkspaceService.prototype, "server", void 0);
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
tslib_1.__metadata("design:type", Object)
|
|
1004
|
+
__decorate([
|
|
1005
|
+
inject(WindowService)
|
|
758
1006
|
], WorkspaceService.prototype, "windowService", void 0);
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
tslib_1.__metadata("design:type", Object)
|
|
1007
|
+
__decorate([
|
|
1008
|
+
inject(ILogger),
|
|
1009
|
+
named('workspace:WorkspaceService')
|
|
763
1010
|
], WorkspaceService.prototype, "logger", void 0);
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
tslib_1.__metadata("design:type", Object)
|
|
1011
|
+
__decorate([
|
|
1012
|
+
inject(WorkspacePreferences)
|
|
767
1013
|
], WorkspaceService.prototype, "preferences", void 0);
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
tslib_1.__metadata("design:type", Object)
|
|
1014
|
+
__decorate([
|
|
1015
|
+
inject(PreferenceService)
|
|
771
1016
|
], WorkspaceService.prototype, "preferenceImpl", void 0);
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
tslib_1.__metadata("design:type", Object)
|
|
1017
|
+
__decorate([
|
|
1018
|
+
inject(PreferenceSchemaService)
|
|
775
1019
|
], WorkspaceService.prototype, "schemaService", void 0);
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
tslib_1.__metadata("design:type", Object)
|
|
1020
|
+
__decorate([
|
|
1021
|
+
inject(EnvVariablesServer)
|
|
779
1022
|
], WorkspaceService.prototype, "envVariableServer", void 0);
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
tslib_1.__metadata("design:type", core_1.MessageService)
|
|
1023
|
+
__decorate([
|
|
1024
|
+
inject(MessageService)
|
|
783
1025
|
], WorkspaceService.prototype, "messageService", void 0);
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
tslib_1.__metadata("design:type", browser_1.LabelProvider)
|
|
1026
|
+
__decorate([
|
|
1027
|
+
inject(LabelProvider)
|
|
787
1028
|
], WorkspaceService.prototype, "labelProvider", void 0);
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
tslib_1.__metadata("design:type", Object)
|
|
1029
|
+
__decorate([
|
|
1030
|
+
inject(FileSystemPreferences)
|
|
791
1031
|
], WorkspaceService.prototype, "fsPreferences", void 0);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
tslib_1.__metadata("design:type", workspace_schema_updater_1.WorkspaceSchemaUpdater)
|
|
1032
|
+
__decorate([
|
|
1033
|
+
inject(WorkspaceSchemaUpdater)
|
|
795
1034
|
], WorkspaceService.prototype, "schemaUpdater", void 0);
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
tslib_1.__metadata("design:type", common_1.UntitledWorkspaceService)
|
|
1035
|
+
__decorate([
|
|
1036
|
+
inject(UntitledWorkspaceService)
|
|
799
1037
|
], WorkspaceService.prototype, "untitledWorkspaceService", void 0);
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
tslib_1.__metadata("design:type", common_1.WorkspaceFileService)
|
|
1038
|
+
__decorate([
|
|
1039
|
+
inject(WorkspaceFileService)
|
|
803
1040
|
], WorkspaceService.prototype, "workspaceFileService", void 0);
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
tslib_1.__metadata("design:type", window_title_service_1.WindowTitleService)
|
|
1041
|
+
__decorate([
|
|
1042
|
+
inject(WindowTitleService)
|
|
807
1043
|
], WorkspaceService.prototype, "windowTitleService", void 0);
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
tslib_1.__metadata("design:type", Object)
|
|
1044
|
+
__decorate([
|
|
1045
|
+
inject(ContributionProvider),
|
|
1046
|
+
named(WorkspaceOpenHandlerContribution)
|
|
812
1047
|
], WorkspaceService.prototype, "openHandlerContribution", void 0);
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
tslib_1.__metadata("design:type", Object)
|
|
1048
|
+
__decorate([
|
|
1049
|
+
inject(ContributionProvider),
|
|
1050
|
+
named(WorkspaceHandlingContribution)
|
|
817
1051
|
], WorkspaceService.prototype, "workspaceHandlingContribution", void 0);
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
tslib_1.__metadata("design:type", Function),
|
|
821
|
-
tslib_1.__metadata("design:paramtypes", []),
|
|
822
|
-
tslib_1.__metadata("design:returntype", void 0)
|
|
1052
|
+
__decorate([
|
|
1053
|
+
postConstruct()
|
|
823
1054
|
], WorkspaceService.prototype, "init", null);
|
|
824
|
-
|
|
825
|
-
|
|
1055
|
+
WorkspaceService = __decorate([
|
|
1056
|
+
injectable()
|
|
826
1057
|
], WorkspaceService);
|
|
827
|
-
|
|
1058
|
+
export { WorkspaceService };
|
|
1059
|
+
export var WorkspaceData;
|
|
828
1060
|
(function (WorkspaceData) {
|
|
829
|
-
|
|
1061
|
+
// The `name` of a folder is not validated when loading, so that a workspace file with an invalid name still loads,
|
|
1062
|
+
// and the folder falls back to its folder name, as in VS Code. The editor still validates it against `workspaceSchema`.
|
|
1063
|
+
const validateSchema = new Ajv().compile(withoutFolderName(workspaceSchema));
|
|
1064
|
+
function withoutFolderName(schema) {
|
|
1065
|
+
const copy = structuredClone(schema);
|
|
1066
|
+
delete copy.properties?.folders.items?.properties?.name;
|
|
1067
|
+
return copy;
|
|
1068
|
+
}
|
|
1069
|
+
function isValidFolderName(name) {
|
|
1070
|
+
return typeof name === 'string' && name.length > 0;
|
|
1071
|
+
}
|
|
830
1072
|
function is(data) {
|
|
831
1073
|
return !!validateSchema(data);
|
|
832
1074
|
}
|
|
833
1075
|
WorkspaceData.is = is;
|
|
1076
|
+
/**
|
|
1077
|
+
* Normalizes the given folder URI the same way as the URIs of the workspace roots, so that they can be compared.
|
|
1078
|
+
*/
|
|
1079
|
+
function normalizeFolderUri(folderUri) {
|
|
1080
|
+
return new URI(folderUri.endsWith('/') ? folderUri.slice(0, -1) : folderUri).normalizePath().toString();
|
|
1081
|
+
}
|
|
1082
|
+
WorkspaceData.normalizeFolderUri = normalizeFolderUri;
|
|
1083
|
+
/**
|
|
1084
|
+
* Builds the workspace data for the given folders. A folder given as an entry with a `name` keeps that name,
|
|
1085
|
+
* any other folder keeps the `name` of its entry in `additionalFields.folders`. Names that are not strings are dropped.
|
|
1086
|
+
*/
|
|
834
1087
|
function buildWorkspaceData(folders, additionalFields) {
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
if (
|
|
838
|
-
|
|
1088
|
+
const currentNames = new Map();
|
|
1089
|
+
for (const { path, name } of additionalFields?.folders ?? []) {
|
|
1090
|
+
if (isValidFolderName(name)) {
|
|
1091
|
+
currentNames.set(normalizeFolderUri(path), name);
|
|
839
1092
|
}
|
|
840
|
-
|
|
841
|
-
|
|
1093
|
+
}
|
|
1094
|
+
const roots = new Map();
|
|
1095
|
+
for (const folder of folders) {
|
|
1096
|
+
const path = typeof folder === 'string' ? folder : FileStat.is(folder) ? folder.resource.toString() : folder.path;
|
|
1097
|
+
if (!roots.has(path)) {
|
|
1098
|
+
const name = typeof folder === 'string' || FileStat.is(folder) ? undefined : folder.name;
|
|
1099
|
+
roots.set(path, isValidFolderName(name) ? name : currentNames.get(normalizeFolderUri(path)));
|
|
842
1100
|
}
|
|
843
1101
|
}
|
|
844
1102
|
const data = {
|
|
845
|
-
folders: Array.from(roots,
|
|
1103
|
+
folders: Array.from(roots, ([path, name]) => name ? { path, name } : { path })
|
|
846
1104
|
};
|
|
847
1105
|
if (additionalFields) {
|
|
848
1106
|
delete additionalFields.folders;
|
|
@@ -852,40 +1110,34 @@ var WorkspaceData;
|
|
|
852
1110
|
}
|
|
853
1111
|
WorkspaceData.buildWorkspaceData = buildWorkspaceData;
|
|
854
1112
|
function transformToRelative(data, workspaceFile) {
|
|
855
|
-
const
|
|
856
|
-
const workspaceFileUri = new
|
|
857
|
-
for (const { path } of data.folders) {
|
|
858
|
-
const folderUri = new
|
|
1113
|
+
const folders = [];
|
|
1114
|
+
const workspaceFileUri = new URI(workspaceFile ? workspaceFile.resource.toString() : '').withScheme('file');
|
|
1115
|
+
for (const { path, name } of data.folders) {
|
|
1116
|
+
const folderUri = new URI(path).withScheme('file');
|
|
859
1117
|
const rel = workspaceFileUri.parent.relative(folderUri);
|
|
860
|
-
|
|
861
|
-
folderUris.push(rel.toString());
|
|
862
|
-
}
|
|
863
|
-
else {
|
|
864
|
-
folderUris.push(folderUri.toString());
|
|
865
|
-
}
|
|
1118
|
+
folders.push({ path: rel ? rel.toString() : folderUri.toString(), name });
|
|
866
1119
|
}
|
|
867
|
-
return buildWorkspaceData(
|
|
1120
|
+
return buildWorkspaceData(folders, { ...data, folders: [] });
|
|
868
1121
|
}
|
|
869
1122
|
WorkspaceData.transformToRelative = transformToRelative;
|
|
870
1123
|
function transformToAbsolute(data, workspaceFile) {
|
|
871
1124
|
if (workspaceFile) {
|
|
872
1125
|
const folders = [];
|
|
873
|
-
for (const
|
|
874
|
-
const path = folder.path;
|
|
1126
|
+
for (const { path, name } of data.folders) {
|
|
875
1127
|
if (path.startsWith('file:///')) {
|
|
876
|
-
folders.push(path);
|
|
1128
|
+
folders.push({ path, name });
|
|
877
1129
|
}
|
|
878
1130
|
else {
|
|
879
1131
|
const absolutePath = workspaceFile.resource.withScheme('file').parent.resolveToAbsolute(path)?.toString();
|
|
880
1132
|
if (absolutePath) {
|
|
881
|
-
folders.push(absolutePath.toString());
|
|
1133
|
+
folders.push({ path: absolutePath.toString(), name });
|
|
882
1134
|
}
|
|
883
1135
|
}
|
|
884
1136
|
}
|
|
885
|
-
return Object.assign(data, buildWorkspaceData(folders, data));
|
|
1137
|
+
return Object.assign(data, buildWorkspaceData(folders, { ...data, folders: [] }));
|
|
886
1138
|
}
|
|
887
1139
|
return data;
|
|
888
1140
|
}
|
|
889
1141
|
WorkspaceData.transformToAbsolute = transformToAbsolute;
|
|
890
|
-
})(WorkspaceData || (
|
|
1142
|
+
})(WorkspaceData || (WorkspaceData = {}));
|
|
891
1143
|
//# sourceMappingURL=workspace-service.js.map
|