Skip to content

Commit 9d0f5e5

Browse files
committed
Re #161. File decoration provider.
1 parent 30f742a commit 9d0f5e5

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/common/uri.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,25 @@ export function toPRUri(uri: Uri, pullRequestModel: IPullRequestModel, fileInRep
7979
});
8080
}
8181

82+
export interface FileChangeNodeUriParams {
83+
hasComments?: boolean;
84+
}
85+
86+
export function toFileChangeNodeUri(uri: Uri, hasComments: boolean) {
87+
const params = {
88+
hasComments: hasComments
89+
}
90+
91+
return uri.with({
92+
scheme: 'file',
93+
query: JSON.stringify(params)
94+
})
95+
}
96+
97+
export function fromFileChangeNodeUri(uri: Uri): FileChangeNodeUriParams {
98+
try {
99+
return JSON.parse(uri.query) as FileChangeNodeUriParams;
100+
} catch (e) {
101+
return null;
102+
}
103+
}

src/common/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export function groupBy<T>(arr: T[], fn: (el: T) => string): { [key: string]: T[
8888

8989
export function formatError(e: any): string {
9090
if (!(e instanceof Error)) {
91+
if (typeof e === 'string') {
92+
return e;
93+
}
9194
return 'Error';
9295
}
9396

src/view/prsTreeDataProvider.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Repository } from '../common/repository';
1010
import { TreeNode } from './treeNodes/treeNode';
1111
import { PRCategoryActionNode, CategoryTreeNode, PRCategoryActionType } from './treeNodes/categoryNode';
1212
import { IPullRequestManager, PRType } from '../github/interface';
13+
import { fromFileChangeNodeUri } from '../common/uri';
1314

1415
export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<TreeNode>, vscode.TextDocumentContentProvider, vscode.DecorationProvider, vscode.Disposable {
1516
private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>();
@@ -74,15 +75,16 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
7475
_onDidChangeDecorations: vscode.EventEmitter<vscode.Uri | vscode.Uri[]> = new vscode.EventEmitter<vscode.Uri | vscode.Uri[]>();
7576
onDidChangeDecorations: vscode.Event<vscode.Uri | vscode.Uri[]> = this._onDidChangeDecorations.event;
7677
provideDecoration(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<vscode.DecorationData> {
77-
if (uri.scheme === 'pr') {
78+
let fileChangeUriParams = fromFileChangeNodeUri(uri);
79+
if (fileChangeUriParams && fileChangeUriParams.hasComments) {
7880
return {
7981
bubble: true,
8082
abbreviation: '♪♪',
8183
title: '♪♪'
82-
};
83-
} else {
84-
return {};
84+
}
8585
}
86+
87+
return {};
8688
}
8789

8890
async provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): Promise<string> {

src/view/treeNodes/fileChangeNode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IPullRequestModel } from '../../github/interface';
1111
import { TreeNode } from './treeNode';
1212
import { Comment } from '../../common/comment';
1313
import { getDiffLineByPosition, getZeroBased } from '../../common/diffPositionMapping';
14+
import { toFileChangeNodeUri } from '../../common/uri';
1415

1516
export class RemoteFileChangeNode extends TreeNode implements vscode.TreeItem {
1617
public label: string;
@@ -70,7 +71,8 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
7071
} else {
7172
this.iconPath = Resource.getFileStatusUri(this);
7273
}
73-
this.resourceUri = this.filePath;
74+
75+
this.resourceUri = toFileChangeNodeUri(this.filePath, comments.length > 0);
7476

7577
let opts: vscode.TextDocumentShowOptions = {
7678
preserveFocus: true

0 commit comments

Comments
 (0)