Pārlūkot izejas kodu

Fixes workspaces repo add/remove event handling

main
Eric Amodio pirms 1 gada
vecāks
revīzija
70957a3741
4 mainītis faili ar 79 papildinājumiem un 26 dzēšanām
  1. +17
    -7
      src/git/gitProviderService.ts
  2. +2
    -3
      src/views/nodes/repositoriesNode.ts
  3. +20
    -5
      src/views/nodes/viewNode.ts
  4. +40
    -11
      src/views/nodes/workspaceNode.ts

+ 17
- 7
src/git/gitProviderService.ts Parādīt failu

@ -620,17 +620,18 @@ export class GitProviderService implements Disposable {
const added: Repository[] = [];
for (const repository of repositories) {
if (this._repositories.add(repository)) {
this._repositories.add(repository);
if (!repository.closed) {
added.push(repository);
}
}
this.updateContext();
if (added.length === 0) return;
// Defer the event trigger enough to let everything unwind
queueMicrotask(() => this.fireRepositoriesChanged(added));
if (added.length) {
// Defer the event trigger enough to let everything unwind
queueMicrotask(() => this.fireRepositoriesChanged(added));
}
} finally {
deferred.fulfill();
}
@ -2400,15 +2401,24 @@ export class GitProviderService implements Disposable {
Logger.log(scope, `Repository found in '${repoUri.toString(true)}'`);
const repositories = provider.openRepository(root?.folder, repoUri, false, undefined, closed);
const added: Repository[] = [];
for (const repository of repositories) {
this._repositories.add(repository);
if (!repository.closed) {
added.push(repository);
}
}
this._pendingRepositories.delete(key);
this.updateContext();
// Send a notification that the repositories changed
queueMicrotask(() => this.fireRepositoriesChanged(repositories));
if (added.length) {
// Send a notification that the repositories changed
queueMicrotask(() => this.fireRepositoriesChanged(added));
}
repository = repositories.length === 1 ? repositories[0] : this.getRepository(uri);
return repository;

+ 2
- 3
src/views/nodes/repositoriesNode.ts Parādīt failu

@ -7,7 +7,6 @@ import { debug } from '../../system/decorators/log';
import { debounce, szudzikPairing } from '../../system/function';
import { Logger } from '../../system/logger';
import type { ViewsWithRepositoriesNode } from '../viewBase';
import { WorkspacesView } from '../workspacesView';
import { MessageNode } from './common';
import { RepositoryNode } from './repositoryNode';
import type { ViewNode } from './viewNode';
@ -31,7 +30,7 @@ export class RepositoriesNode extends SubscribeableViewNode
if (this._children == null) return;
for (const child of this._children) {
if (child instanceof RepositoryNode) {
if ('dispose' in child) {
child.dispose();
}
}
@ -50,7 +49,7 @@ export class RepositoriesNode extends SubscribeableViewNode
}
getTreeItem(): TreeItem {
const isInWorkspacesView = this.view instanceof WorkspacesView;
const isInWorkspacesView = this.view.type === 'workspaces';
const isLinkedWorkspace = isInWorkspacesView && this.view.container.workspaces.currentWorkspaceId != null;
const isCurrentLinkedWorkspace = isLinkedWorkspace && this.view.container.workspaces.currentWorkspace != null;
const item = new TreeItem(

+ 20
- 5
src/views/nodes/viewNode.ts Parādīt failu

@ -703,6 +703,22 @@ export abstract class RepositoriesSubscribeableNode<
super(unknownGitUri, view);
}
override dispose() {
super.dispose();
this.resetChildren();
}
private resetChildren() {
if (this.children == null) return;
for (const child of this.children) {
if ('dispose' in child) {
child.dispose();
}
}
this.children = undefined;
}
override async getSplattedChild() {
if (this.children == null) {
await this.getChildren();
@ -714,11 +730,10 @@ export abstract class RepositoriesSubscribeableNode<
@gate()
@debug()
override refresh(reset: boolean = false) {
if (reset && this.children != null) {
for (const child of this.children) {
child.dispose();
}
this.children = undefined;
if (this.children == null) return;
if (reset) {
this.resetChildren();
}
}

+ 40
- 11
src/views/nodes/workspaceNode.ts Parādīt failu

@ -1,15 +1,19 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Disposable, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import type { RepositoriesChangeEvent } from '../../git/gitProviderService';
import { GitUri } from '../../git/gitUri';
import type { CloudWorkspace, LocalWorkspace } from '../../plus/workspaces/models';
import { WorkspaceType } from '../../plus/workspaces/models';
import { createCommand } from '../../system/command';
import { gate } from '../../system/decorators/gate';
import { debug } from '../../system/decorators/log';
import type { WorkspacesView } from '../workspacesView';
import { CommandMessageNode, MessageNode } from './common';
import { RepositoryNode } from './repositoryNode';
import { ContextValues, getViewNodeId, ViewNode } from './viewNode';
import type { ViewNode } from './viewNode';
import { ContextValues, getViewNodeId, SubscribeableViewNode } from './viewNode';
import { WorkspaceMissingRepositoryNode } from './workspaceMissingRepositoryNode';
export class WorkspaceNode extends ViewNode<WorkspacesView> {
export class WorkspaceNode extends SubscribeableViewNode<WorkspacesView> {
constructor(
uri: GitUri,
view: WorkspacesView,
@ -22,6 +26,22 @@ export class WorkspaceNode extends ViewNode {
this._uniqueId = getViewNodeId('workspace', this.context);
}
override dispose() {
super.dispose();
this.resetChildren();
}
private resetChildren() {
if (this._children == null) return;
for (const child of this._children) {
if ('dispose' in child) {
child.dispose();
}
}
this._children = undefined;
}
override get id(): string {
return this._uniqueId;
}
@ -131,17 +151,26 @@ export class WorkspaceNode extends ViewNode {
return item;
}
override refresh() {
@gate()
@debug()
override refresh(reset: boolean = false) {
if (this._children == null) return;
if (this._children.length) {
for (const child of this._children) {
if ('dispose' in child) {
child.dispose();
}
}
if (reset) {
this.resetChildren();
}
}
this._children = undefined;
protected override etag(): number {
return this.view.container.git.etag;
}
@debug()
protected subscribe(): Disposable | Promise<Disposable> {
return Disposable.from(this.view.container.git.onDidChangeRepositories(this.onRepositoriesChanged, this));
}
private onRepositoriesChanged(_e: RepositoriesChangeEvent) {
void this.triggerChange(true);
}
}

Notiek ielāde…
Atcelt
Saglabāt