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

Add filtering on user and check replies #158356

Merged
merged 1 commit into from Aug 17, 2022
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
19 changes: 15 additions & 4 deletions src/vs/workbench/contrib/comments/browser/commentsTreeViewer.ts
Expand Up @@ -309,20 +309,31 @@ export class Filter implements ITreeFilter<ResourceWithCommentThreads | CommentN
return true;
}

const textMatches = FilterOptions._messageFilter(this.options.textFilter.text, typeof comment.comment.body === 'string' ? comment.comment.body : comment.comment.body.value);
const textMatches =
// Check body of comment for value
FilterOptions._messageFilter(this.options.textFilter.text, typeof comment.comment.body === 'string' ? comment.comment.body : comment.comment.body.value)
// Check first user for value
|| FilterOptions._messageFilter(this.options.textFilter.text, comment.comment.userName)
// Check all replies for value
|| (comment.replies.map(reply => {
// Check user for value
return FilterOptions._messageFilter(this.options.textFilter.text, reply.comment.userName)
// Check body of reply for value
|| FilterOptions._messageFilter(this.options.textFilter.text, typeof reply.comment.body === 'string' ? reply.comment.body : reply.comment.body.value);
}).filter(value => !!value) as IMatch[][]).flat();

// Matched and not negated
if (textMatches && !this.options.textFilter.negate) {
if (textMatches.length && !this.options.textFilter.negate) {
return { visibility: true, data: { type: FilterDataType.Comment, textMatches } };
}

// Matched and negated - exclude it only if parent visibility is not set
if (textMatches && this.options.textFilter.negate && parentVisibility === TreeVisibility.Recurse) {
if (textMatches.length && this.options.textFilter.negate && parentVisibility === TreeVisibility.Recurse) {
return false;
}

// Not matched and negated - include it only if parent visibility is not set
if (!textMatches && this.options.textFilter.negate && parentVisibility === TreeVisibility.Recurse) {
if ((textMatches.length === 0) && this.options.textFilter.negate && parentVisibility === TreeVisibility.Recurse) {
return true;
}

Expand Down
15 changes: 5 additions & 10 deletions src/vs/workbench/contrib/comments/browser/commentsView.ts
Expand Up @@ -49,6 +49,7 @@ export class CommentsPanel extends ViewPane implements ICommentsView {
private treeContainer!: HTMLElement;
private messageBoxContainer!: HTMLElement;
private commentsModel!: CommentsModel;
private totalComments: number = 0;
private readonly hasCommentsContextKey: IContextKey<boolean>;
private readonly smallLayoutContextKey: IContextKey<boolean>;
private readonly filter: Filter;
Expand Down Expand Up @@ -117,16 +118,6 @@ export class CommentsPanel extends ViewPane implements ICommentsView {
}));
}

private _totalComments: number = 0;
set totalComments(totalComments: number) {
this._totalComments = totalComments;
this.updateFilter();
}

get totalComments(): number {
return this._totalComments;
}

override saveState(): void {
this.viewState['filter'] = this.filters.filterText;
this.viewState['filterHistory'] = this.filters.filterHistory;
Expand Down Expand Up @@ -332,6 +323,10 @@ export class CommentsPanel extends ViewPane 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