Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Folded comments disappear after moving to a different tab #171736

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/vs/base/browser/ui/tree/asyncDataTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ export class AsyncDataTree<TInput, T, TFilterData = void> implements IDisposable
get onDidFocus(): Event<void> { return this.tree.onDidFocus; }
get onDidBlur(): Event<void> { return this.tree.onDidBlur; }

/**
* To be used internally only!
* @deprecated
*/
get onDidChangeModel(): Event<void> { return this.tree.onDidChangeModel; }
get onDidChangeCollapseState(): Event<ICollapseStateChangeEvent<IAsyncDataTreeNode<TInput, T> | null, TFilterData>> { return this.tree.onDidChangeCollapseState; }

Expand Down
34 changes: 9 additions & 25 deletions src/vs/workbench/contrib/comments/browser/commentsTreeViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IResourceLabel, ResourceLabels } from 'vs/workbench/browser/labels';
import { CommentNode, CommentsModel, ResourceWithCommentThreads } from 'vs/workbench/contrib/comments/common/commentModel';
import { IAsyncDataSource, ITreeFilter, ITreeNode, TreeFilterResult, TreeVisibility } from 'vs/base/browser/ui/tree/tree';
import { ITreeFilter, ITreeNode, TreeFilterResult, TreeVisibility } from 'vs/base/browser/ui/tree/tree';
import { IListVirtualDelegate, IListRenderer } from 'vs/base/browser/ui/list/list';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { WorkbenchAsyncDataTree, IListService, IWorkbenchAsyncDataTreeOptions } from 'vs/platform/list/browser/listService';
import { IListService, IWorkbenchAsyncDataTreeOptions, WorkbenchObjectTree } from 'vs/platform/list/browser/listService';
import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { TimestampWidget } from 'vs/workbench/contrib/comments/browser/timestamp';
Expand All @@ -35,22 +35,6 @@ export const COMMENTS_VIEW_ID = 'workbench.panel.comments';
export const COMMENTS_VIEW_STORAGE_ID = 'Comments';
export const COMMENTS_VIEW_TITLE = nls.localize('comments.view.title', "Comments");

export class CommentsAsyncDataSource implements IAsyncDataSource<any, any> {
hasChildren(element: any): boolean {
return (element instanceof CommentsModel || element instanceof ResourceWithCommentThreads) && !(element instanceof CommentNode);
}

getChildren(element: any): any[] | Promise<any[]> {
if (element instanceof CommentsModel) {
return Promise.resolve(element.resourceCommentThreads);
}
if (element instanceof ResourceWithCommentThreads) {
return Promise.resolve(element.commentThreads);
}
return Promise.resolve([]);
}
}

interface IResourceTemplateData {
resourceLabel: IResourceLabel;
}
Expand Down Expand Up @@ -278,6 +262,10 @@ export class Filter implements ITreeFilter<ResourceWithCommentThreads | CommentN
constructor(public options: FilterOptions) { }

filter(element: ResourceWithCommentThreads | CommentNode, parentVisibility: TreeVisibility): TreeFilterResult<FilterData> {
if (this.options.filter === '' && this.options.showResolved && this.options.showUnresolved) {
return TreeVisibility.Visible;
}

if (element instanceof ResourceWithCommentThreads) {
return this.filterResourceMarkers(element);
} else {
Expand Down Expand Up @@ -341,7 +329,7 @@ export class Filter implements ITreeFilter<ResourceWithCommentThreads | CommentN
}
}

