@theia/workspace 1.77.0-next.57 → 1.77.0-next.63

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.
@@ -27,9 +27,42 @@ export class WorkspaceUriLabelProviderContribution extends DefaultUriLabelProvid
27
27
  @inject(WorkspaceVariableContribution) protected readonly workspaceVariable: WorkspaceVariableContribution;
28
28
  @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
29
29
 
30
+ /**
31
+ * The names of the workspace roots by root URI, as last labeled.
32
+ */
33
+ protected rootNames = new Map<string, string>();
34
+
30
35
  @postConstruct()
31
36
  override init(): void {
32
- // no-op, backward compatibility
37
+ this.rootNames = this.getRootNamesByUri();
38
+ this.workspaceService.onWorkspaceChanged(() => this.updateRootNames());
39
+ }
40
+
41
+ protected getRootNamesByUri(): Map<string, string> {
42
+ return new Map(Array.from(this.workspaceService.getRootNames(), ([name, uri]) => [uri.toString(), name]));
43
+ }
44
+
45
+ /**
46
+ * 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.
48
+ */
49
+ protected updateRootNames(): void {
50
+ const rootNames = this.getRootNamesByUri();
51
+ const changed = new Set<string>();
52
+ for (const [uri, name] of rootNames) {
53
+ if (this.rootNames.get(uri) !== name) {
54
+ changed.add(uri);
55
+ }
56
+ }
57
+ this.rootNames = rootNames;
58
+ if (changed.size > 0) {
59
+ this.onDidChangeEmitter.fire({
60
+ affects: element => {
61
+ const uri = this.canHandle(element) > 0 ? this.getUri(element as URI | URIIconReference | FileStat) : undefined;
62
+ return !!uri && changed.has(uri.toString());
63
+ }
64
+ });
65
+ }
33
66
  }
34
67
 
35
68
  override canHandle(element: object): number {
@@ -43,7 +76,16 @@ export class WorkspaceUriLabelProviderContribution extends DefaultUriLabelProvid
43
76
  return super.getIcon(this.asURIIconReference(element));
44
77
  }
45
78
 
79
+ /**
80
+ * Names a workspace root by its unique name (see {@link WorkspaceService.getRootNames}), so that
81
+ * roots sharing a folder name can be told apart, e.g. `alice/app` and `bob/app`.
82
+ */
46
83
  override getName(element: URI | URIIconReference | FileStat): string | undefined {
84
+ const uri = this.getUri(element);
85
+ const rootName = uri && this.workspaceService.getRootName(uri);
86
+ if (rootName) {
87
+ return rootName;
88
+ }
47
89
  return super.getName(this.asURIIconReference(element));
48
90
  }
49
91