Skip to content

Commit

Permalink
Improve comment view behavior for empty comment (#224379)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 authored Jul 31, 2024
1 parent 5410988 commit ae6995d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { URI } from 'vs/base/common/uri';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { threadHasMeaningfulComments } from 'vs/workbench/contrib/comments/browser/commentsModel';

export const ID = 'editor.contrib.review';

Expand Down Expand Up @@ -1015,7 +1016,7 @@ export class CommentController implements IEditorContribution {
}

private async openCommentsView(thread: languages.CommentThread) {
if (thread.comments && (thread.comments.length > 0)) {
if (thread.comments && (thread.comments.length > 0) && threadHasMeaningfulComments(thread)) {
const openViewState = this.configurationService.getValue<ICommentsConfiguration>(COMMENTS_SECTION).openView;
if (openViewState === 'file') {
return this.viewsService.openView(COMMENTS_VIEW_ID);
Expand Down
15 changes: 14 additions & 1 deletion src/vs/workbench/contrib/comments/browser/commentsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { CommentThread } from 'vs/editor/common/languages';
import { localize } from 'vs/nls';
import { ResourceWithCommentThreads, ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel';
import { Disposable } from 'vs/base/common/lifecycle';
import { isMarkdownString } from 'vs/base/common/htmlContent';

export function threadHasMeaningfulComments(thread: CommentThread): boolean {
return !!thread.comments && !!thread.comments.length && thread.comments.some(comment => isMarkdownString(comment.body) ? comment.body.value.length > 0 : comment.body.length > 0);

}

export interface ICommentsModel {
hasCommentThreads(): boolean;
Expand Down Expand Up @@ -113,7 +119,14 @@ export class CommentsModel extends Disposable implements ICommentsModel {
}

public hasCommentThreads(): boolean {
return !!this._resourceCommentThreads.length;
// There's a resource with at least one thread
return !!this._resourceCommentThreads.length && this._resourceCommentThreads.some(resource => {
// At least one of the threads in the the resource has comments
return (resource.commentThreads.length > 0) && resource.commentThreads.some(thread => {
// At least one of the comments in the thread is not empty
return threadHasMeaningfulComments(thread.thread);
});
});
}

public getMessage(): string {
Expand Down
21 changes: 14 additions & 7 deletions src/vs/workbench/contrib/comments/browser/commentsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import { Memento, MementoObject } from 'vs/workbench/common/memento';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { FilterOptions } from 'vs/workbench/contrib/comments/browser/commentsFilterOptions';
import { CommentThreadApplicability, CommentThreadState } from 'vs/editor/common/languages';
import { Iterable } from 'vs/base/common/iterator';
import { revealCommentThread } from 'vs/workbench/contrib/comments/browser/commentsController';
import { registerNavigableContainer } from 'vs/workbench/browser/actions/widgetNavigationCommands';
import { CommentsModel, type ICommentsModel } from 'vs/workbench/contrib/comments/browser/commentsModel';
import { CommentsModel, threadHasMeaningfulComments, type ICommentsModel } from 'vs/workbench/contrib/comments/browser/commentsModel';
import { IHoverService } from 'vs/platform/hover/browser/hover';
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
import { AccessibleViewAction } from 'vs/workbench/contrib/accessibility/browser/accessibleViewActions';
Expand All @@ -47,12 +46,20 @@ const VIEW_STORAGE_ID = 'commentsViewState';
type CommentsTreeNode = CommentsModel | ResourceWithCommentThreads | CommentNode;

function createResourceCommentsIterator(model: ICommentsModel): Iterable<ITreeElement<CommentsTreeNode>> {
return Iterable.map(model.resourceCommentThreads, m => {
const CommentNodeIt = Iterable.from(m.commentThreads);
const children = Iterable.map(CommentNodeIt, r => ({ element: r }));
const result: ITreeElement<CommentsTreeNode>[] = [];

return { element: m, children };
});
for (const m of model.resourceCommentThreads) {
const children = [];
for (const r of m.commentThreads) {
if (threadHasMeaningfulComments(r.thread)) {
children.push({ element: r });
}
}
if (children.length > 0) {
result.push({ element: m, children });
}
}
return result;
}

export class CommentsPanel extends FilterViewPane implements ICommentsView {
Expand Down

0 comments on commit ae6995d

Please sign in to comment.