export class CommentsList extends WorkbenchAsyncDataTree<CommentsModel | ResourceWithCommentThreads | CommentNode, any> {
export class CommentsList extends WorkbenchObjectTree<CommentsModel | ResourceWithCommentThreads | CommentNode, any> {
constructor(
labels: ResourceLabels,
container: HTMLElement,
Expand All @@ -353,7 +341,6 @@ export class CommentsList extends WorkbenchAsyncDataTree<CommentsModel | Resourc
@IConfigurationService configurationService: IConfigurationService,
) {
const delegate = new CommentsModelVirualDelegate();
const dataSource = new CommentsAsyncDataSource();

const renderers = [
instantiationService.createInstance(ResourceWithCommentsRenderer, labels),
Expand All @@ -365,7 +352,6 @@ export class CommentsList extends WorkbenchAsyncDataTree<CommentsModel | Resourc
container,
delegate,
renderers,
dataSource,
{
accessibilityProvider: options.accessibilityProvider,
identityProvider: {
Expand All @@ -389,17 +375,15 @@ export class CommentsList extends WorkbenchAsyncDataTree<CommentsModel | Resourc

return true;
},
collapseByDefault: () => {
return false;
},
collapseByDefault: false,
overrideStyles: options.overrideStyles,
filter: options.filter,
findWidgetEnabled: false
},
instantiationService,
contextKeyService,
listService,
configurationService
configurationService,
);
}

Expand Down
22 changes: 15 additions & 7 deletions src/vs/workbench/contrib/comments/browser/commentsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ import { FilterOptions } from 'vs/workbench/contrib/comments/browser/commentsFil
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
import { CommentThreadState } from 'vs/editor/common/languages';
import { IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { ITreeElement } from 'vs/base/browser/ui/tree/tree';
import { Iterable } from 'vs/base/common/iterator';

const CONTEXT_KEY_HAS_COMMENTS = new RawContextKey<boolean>('commentsView.hasComments', false);
const VIEW_STORAGE_ID = 'commentsViewState';

function createResourceCommentsIterator(model: CommentsModel): Iterable<ITreeElement<ResourceWithCommentThreads | CommentNode>> {
return Iterable.map(model.resourceCommentThreads, m => {
const CommentNodeIt = Iterable.from(m.commentThreads);
const children = Iterable.map(CommentNodeIt, r => ({ element: r }));

return { element: m, children };
});
}

export class CommentsPanel extends FilterViewPane implements ICommentsView {
private treeLabels!: ResourceLabels;
private tree: CommentsList | undefined;
Expand Down Expand Up @@ -232,7 +243,7 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
private async renderComments(): Promise<void> {
this.treeContainer.classList.toggle('hidden', !this.commentsModel.hasCommentThreads());
this.renderMessage();
await this.tree?.setInput(this.commentsModel);
await this.tree?.setChildren(null, createResourceCommentsIterator(this.commentsModel));
}

public collapseAll() {
Expand Down Expand Up @@ -308,10 +319,6 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
this._register(this.tree.onDidOpen(e => {
this.openFile(e.element, e.editorOptions.pinned, e.editorOptions.preserveFocus, e.sideBySide);
}));
this._register(this.tree?.onDidChangeModel(() => {
this.cachedFilterStats = undefined;
this.updateFilter();
}));
}

private openFile(element: any, pinned?: boolean, preserveFocus?: boolean, sideBySide?: boolean): boolean {
Expand Down Expand Up @@ -382,7 +389,7 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
this.treeContainer.classList.toggle('hidden', !this.commentsModel.hasCommentThreads());
this.cachedFilterStats = undefined;
this.renderMessage();
await this.tree.updateChildren();
this.tree?.setChildren(null, createResourceCommentsIterator(this.commentsModel));

if (this.tree.getSelection().length === 0 && this.commentsModel.hasCommentThreads()) {
const firstComment = this.commentsModel.resourceCommentThreads[0].commentThreads[0];
Expand All @@ -395,8 +402,8 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
}

private onAllCommentsChanged(e: IWorkspaceCommentThreadsEvent): void {
this.cachedFilterStats = undefined;
this.commentsModel.setCommentThreads(e.ownerId, e.commentThreads);

this.totalComments += e.commentThreads.length;

let unresolved = 0;
Expand All @@ -411,6 +418,7 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
}

private onCommentsUpdated(e: ICommentThreadChangedEvent): void {
this.cachedFilterStats = undefined;
const didUpdate = this.commentsModel.updateCommentThreads(e);

this.totalComments += e.added.length;
Expand Down