From 070d4f3864f72ccccb7b1dc14443d910983043c7 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Mon, 23 Apr 2018 10:36:20 -0700 Subject: [PATCH] filter comments by file --- .../git-extended/src/prView/prProvider.ts | 1 - .../git-extended/src/review/reviewMode.ts | 71 ++++++++++--------- .../commentsEditorContribution.ts | 4 +- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/extensions/git-extended/src/prView/prProvider.ts b/extensions/git-extended/src/prView/prProvider.ts index 6e99cb1e9bd..9b79ba34f1c 100644 --- a/extensions/git-extended/src/prView/prProvider.ts +++ b/extensions/git-extended/src/prView/prProvider.ts @@ -162,7 +162,6 @@ export class PRProvider implements vscode.TreeDataProvider(); - setTimeout(() => _onDidChangeCommentThreads.fire({ changed: [], added: [], removed: [] }), 5000); vscode.workspace.registerDocumentCommentProvider({ onDidChangeCommentThreads: _onDidChangeCommentThreads.event, provideDocumentComments: async (document: vscode.TextDocument, token: vscode.CancellationToken) => { diff --git a/extensions/git-extended/src/review/reviewMode.ts b/extensions/git-extended/src/review/reviewMode.ts index 9f978761347..53bf267a4fa 100644 --- a/extensions/git-extended/src/review/reviewMode.ts +++ b/extensions/git-extended/src/review/reviewMode.ts @@ -281,36 +281,41 @@ export class ReviewMode implements vscode.DecorationProvider { return []; } - let sections = _.groupBy(comments, comment => comment.position); + let fileCommentGroups = _.groupBy(comments, comment => comment.path); let ret: vscode.CommentThread[] = []; - for (let i in sections) { - let comments = sections[i]; - - const comment = comments[0]; - // If the position is null, the comment is on a line that has been changed. Fall back to using original position. - const commentPosition = comment.position === null ? comment.original_position : comment.position - 1; - const commentAbsolutePosition = comment.diff_hunk_range.start + commentPosition; - const pos = new vscode.Position(comment.currentPosition ? comment.currentPosition - 1 - 1 : commentAbsolutePosition - /* after line */ 1 - /* it's zero based*/ 1, 0); - const range = new vscode.Range(pos, pos); - - ret.push({ - threadId: comment.id, - resource: vscode.Uri.file(path.resolve(this._repository.path, comment.path)), - range, - comments: comments.map(comment => { - return { - commentId: comment.id, - body: new vscode.MarkdownString(comment.body), - userName: comment.user.login, - gravatar: comment.user.avatar_url - }; - }), - collapsibleState: collapsibleState, - reply: this._reply - }); - } + for (let file in fileCommentGroups) { + let fileComments = fileCommentGroups[file]; + let sections = _.groupBy(fileComments, comment => comment.position); + + for (let i in sections) { + let comments = sections[i]; + + const comment = comments[0]; + // If the position is null, the comment is on a line that has been changed. Fall back to using original position. + const commentPosition = comment.position === null ? comment.original_position : comment.position - 1; + const commentAbsolutePosition = comment.diff_hunk_range.start + commentPosition; + const pos = new vscode.Position(comment.currentPosition ? comment.currentPosition - 1 - 1 : commentAbsolutePosition - /* after line */ 1 - /* it's zero based*/ 1, 0); + const range = new vscode.Range(pos, pos); + + ret.push({ + threadId: comment.id, + resource: vscode.Uri.file(path.resolve(this._repository.path, comment.path)), + range, + comments: comments.map(comment => { + return { + commentId: comment.id, + body: new vscode.MarkdownString(comment.body), + userName: comment.user.login, + gravatar: comment.user.avatar_url + }; + }), + collapsibleState: collapsibleState, + reply: this._reply + }); + } + } return ret; } @@ -391,12 +396,12 @@ export class ReviewMode implements vscode.DecorationProvider { async switch(pr: PullRequest) { try { - if (pr.prItem.maintainer_can_modify) { - await this._repository.checkoutPR(pr); - } else { - await this._repository.fetch(pr.remote.remoteName, `pull/${pr.prItem.number}/head:pull-request-${pr.prItem.number}`); - await this._repository.checkout(`pull-request-${pr.prItem.number}`); - } + // if (pr.prItem.maintainer_can_modify) { + // await this._repository.checkoutPR(pr); + // } else { + await this._repository.fetch(pr.remote.remoteName, `pull/${pr.prItem.number}/head:pull-request-${pr.prItem.number}`); + await this._repository.checkout(`pull-request-${pr.prItem.number}`); + // } } catch (e) { vscode.window.showErrorMessage(e); return; diff --git a/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts b/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts index eac7b39edde..bdddb6c8573 100644 --- a/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts +++ b/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts @@ -192,7 +192,7 @@ export class ReviewZoneWidget extends ZoneWidget { this._actionbarWidget = new ActionBar(actionsContainer.getHTMLElement(), {}); this._disposables.push(this._actionbarWidget); - this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), this._isCollapsed ? EXPAND_ACTION_CLASS : COLLAPSE_ACTION_CLASS, true, () => { + /* this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), this._isCollapsed ? EXPAND_ACTION_CLASS : COLLAPSE_ACTION_CLASS, true, () => { if (this._isCollapsed) { } else { @@ -201,7 +201,7 @@ export class ReviewZoneWidget extends ZoneWidget { return null; }); - this._actionbarWidget.push(this._toggleAction, { label: false, icon: true }); + this._actionbarWidget.push(this._toggleAction, { label: false, icon: true }); */ } toggleExpand() { -- GitLab