Skip to content

Commit 624385f

Browse files
Improves visuals and descriptions for linked workspaces
1 parent da87575 commit 624385f

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11198,7 +11198,7 @@
1119811198
},
1119911199
{
1120011200
"command": "gitlens.views.workspaces.addReposFromLinked",
11201-
"when": "viewItem =~ /gitlens:repositories\\b(?=.*?\\b\\+synced\\b)/",
11201+
"when": "viewItem =~ /gitlens:repositories\\b(?=.*?\\b\\+linked\\b)(?=.*?\\b\\+current\\b)/",
1120211202
"group": "1_gitlens_actions@3"
1120311203
},
1120411204
{
@@ -11218,7 +11218,7 @@
1121811218
},
1121911219
{
1122011220
"command": "gitlens.views.workspaces.changeAutoAddSetting",
11221-
"when": "viewItem =~ /(gitlens:workspace\\b(?=.*?\\b\\+(cloud|local)\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+hasPath\\b)|gitlens:repositories\\b(?=.*?\\b\\+synced\\b))/",
11221+
"when": "viewItem =~ /(gitlens:workspace\\b(?=.*?\\b\\+(cloud|local)\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+hasPath\\b)|gitlens:repositories\\b(?=.*?\\b\\+linked\\b))/",
1122211222
"group": "2_gitlens_quickopen@6"
1122311223
},
1122411224
{

src/plus/workspaces/workspacesService.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class WorkspacesService implements Disposable {
5050
private _workspacesPathProvider: WorkspacesPathMappingProvider;
5151
private _currentWorkspaceId: string | undefined;
5252
private _currentWorkspaceAutoAddSetting: WorkspaceAutoAddSetting = WorkspaceAutoAddSetting.Disabled;
53+
private _currentWorkspace: CloudWorkspace | LocalWorkspace | undefined;
5354

5455
constructor(
5556
private readonly container: Container,
@@ -75,6 +76,10 @@ export class WorkspacesService implements Disposable {
7576
return this._currentWorkspaceId;
7677
}
7778

79+
get currentWorkspace(): CloudWorkspace | LocalWorkspace | undefined {
80+
return this._currentWorkspace;
81+
}
82+
7883
private onSubscriptionChanged(event: SubscriptionChangeEvent): void {
7984
if (
8085
event.current.account == null ||
@@ -211,6 +216,15 @@ export class WorkspacesService implements Disposable {
211216
getWorkspacesResponse.localWorkspaceInfo = loadLocalWorkspacesResponse.localWorkspaceInfo;
212217
}
213218

219+
const currentWorkspace = [...(this._cloudWorkspaces ?? []), ...(this._localWorkspaces ?? [])].find(
220+
workspace => workspace.current,
221+
);
222+
223+
if (currentWorkspace != null) {
224+
this._currentWorkspaceId = currentWorkspace.id;
225+
this._currentWorkspace = currentWorkspace;
226+
}
227+
214228
getWorkspacesResponse.cloudWorkspaces = this._cloudWorkspaces ?? [];
215229
getWorkspacesResponse.localWorkspaces = this._localWorkspaces ?? [];
216230

@@ -261,11 +275,13 @@ export class WorkspacesService implements Disposable {
261275

262276
if (
263277
(!options?.force && this._currentWorkspaceAutoAddSetting === WorkspaceAutoAddSetting.Disabled) ||
264-
!currentWorkspace.current
278+
!currentWorkspace?.current
265279
) {
266280
return;
267281
}
268282

283+
this._currentWorkspace = currentWorkspace;
284+
269285
if (!(await currentWorkspace.getRepositoryDescriptors())?.length) return;
270286

271287
const repositories = [
@@ -281,7 +297,12 @@ export class WorkspacesService implements Disposable {
281297
currentWorkspaceRepositoryIdMap.set(repository.id, repository);
282298
}
283299
const repositoriesToAdd = repositories.filter(r => !currentWorkspaceRepositoryIdMap.has(r.id));
284-
if (repositoriesToAdd.length === 0) return;
300+
if (repositoriesToAdd.length === 0) {
301+
if (options?.force) {
302+
void window.showInformationMessage('No new repositories found to add.', { modal: true });
303+
}
304+
return;
305+
}
285306
let chosenRepoPaths: string[] = [];
286307
if (!options?.force && this._currentWorkspaceAutoAddSetting === WorkspaceAutoAddSetting.Prompt) {
287308
const addChoice = await window.showInformationMessage(

src/views/nodes/repositoriesNode.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TextEditor } from 'vscode';
2-
import { Disposable, TreeItem, TreeItemCollapsibleState, window, workspace } from 'vscode';
2+
import { Disposable, TreeItem, TreeItemCollapsibleState, Uri, window, workspace } from 'vscode';
33
import type { RepositoriesChangeEvent } from '../../git/gitProviderService';
44
import { GitUri, unknownGitUri } from '../../git/gitUri';
55
import { gate } from '../../system/decorators/gate';
@@ -51,7 +51,8 @@ export class RepositoriesNode extends SubscribeableViewNode<ViewsWithRepositorie
5151

5252
getTreeItem(): TreeItem {
5353
const isInWorkspacesView = this.view instanceof WorkspacesView;
54-
const isSyncedWorkspace = isInWorkspacesView && this.view.container.workspaces.currentWorkspaceId != null;
54+
const isLinkedWorkspace = isInWorkspacesView && this.view.container.workspaces.currentWorkspaceId != null;
55+
const isCurrentLinkedWorkspace = isLinkedWorkspace && this.view.container.workspaces.currentWorkspace != null;
5556
const item = new TreeItem(
5657
isInWorkspacesView ? 'Current Window' : 'Repositories',
5758
isInWorkspacesView ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.Expanded,
@@ -66,8 +67,13 @@ export class RepositoriesNode extends SubscribeableViewNode<ViewsWithRepositorie
6667
contextValue += '+workspaces';
6768
}
6869

69-
if (isSyncedWorkspace) {
70-
contextValue += '+synced';
70+
if (isLinkedWorkspace) {
71+
contextValue += '+linked';
72+
}
73+
74+
if (isCurrentLinkedWorkspace) {
75+
contextValue += '+current';
76+
item.resourceUri = Uri.parse('gitlens-view://workspaces/workspace/current');
7177
}
7278

7379
item.contextValue = contextValue;

src/views/nodes/workspaceNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ export class WorkspaceNode extends ViewNode<WorkspacesView> {
8989

9090
let contextValue = `${ContextValues.Workspace}`;
9191
item.resourceUri = undefined;
92+
const descriptionItems = [];
9293
if (this.workspace.type === WorkspaceType.Cloud) {
9394
contextValue += '+cloud';
9495
} else {
9596
contextValue += '+local';
9697
}
9798
if (this.workspace.current) {
9899
contextValue += '+current';
100+
descriptionItems.push('current');
99101
item.resourceUri = Uri.parse('gitlens-view://workspaces/workspace/current');
100102
}
101103
if (this.workspace.localPath != null) {
@@ -120,8 +122,10 @@ export class WorkspaceNode extends ViewNode<WorkspacesView> {
120122
}`;
121123

122124
if (this.workspace.type === WorkspaceType.Cloud && this.workspace.organizationId != null) {
123-
item.description = 'shared';
125+
descriptionItems.push('shared');
124126
}
127+
128+
item.description = descriptionItems.join(', ');
125129
return item;
126130
}
127131

0 commit comments

Comments
 (0)