Skip to content

Commit 462b4de

Browse files
author
Rachel Macfarlane
committed
Fixes #181, Refresh action on Changes In Pull Request doesn't update comments panel
1 parent b2026ba commit 462b4de

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

src/view/prChangesTreeDataProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export class PullRequestChangesTreeDataProvider extends vscode.Disposable implem
2626
constructor(private context: vscode.ExtensionContext) {
2727
super(() => this.dispose());
2828
this.context.subscriptions.push(vscode.window.registerTreeDataProvider<TreeNode>('prStatus', this));
29+
}
2930

30-
this._disposables.push(vscode.commands.registerCommand('pr.refreshChanges', _ => {
31-
this._onDidChangeTreeData.fire();
32-
}));
31+
refresh() {
32+
this._onDidChangeTreeData.fire();
3333
}
3434

3535
async showPullRequestFileChanges(pullRequestManager: IPullRequestManager, pullrequest: IPullRequestModel, fileChanges: (FileChangeNode | RemoteFileChangeNode)[], comments: Comment[]) {

src/view/reviewManager.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export class ReviewManager implements vscode.DecorationProvider {
6464
// todo, validate state only when state changes.
6565
this.updateState();
6666
}));
67+
68+
this._disposables.push(vscode.commands.registerCommand('pr.refreshChanges', _ => {
69+
this.updateComments();
70+
this.prFileChangesProvider.refresh();
71+
}));
72+
6773
this._prsTreeDataProvider = new PullRequestsTreeDataProvider(this._configuration, _repository, _prManager);
6874
this._disposables.push(this._prsTreeDataProvider);
6975
this._disposables.push(vscode.window.registerDecorationProvider(this));
@@ -220,10 +226,14 @@ export class ReviewManager implements vscode.DecorationProvider {
220226
});
221227

222228
matchedFile.comments.push(comment);
229+
this._comments.push(comment);
230+
231+
this._onDidChangeCommentThreads.fire({
232+
added: [],
233+
changed: [thread],
234+
removed: []
235+
});
223236

224-
setTimeout(() => {
225-
this.updateComments();
226-
}, 0);
227237
return thread;
228238
} catch (e) {
229239
throw new Error(formatError(e));
@@ -257,16 +267,19 @@ export class ReviewManager implements vscode.DecorationProvider {
257267

258268
let commentThread: vscode.CommentThread = {
259269
threadId: comment.commentId,
260-
resource: uri,
270+
resource: vscode.Uri.file(path.resolve(this._repository.path, rawComment.path)),
261271
range: range,
262272
comments: [comment]
263273
};
264274

265275
matchedFile.comments.push(rawComment);
276+
this._comments.push(rawComment);
266277

267-
setTimeout(() => {
268-
this.updateComments();
269-
}, 0);
278+
this._onDidChangeCommentThreads.fire({
279+
added: [commentThread],
280+
changed: [],
281+
removed: []
282+
});
270283

271284
return commentThread;
272285
} catch (e) {
@@ -361,6 +374,11 @@ export class ReviewManager implements vscode.DecorationProvider {
361374
});
362375

363376
this._comments = comments;
377+
this._localFileChanges.forEach(change => {
378+
if (change instanceof FileChangeNode) {
379+
change.comments = this._comments.filter(comment => change.fileName === comment.path && comment.position !== null);
380+
}
381+
});
364382
this._onDidChangeDecorations.fire();
365383
}
366384

src/view/treeNodes/fileChangeNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
5858
public readonly parentFilePath: vscode.Uri,
5959
public readonly isPartial: boolean,
6060
public readonly diffHunks: DiffHunk[],
61-
public readonly comments: Comment[] = [],
61+
public comments: Comment[] = [],
6262
public readonly sha?: string,
6363
) {
6464
super();

0 commit comments

Comments
 (0)