@@ -3,13 +3,58 @@ import * as vscode from 'vscode';
3
3
import { FileStatus , PullRequest } from '../../bitbucket/model' ;
4
4
import { Commands } from '../../commands' ;
5
5
import { configuration } from '../../config/configuration' ;
6
- import { Resources } from '../../resources' ;
7
6
import { DiffViewArgs } from '../pullrequest/diffViewHelper' ;
8
- import { PullRequestContextValue } from '../pullrequest/pullRequestNode' ;
9
7
import { AbstractBaseNode } from './abstractBaseNode' ;
10
8
import { Container } from '../../container' ;
11
9
import { DirectoryNode } from './directoryNode' ;
12
10
import * as crypto from 'crypto' ;
11
+ import { Logger } from 'src/logger' ;
12
+
13
+ export class FileDecorationProvider implements vscode . FileDecorationProvider {
14
+ private _onDidChangeFileDecorations = new vscode . EventEmitter < vscode . Uri [ ] > ( ) ;
15
+ readonly onDidChangeFileDecorations = this . _onDidChangeFileDecorations . event ;
16
+
17
+ provideFileDecoration (
18
+ uri : vscode . Uri ,
19
+ _token : vscode . CancellationToken ,
20
+ ) : vscode . ProviderResult < vscode . FileDecoration > {
21
+ try {
22
+ const params = JSON . parse ( uri . query ) ;
23
+ const status = params . status as FileStatus ;
24
+ const hasComments = params . hasComments ;
25
+ if ( status ) {
26
+ return {
27
+ badge : hasComments ? `💬${ status } ` : status ,
28
+ color : this . getColor ( status ) ,
29
+ tooltip : hasComments ? `File has comments` : undefined ,
30
+ propagate : false ,
31
+ } ;
32
+ }
33
+ } catch ( e ) {
34
+ console . error ( 'Error in provideFileDecoration:' , e ) ;
35
+ }
36
+ return undefined ;
37
+ }
38
+
39
+ private getColor ( status : FileStatus ) : vscode . ThemeColor {
40
+ switch ( status ) {
41
+ case FileStatus . MODIFIED :
42
+ return new vscode . ThemeColor ( 'gitDecoration.modifiedResourceForeground' ) ;
43
+ case FileStatus . ADDED :
44
+ return new vscode . ThemeColor ( 'gitDecoration.addedResourceForeground' ) ;
45
+ case FileStatus . DELETED :
46
+ return new vscode . ThemeColor ( 'gitDecoration.deletedResourceForeground' ) ;
47
+ case FileStatus . RENAMED :
48
+ return new vscode . ThemeColor ( 'gitDecoration.renamedResourceForeground' ) ;
49
+ case FileStatus . CONFLICT :
50
+ return new vscode . ThemeColor ( 'gitDecoration.conflictingResourceForeground' ) ;
51
+ case FileStatus . COPIED :
52
+ return new vscode . ThemeColor ( 'gitDecoration.addedResourceForeground' ) ;
53
+ default :
54
+ return new vscode . ThemeColor ( 'gitDecoration.modifiedResourceForeground' ) ;
55
+ }
56
+ }
57
+ }
13
58
14
59
export class PullRequestFilesNode extends AbstractBaseNode {
15
60
constructor (
@@ -45,16 +90,26 @@ export class PullRequestFilesNode extends AbstractBaseNode {
45
90
}
46
91
}
47
92
93
+ createFileChangeUri ( fileName : string , status : FileStatus , prUrl : string , hasComments : boolean ) : vscode . Uri {
94
+ if ( hasComments ) {
95
+ Logger . debug ( hasComments , prUrl , 'hasComments' ) ;
96
+ }
97
+ return vscode . Uri . parse ( `${ prUrl } /${ fileName } ` ) . with ( {
98
+ scheme : 'pullRequest' ,
99
+ query : JSON . stringify ( {
100
+ status : status ,
101
+ hasComments : hasComments ,
102
+ } ) ,
103
+ } ) ;
104
+ }
105
+
48
106
async getTreeItem ( ) : Promise < vscode . TreeItem > {
49
107
const itemData = this . diffViewData . fileDisplayData ;
50
108
let fileDisplayString = itemData . fileDisplayName ;
51
109
if ( configuration . get < boolean > ( 'bitbucket.explorer.nestFilesEnabled' ) ) {
52
110
fileDisplayString = path . basename ( itemData . fileDisplayName ) ;
53
111
}
54
- const item = new vscode . TreeItem (
55
- `${ itemData . numberOfComments > 0 ? '💬 ' : '' } ${ fileDisplayString } ` ,
56
- vscode . TreeItemCollapsibleState . None ,
57
- ) ;
112
+ const item = new vscode . TreeItem ( fileDisplayString , vscode . TreeItemCollapsibleState . None ) ;
58
113
59
114
item . checkboxState = this . checked
60
115
? vscode . TreeItemCheckboxState . Checked
@@ -68,28 +123,14 @@ export class PullRequestFilesNode extends AbstractBaseNode {
68
123
title : 'Diff file' ,
69
124
arguments : this . diffViewData . diffArgs ,
70
125
} ;
71
-
72
- item . contextValue = `${ PullRequestContextValue } ${ this . checked ? '.checked' : '' } ` ;
73
- item . resourceUri = vscode . Uri . parse ( `${ itemData . prUrl } #chg-${ itemData . fileDisplayName } ` ) ;
74
- switch ( itemData . fileDiffStatus ) {
75
- case FileStatus . ADDED :
76
- item . iconPath = Resources . icons . get ( 'add-circle' ) ;
77
- break ;
78
- case FileStatus . DELETED :
79
- item . iconPath = Resources . icons . get ( 'delete' ) ;
80
- break ;
81
- case FileStatus . CONFLICT :
82
- item . iconPath = Resources . icons . get ( 'warning' ) ;
83
- break ;
84
- default :
85
- item . iconPath = Resources . icons . get ( 'edit' ) ;
86
- break ;
87
- }
88
-
89
- if ( this . diffViewData . fileDisplayData . isConflicted ) {
90
- item . iconPath = Resources . icons . get ( 'warning' ) ;
91
- }
92
-
126
+ // Create URI with both status and comment information
127
+ item . resourceUri = this . createFileChangeUri (
128
+ itemData . fileDisplayName ,
129
+ itemData . fileDiffStatus ,
130
+ itemData . prUrl ,
131
+ itemData . numberOfComments > 0 ,
132
+ ) ;
133
+ item . iconPath = undefined ;
93
134
return item ;
94
135
}
95
136
0 commit comments