Skip to content

Commit

Permalink
Re #161. File decoration provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Aug 20, 2018
1 parent 30f742a commit 9d0f5e5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/common/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,25 @@ export function toPRUri(uri: Uri, pullRequestModel: IPullRequestModel, fileInRep
});
}

export interface FileChangeNodeUriParams {
hasComments?: boolean;
}

export function toFileChangeNodeUri(uri: Uri, hasComments: boolean) {
const params = {
hasComments: hasComments
}

return uri.with({
scheme: 'file',
query: JSON.stringify(params)
})
}

export function fromFileChangeNodeUri(uri: Uri): FileChangeNodeUriParams {
try {
return JSON.parse(uri.query) as FileChangeNodeUriParams;
} catch (e) {
return null;
}
}
3 changes: 3 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export function groupBy<T>(arr: T[], fn: (el: T) => string): { [key: string]: T[

export function formatError(e: any): string {
if (!(e instanceof Error)) {
if (typeof e === 'string') {
return e;
}
return 'Error';
}

Expand Down
10 changes: 6 additions & 4 deletions src/view/prsTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Repository } from '../common/repository';
import { TreeNode } from './treeNodes/treeNode';
import { PRCategoryActionNode, CategoryTreeNode, PRCategoryActionType } from './treeNodes/categoryNode';
import { IPullRequestManager, PRType } from '../github/interface';
import { fromFileChangeNodeUri } from '../common/uri';

export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<TreeNode>, vscode.TextDocumentContentProvider, vscode.DecorationProvider, vscode.Disposable {
private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>();
Expand Down Expand Up @@ -74,15 +75,16 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
_onDidChangeDecorations: vscode.EventEmitter<vscode.Uri | vscode.Uri[]> = new vscode.EventEmitter<vscode.Uri | vscode.Uri[]>();
onDidChangeDecorations: vscode.Event<vscode.Uri | vscode.Uri[]> = this._onDidChangeDecorations.event;
provideDecoration(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<vscode.DecorationData> {
if (uri.scheme === 'pr') {
let fileChangeUriParams = fromFileChangeNodeUri(uri);
if (fileChangeUriParams && fileChangeUriParams.hasComments) {
return {
bubble: true,
abbreviation: '♪♪',
title: '♪♪'
};
} else {
return {};
}
}

return {};
}

async provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): Promise<string> {
Expand Down
4 changes: 3 additions & 1 deletion src/view/treeNodes/fileChangeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IPullRequestModel } from '../../github/interface';
import { TreeNode } from './treeNode';
import { Comment } from '../../common/comment';
import { getDiffLineByPosition, getZeroBased } from '../../common/diffPositionMapping';
import { toFileChangeNodeUri } from '../../common/uri';

export class RemoteFileChangeNode extends TreeNode implements vscode.TreeItem {
public label: string;
Expand Down Expand Up @@ -70,7 +71,8 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
} else {
this.iconPath = Resource.getFileStatusUri(this);
}
this.resourceUri = this.filePath;

this.resourceUri = toFileChangeNodeUri(this.filePath, comments.length > 0);

let opts: vscode.TextDocumentShowOptions = {
preserveFocus: true
Expand Down

0 comments on commit 9d0f5e5

Please sign in to comment.