@theia/workspace 1.77.0-next.84 → 1.77.0-next.89
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/workspace-breadcrumbs-contribution.d.ts +2 -0
- package/lib/browser/workspace-breadcrumbs-contribution.d.ts.map +1 -1
- package/lib/browser/workspace-breadcrumbs-contribution.js +13 -0
- package/lib/browser/workspace-breadcrumbs-contribution.js.map +1 -1
- package/lib/browser/workspace-schema-updater.d.ts.map +1 -1
- package/lib/browser/workspace-schema-updater.js +4 -0
- package/lib/browser/workspace-schema-updater.js.map +1 -1
- package/lib/browser/workspace-service.d.ts +46 -2
- package/lib/browser/workspace-service.d.ts.map +1 -1
- package/lib/browser/workspace-service.js +114 -37
- package/lib/browser/workspace-service.js.map +1 -1
- package/lib/browser/workspace-service.spec.js +197 -1
- package/lib/browser/workspace-service.spec.js.map +1 -1
- package/lib/browser/workspace-uri-contribution.d.ts +12 -1
- package/lib/browser/workspace-uri-contribution.d.ts.map +1 -1
- package/lib/browser/workspace-uri-contribution.js +20 -7
- package/lib/browser/workspace-uri-contribution.js.map +1 -1
- package/lib/browser/workspace-uri-contribution.spec.js +25 -0
- package/lib/browser/workspace-uri-contribution.spec.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/workspace-breadcrumbs-contribution.ts +15 -0
- package/src/browser/workspace-schema-updater.ts +4 -0
- package/src/browser/workspace-service.spec.ts +236 -2
- package/src/browser/workspace-service.ts +134 -39
- package/src/browser/workspace-uri-contribution.spec.ts +28 -0
- package/src/browser/workspace-uri-contribution.ts +22 -7
|
@@ -58,6 +58,10 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
58
58
|
protected _workspace: FileStat | undefined;
|
|
59
59
|
|
|
60
60
|
protected _roots: FileStat[] = [];
|
|
61
|
+
/** The names of the roots, published together with `_roots` when `onWorkspaceChanged` fires. */
|
|
62
|
+
protected configuredRootNames = new Map<string, string>();
|
|
63
|
+
/** The names of the roots read by the last `computeRoots`, not yet published. */
|
|
64
|
+
protected computedRootNames = new Map<string, string>();
|
|
61
65
|
protected deferredRoots = new Deferred<FileStat[]>();
|
|
62
66
|
|
|
63
67
|
@inject(FileService)
|
|
@@ -300,7 +304,9 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
300
304
|
|
|
301
305
|
protected async updateRoots(): Promise<void> {
|
|
302
306
|
const newRoots = await this.computeRoots();
|
|
303
|
-
|
|
307
|
+
const newRootNames = this.computedRootNames;
|
|
308
|
+
// Compare against the published names, so that overlapping calls fire only once for a rename
|
|
309
|
+
let rootsChanged = !this.areConfiguredRootNamesEqual(this.configuredRootNames, newRootNames);
|
|
304
310
|
if (newRoots.length !== this._roots.length || newRoots.length === 0) {
|
|
305
311
|
rootsChanged = true;
|
|
306
312
|
} else {
|
|
@@ -313,6 +319,7 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
313
319
|
}
|
|
314
320
|
if (rootsChanged) {
|
|
315
321
|
this._roots = newRoots;
|
|
322
|
+
this.configuredRootNames = newRootNames;
|
|
316
323
|
this.rootNamesCache = undefined;
|
|
317
324
|
this.deferredRoots.resolve(this._roots); // in order to resolve first
|
|
318
325
|
this.deferredRoots = new Deferred<FileStat[]>();
|
|
@@ -321,28 +328,44 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
321
328
|
}
|
|
322
329
|
}
|
|
323
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Computes the workspace roots. Also sets `computedRootNames` to the names given to the roots in the workspace file,
|
|
333
|
+
* which `updateRoots` publishes with the roots, see `getConfiguredRootName`.
|
|
334
|
+
* An override that does not call `super` has to set `computedRootNames` itself, otherwise the names of the previous roots remain.
|
|
335
|
+
*/
|
|
324
336
|
protected async computeRoots(): Promise<FileStat[]> {
|
|
325
337
|
const roots: FileStat[] = [];
|
|
338
|
+
const rootNames = new Map<string, string>();
|
|
326
339
|
if (this._workspace) {
|
|
327
340
|
if (this._workspace.isDirectory) {
|
|
341
|
+
this.computedRootNames = rootNames;
|
|
328
342
|
return [this._workspace];
|
|
329
343
|
}
|
|
330
344
|
|
|
331
345
|
const workspaceData = await this.getWorkspaceDataFromFile();
|
|
332
346
|
if (workspaceData) {
|
|
333
|
-
for (const { path } of workspaceData.folders) {
|
|
347
|
+
for (const { path, name } of workspaceData.folders) {
|
|
334
348
|
const valid = await this.toValidRoot(path);
|
|
335
349
|
if (valid) {
|
|
336
350
|
roots.push(valid);
|
|
337
351
|
} else {
|
|
338
352
|
roots.push(FileStat.dir(path));
|
|
339
353
|
}
|
|
354
|
+
// `getWorkspaceDataFromFile` already drops invalid names, but an override of it may not
|
|
355
|
+
if (typeof name === 'string' && name) {
|
|
356
|
+
rootNames.set(WorkspaceData.normalizeFolderUri(path), name);
|
|
357
|
+
}
|
|
340
358
|
}
|
|
341
359
|
}
|
|
342
360
|
}
|
|
361
|
+
this.computedRootNames = rootNames;
|
|
343
362
|
return roots;
|
|
344
363
|
}
|
|
345
364
|
|
|
365
|
+
protected areConfiguredRootNamesEqual(names: Map<string, string>, otherNames: Map<string, string>): boolean {
|
|
366
|
+
return names.size === otherNames.size && Array.from(names).every(([root, name]) => otherNames.get(root) === name);
|
|
367
|
+
}
|
|
368
|
+
|
|
346
369
|
protected async getWorkspaceDataFromFile(): Promise<WorkspaceData | undefined> {
|
|
347
370
|
if (this._workspace && await this.fileService.exists(this._workspace.resource)) {
|
|
348
371
|
if (this._workspace.isDirectory) {
|
|
@@ -537,7 +560,12 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
537
560
|
}
|
|
538
561
|
}
|
|
539
562
|
|
|
540
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Removes `deleteCount` roots starting at `start` and inserts the given roots there, and writes the result to the workspace file.
|
|
565
|
+
* A root to add can be given a name, which is written to the workspace file as the `name` of its folder entry.
|
|
566
|
+
* @returns the URIs of the removed roots
|
|
567
|
+
*/
|
|
568
|
+
async spliceRoots(start: number, deleteCount?: number, ...rootsToAdd: (URI | WorkspaceRootToAdd)[]): Promise<URI[]> {
|
|
541
569
|
if (!this._workspace || this._workspace.isDirectory) {
|
|
542
570
|
const untitledWorkspace = await this.getUntitledWorkspace();
|
|
543
571
|
await this.save(untitledWorkspace);
|
|
@@ -545,23 +573,35 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
545
573
|
throw new Error('Could not create new untitled workspace');
|
|
546
574
|
}
|
|
547
575
|
}
|
|
548
|
-
const
|
|
549
|
-
const
|
|
576
|
+
const roots = this._roots.map(root => root.resource.toString());
|
|
577
|
+
const toRemove = roots.splice(start, deleteCount || 0);
|
|
578
|
+
// Deduplicate against the remaining roots only, so that a root removed by this call can be added again, e.g. to rename it.
|
|
579
|
+
const dedup = new Set<string>(roots);
|
|
550
580
|
const toAdd: string[] = [];
|
|
581
|
+
const namesToAdd = new Map<string, string>();
|
|
551
582
|
for (const root of rootsToAdd) {
|
|
552
|
-
const uri = root
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
583
|
+
const { uri, name } = root instanceof URI ? { uri: root, name: undefined } : root;
|
|
584
|
+
const uriString = uri.toString();
|
|
585
|
+
if (!dedup.has(uriString)) {
|
|
586
|
+
dedup.add(uriString);
|
|
587
|
+
toAdd.push(uriString);
|
|
588
|
+
if (name) {
|
|
589
|
+
namesToAdd.set(uriString, name);
|
|
590
|
+
}
|
|
556
591
|
}
|
|
557
592
|
}
|
|
558
|
-
|
|
593
|
+
roots.splice(start, 0, ...toAdd);
|
|
559
594
|
if (!toRemove.length && !toAdd.length) {
|
|
560
595
|
return [];
|
|
561
596
|
}
|
|
562
597
|
|
|
563
598
|
const currentData = await this.getWorkspaceDataFromFile();
|
|
564
|
-
|
|
599
|
+
if (currentData) {
|
|
600
|
+
// 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
|
|
601
|
+
const added = new Set(toAdd.map(root => WorkspaceData.normalizeFolderUri(root)));
|
|
602
|
+
currentData.folders = currentData.folders.filter(folder => !added.has(WorkspaceData.normalizeFolderUri(folder.path)));
|
|
603
|
+
}
|
|
604
|
+
const newData = WorkspaceData.buildWorkspaceData(roots.map(path => ({ path, name: namesToAdd.get(path) })), currentData);
|
|
565
605
|
await this.writeWorkspaceFile(this._workspace, newData);
|
|
566
606
|
await this.updateWorkspace();
|
|
567
607
|
return toRemove.map(root => new URI(root));
|
|
@@ -625,12 +665,8 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
625
665
|
if (!uri) {
|
|
626
666
|
return undefined;
|
|
627
667
|
}
|
|
628
|
-
let uriStr = uri.toString();
|
|
629
668
|
try {
|
|
630
|
-
|
|
631
|
-
uriStr = uriStr.slice(0, -1);
|
|
632
|
-
}
|
|
633
|
-
const normalizedUri = new URI(uriStr).normalizePath();
|
|
669
|
+
const normalizedUri = new URI(WorkspaceData.normalizeFolderUri(uri.toString()));
|
|
634
670
|
return await this.fileService.resolve(normalizedUri);
|
|
635
671
|
} catch (error) {
|
|
636
672
|
return undefined;
|
|
@@ -803,6 +839,35 @@ export class WorkspaceService implements FrontendApplicationContribution, Worksp
|
|
|
803
839
|
return rootUris.sort((r1, r2) => r2.toString().length - r1.toString().length)[0];
|
|
804
840
|
}
|
|
805
841
|
|
|
842
|
+
/**
|
|
843
|
+
* Returns the name given to the workspace root by the `name` property of its folder entry in the workspace file.
|
|
844
|
+
* This is the name shown for the root, as `WorkspaceFolder.name` in VS Code. Unlike the unique names of {@link getRootNames},
|
|
845
|
+
* it is chosen by the user and not used to address files.
|
|
846
|
+
* @param rootUri URI of the workspace root
|
|
847
|
+
* @returns the name of the root, or `undefined` if the root has no name or is not a workspace root
|
|
848
|
+
*/
|
|
849
|
+
getConfiguredRootName(rootUri: URI): string | undefined {
|
|
850
|
+
if (this.configuredRootNames.size === 0) {
|
|
851
|
+
return undefined;
|
|
852
|
+
}
|
|
853
|
+
// Called for every file label, e.g. by `getDetails`, so normalize each root URI only once per set of names
|
|
854
|
+
if (this.configuredRootNamesByUri?.names !== this.configuredRootNames) {
|
|
855
|
+
this.configuredRootNamesByUri = { names: this.configuredRootNames, byUri: new Map() };
|
|
856
|
+
}
|
|
857
|
+
const key = rootUri.toString();
|
|
858
|
+
const { byUri } = this.configuredRootNamesByUri;
|
|
859
|
+
if (!byUri.has(key)) {
|
|
860
|
+
byUri.set(key, this.configuredRootNames.get(WorkspaceData.normalizeFolderUri(key)));
|
|
861
|
+
}
|
|
862
|
+
return byUri.get(key);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* The configured root names by the string of a root URI as passed to `getConfiguredRootName`,
|
|
867
|
+
* for the `configuredRootNames` they were looked up in.
|
|
868
|
+
*/
|
|
869
|
+
protected configuredRootNamesByUri: { names: Map<string, string>; byUri: Map<string, string | undefined> } | undefined;
|
|
870
|
+
|
|
806
871
|
/**
|
|
807
872
|
* Returns the relative path of the given file to the workspace root.
|
|
808
873
|
* @param uri URI of the file
|
|
@@ -1099,6 +1164,12 @@ export interface WorkspaceInput {
|
|
|
1099
1164
|
|
|
1100
1165
|
}
|
|
1101
1166
|
|
|
1167
|
+
export interface WorkspaceRootToAdd {
|
|
1168
|
+
uri: URI;
|
|
1169
|
+
/** The name of the root, written to the workspace file as the `name` of its folder entry. */
|
|
1170
|
+
name?: string;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1102
1173
|
export interface WorkspaceData {
|
|
1103
1174
|
folders: Array<{ path: string, name?: string }>;
|
|
1104
1175
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1106,23 +1177,52 @@ export interface WorkspaceData {
|
|
|
1106
1177
|
}
|
|
1107
1178
|
|
|
1108
1179
|
export namespace WorkspaceData {
|
|
1109
|
-
|
|
1180
|
+
// The `name` of a folder is not validated when loading, so that a workspace file with an invalid name still loads,
|
|
1181
|
+
// and the folder falls back to its folder name, as in VS Code. The editor still validates it against `workspaceSchema`.
|
|
1182
|
+
const validateSchema = new Ajv().compile(withoutFolderName(workspaceSchema));
|
|
1183
|
+
|
|
1184
|
+
function withoutFolderName(schema: IJSONSchema): IJSONSchema {
|
|
1185
|
+
const copy: IJSONSchema = structuredClone(schema);
|
|
1186
|
+
delete (copy.properties?.folders.items as IJSONSchema | undefined)?.properties?.name;
|
|
1187
|
+
return copy;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function isValidFolderName(name: unknown): name is string {
|
|
1191
|
+
return typeof name === 'string' && name.length > 0;
|
|
1192
|
+
}
|
|
1110
1193
|
|
|
1111
1194
|
export function is(data: unknown): data is WorkspaceData {
|
|
1112
1195
|
return !!validateSchema(data);
|
|
1113
1196
|
}
|
|
1114
1197
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1198
|
+
/**
|
|
1199
|
+
* Normalizes the given folder URI the same way as the URIs of the workspace roots, so that they can be compared.
|
|
1200
|
+
*/
|
|
1201
|
+
export function normalizeFolderUri(folderUri: string): string {
|
|
1202
|
+
return new URI(folderUri.endsWith('/') ? folderUri.slice(0, -1) : folderUri).normalizePath().toString();
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* Builds the workspace data for the given folders. A folder given as an entry with a `name` keeps that name,
|
|
1207
|
+
* any other folder keeps the `name` of its entry in `additionalFields.folders`. Names that are not strings are dropped.
|
|
1208
|
+
*/
|
|
1209
|
+
export function buildWorkspaceData(folders: string[] | FileStat[] | WorkspaceData['folders'], additionalFields?: Partial<WorkspaceData>): WorkspaceData {
|
|
1210
|
+
const currentNames = new Map<string, string>();
|
|
1211
|
+
for (const { path, name } of additionalFields?.folders ?? []) {
|
|
1212
|
+
if (isValidFolderName(name)) {
|
|
1213
|
+
currentNames.set(normalizeFolderUri(path), name);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
const roots = new Map<string, string | undefined>();
|
|
1217
|
+
for (const folder of folders) {
|
|
1218
|
+
const path = typeof folder === 'string' ? folder : FileStat.is(folder) ? folder.resource.toString() : folder.path;
|
|
1219
|
+
if (!roots.has(path)) {
|
|
1220
|
+
const name = typeof folder === 'string' || FileStat.is(folder) ? undefined : folder.name;
|
|
1221
|
+
roots.set(path, isValidFolderName(name) ? name : currentNames.get(normalizeFolderUri(path)));
|
|
1122
1222
|
}
|
|
1123
1223
|
}
|
|
1124
1224
|
const data: WorkspaceData = {
|
|
1125
|
-
folders: Array.from(roots,
|
|
1225
|
+
folders: Array.from(roots, ([path, name]) => name ? { path, name } : { path })
|
|
1126
1226
|
};
|
|
1127
1227
|
if (additionalFields) {
|
|
1128
1228
|
delete additionalFields.folders;
|
|
@@ -1132,36 +1232,31 @@ export namespace WorkspaceData {
|
|
|
1132
1232
|
}
|
|
1133
1233
|
|
|
1134
1234
|
export function transformToRelative(data: WorkspaceData, workspaceFile?: FileStat): WorkspaceData {
|
|
1135
|
-
const
|
|
1235
|
+
const folders: WorkspaceData['folders'] = [];
|
|
1136
1236
|
const workspaceFileUri = new URI(workspaceFile ? workspaceFile.resource.toString() : '').withScheme('file');
|
|
1137
|
-
for (const { path } of data.folders) {
|
|
1237
|
+
for (const { path, name } of data.folders) {
|
|
1138
1238
|
const folderUri = new URI(path).withScheme('file');
|
|
1139
1239
|
const rel = workspaceFileUri.parent.relative(folderUri);
|
|
1140
|
-
|
|
1141
|
-
folderUris.push(rel.toString());
|
|
1142
|
-
} else {
|
|
1143
|
-
folderUris.push(folderUri.toString());
|
|
1144
|
-
}
|
|
1240
|
+
folders.push({ path: rel ? rel.toString() : folderUri.toString(), name });
|
|
1145
1241
|
}
|
|
1146
|
-
return buildWorkspaceData(
|
|
1242
|
+
return buildWorkspaceData(folders, { ...data, folders: [] });
|
|
1147
1243
|
}
|
|
1148
1244
|
|
|
1149
1245
|
export function transformToAbsolute(data: WorkspaceData, workspaceFile?: BaseStat): WorkspaceData {
|
|
1150
1246
|
if (workspaceFile) {
|
|
1151
|
-
const folders:
|
|
1152
|
-
for (const
|
|
1153
|
-
const path = folder.path;
|
|
1247
|
+
const folders: WorkspaceData['folders'] = [];
|
|
1248
|
+
for (const { path, name } of data.folders) {
|
|
1154
1249
|
if (path.startsWith('file:///')) {
|
|
1155
|
-
folders.push(path);
|
|
1250
|
+
folders.push({ path, name });
|
|
1156
1251
|
} else {
|
|
1157
1252
|
const absolutePath = workspaceFile.resource.withScheme('file').parent.resolveToAbsolute(path)?.toString();
|
|
1158
1253
|
if (absolutePath) {
|
|
1159
|
-
folders.push(absolutePath.toString());
|
|
1254
|
+
folders.push({ path: absolutePath.toString(), name });
|
|
1160
1255
|
}
|
|
1161
1256
|
}
|
|
1162
1257
|
|
|
1163
1258
|
}
|
|
1164
|
-
return Object.assign(data, buildWorkspaceData(folders, data));
|
|
1259
|
+
return Object.assign(data, buildWorkspaceData(folders, { ...data, folders: [] }));
|
|
1165
1260
|
}
|
|
1166
1261
|
return data;
|
|
1167
1262
|
}
|
|
@@ -173,6 +173,26 @@ describe('WorkspaceUriLabelProviderContribution class', () => {
|
|
|
173
173
|
expect(events.some(event => event.affects(new URI('file:///home/other')))).to.be.false;
|
|
174
174
|
expect(labelProvider.getName(new URI('file:///home/alice/app'))).eq('alice/app');
|
|
175
175
|
});
|
|
176
|
+
|
|
177
|
+
it('should not return the name given to a workspace root in the workspace file', () => {
|
|
178
|
+
// The name is only shown where the folder is referred to as a root, e.g. not when browsing its parent in a file dialog.
|
|
179
|
+
setRoots([FileStat.dir('file:///home/alice/app'), FileStat.dir('file:///home/bob/lib')]);
|
|
180
|
+
sinon.stub(workspaceService, 'getConfiguredRootName').callsFake(uri => uri.isEqual(new URI('file:///home/alice/app')) ? 'My App' : undefined);
|
|
181
|
+
expect(labelProvider.getName(new URI('file:///home/alice/app'))).eq('app');
|
|
182
|
+
expect(labelProvider.getName(FileStat.dir('file:///home/alice/app'))).eq('app');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should notify a change of the labels of a workspace root and its files when the root is given a name in the workspace file', () => {
|
|
186
|
+
setRoots([FileStat.dir('file:///home/alice/app'), FileStat.dir('file:///home/bob/lib')]);
|
|
187
|
+
workspaceService['onWorkspaceChangeEmitter'].fire(roots);
|
|
188
|
+
const events: DidChangeLabelEvent[] = [];
|
|
189
|
+
labelProvider.onDidChange(event => events.push(event));
|
|
190
|
+
sinon.stub(workspaceService, 'getConfiguredRootName').callsFake(uri => uri.isEqual(new URI('file:///home/alice/app')) ? 'My App' : undefined);
|
|
191
|
+
workspaceService['onWorkspaceChangeEmitter'].fire(roots);
|
|
192
|
+
expect(events.some(event => event.affects(new URI('file:///home/alice/app')))).to.be.true;
|
|
193
|
+
expect(events.some(event => event.affects(new URI('file:///home/alice/app/src/index.ts')))).to.be.true;
|
|
194
|
+
expect(events.some(event => event.affects(new URI('file:///home/bob/lib')))).to.be.false;
|
|
195
|
+
});
|
|
176
196
|
});
|
|
177
197
|
|
|
178
198
|
describe('getDetails()', () => {
|
|
@@ -180,6 +200,14 @@ describe('WorkspaceUriLabelProviderContribution class', () => {
|
|
|
180
200
|
setRoots([FileStat.dir('file:///home/alice/app'), FileStat.dir('file:///home/bob/app')]);
|
|
181
201
|
expect(labelProvider.getDetails(new URI('file:///home/bob/app/src/index.ts'))).eq('bob/app • src');
|
|
182
202
|
});
|
|
203
|
+
|
|
204
|
+
it('should prefix the path of a file with the name given to its workspace root in the workspace file', () => {
|
|
205
|
+
setRoots([FileStat.dir('file:///home/alice/app'), FileStat.dir('file:///home/bob/app')]);
|
|
206
|
+
sinon.stub(workspaceService, 'getConfiguredRootName').callsFake(uri => uri.isEqual(new URI('file:///home/alice/app')) ? 'My App' : undefined);
|
|
207
|
+
expect(labelProvider.getDetails(new URI('file:///home/alice/app/src/index.ts'))).eq('My App • src');
|
|
208
|
+
// A root without a name keeps its unique name
|
|
209
|
+
expect(labelProvider.getDetails(new URI('file:///home/bob/app/src/index.ts'))).eq('bob/app • src');
|
|
210
|
+
});
|
|
183
211
|
});
|
|
184
212
|
|
|
185
213
|
describe('getLongName()', () => {
|
|
@@ -38,28 +38,34 @@ export class WorkspaceUriLabelProviderContribution extends DefaultUriLabelProvid
|
|
|
38
38
|
this.workspaceService.onWorkspaceChanged(() => this.updateRootNames());
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Returns the names shown for the workspace roots by root URI: the name given to a root in the workspace file,
|
|
43
|
+
* or else its unique name.
|
|
44
|
+
*/
|
|
41
45
|
protected getRootNamesByUri(): Map<string, string> {
|
|
42
|
-
return new Map(Array.from(this.workspaceService.getRootNames(),
|
|
46
|
+
return new Map(Array.from(this.workspaceService.getRootNames(),
|
|
47
|
+
([name, uri]) => [uri.toString(), this.workspaceService.getConfiguredRootName(uri) ?? name]));
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
/**
|
|
46
51
|
* Notifies a change of the labels of the roots whose names changed, such as a root named `app` that
|
|
47
|
-
* is named `alice/app` once a root `bob/app` is added.
|
|
52
|
+
* is named `alice/app` once a root `bob/app` is added, or a root that is given a name in the workspace file.
|
|
53
|
+
* The labels of the files in such a root change as well, as their details and breadcrumbs show the name of the root.
|
|
48
54
|
*/
|
|
49
55
|
protected updateRootNames(): void {
|
|
50
56
|
const rootNames = this.getRootNamesByUri();
|
|
51
|
-
const changed =
|
|
57
|
+
const changed: URI[] = [];
|
|
52
58
|
for (const [uri, name] of rootNames) {
|
|
53
59
|
if (this.rootNames.get(uri) !== name) {
|
|
54
|
-
changed.
|
|
60
|
+
changed.push(new URI(uri));
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
this.rootNames = rootNames;
|
|
58
|
-
if (changed.
|
|
64
|
+
if (changed.length > 0) {
|
|
59
65
|
this.onDidChangeEmitter.fire({
|
|
60
66
|
affects: element => {
|
|
61
67
|
const uri = this.canHandle(element) > 0 ? this.getUri(element as URI | URIIconReference | FileStat) : undefined;
|
|
62
|
-
return !!uri && changed.
|
|
68
|
+
return !!uri && changed.some(root => root.isEqualOrParent(uri));
|
|
63
69
|
}
|
|
64
70
|
});
|
|
65
71
|
}
|
|
@@ -112,13 +118,22 @@ export class WorkspaceUriLabelProviderContribution extends DefaultUriLabelProvid
|
|
|
112
118
|
// Parent in order to omit the name - that's what comes out of `getName`, and `getDetails` should supplement, not duplicate.
|
|
113
119
|
const relativePath = uri && this.workspaceVariable.getWorkspaceRelativePath(uri.parent);
|
|
114
120
|
if (relativePath !== undefined) {
|
|
115
|
-
const prefix = this.workspaceService.tryGetRoots().length > 1 ? this.
|
|
121
|
+
const prefix = this.workspaceService.tryGetRoots().length > 1 ? this.getRootDisplayName(this.workspaceVariable.getWorkspaceRootUri(uri)!) : '';
|
|
116
122
|
const separator = prefix && relativePath ? ' • ' : '';
|
|
117
123
|
return prefix + separator + relativePath;
|
|
118
124
|
}
|
|
119
125
|
return this.getLongName(uri.parent);
|
|
120
126
|
}
|
|
121
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Returns the name given to the workspace root in the workspace file, or else its name from `getName`.
|
|
130
|
+
* Only used where the root is referred to as a root: elsewhere, e.g. in a file dialog, the name from the workspace file
|
|
131
|
+
* is not shown, as in VS Code.
|
|
132
|
+
*/
|
|
133
|
+
protected getRootDisplayName(rootUri: URI): string | undefined {
|
|
134
|
+
return this.workspaceService.getConfiguredRootName(rootUri) ?? this.getName(rootUri);
|
|
135
|
+
}
|
|
136
|
+
|
|
122
137
|
protected asURIIconReference(element: URI | URIIconReference | FileStat): URI | URIIconReference {
|
|
123
138
|
if (FileStat.is(element)) {
|
|
124
139
|
return URIIconReference.create(element.isDirectory ? 'folder' : 'file', element.resource);
|