@@ -7,6 +7,9 @@ import { IFileNode, MRTreeDataProvider } from 'src/tree/mrTree';
7
7
import { ReleaseTreeDataProvider } from 'src/tree/releaseTree' ;
8
8
import { IRepoInfo , IMRWebViewDetail , ISessionData } from 'src/typings/commonTypes' ;
9
9
import { GitService } from 'src/common/gitService' ;
10
+ import { ReviewComment , replyNote } from './reviewCommentController' ;
11
+ import { MRUriScheme } from 'src/common/contants' ;
12
+ import { IDiffComment , IMRData } from 'src/typings/respResult' ;
10
13
11
14
export async function activate ( context : vscode . ExtensionContext ) {
12
15
await GitService . init ( ) ;
@@ -42,6 +45,23 @@ export async function activate(context: vscode.ExtensionContext) {
42
45
showCollapseAll : true ,
43
46
} ) ;
44
47
48
+ const commentController = vscode . comments . createCommentController (
49
+ 'mr-comment' ,
50
+ 'Merge request diff comments' ,
51
+ ) ;
52
+ context . subscriptions . push ( commentController ) ;
53
+
54
+ commentController . commentingRangeProvider = {
55
+ provideCommentingRanges : ( document : vscode . TextDocument , token : vscode . CancellationToken ) => {
56
+ if ( document . uri . scheme !== MRUriScheme ) {
57
+ return ;
58
+ }
59
+
60
+ const lineCount = document . lineCount ;
61
+ return [ new vscode . Range ( 0 , 0 , lineCount - 1 , 0 ) ] ;
62
+ } ,
63
+ } ;
64
+
45
65
context . subscriptions . push ( vscode . window . registerUriHandler ( uriHandler ) ) ;
46
66
context . subscriptions . push (
47
67
vscode . commands . registerCommand ( 'codingPlugin.showMROverview' , async ( mr : IMRWebViewDetail ) => {
@@ -184,21 +204,63 @@ export async function activate(context: vscode.ExtensionContext) {
184
204
} ) ,
185
205
) ;
186
206
context . subscriptions . push (
187
- vscode . commands . registerCommand ( `codingPlugin.showDiff` , async ( file : IFileNode ) => {
188
- const headUri = vscode . Uri . parse ( file . path , false ) . with ( {
189
- // path: `${file.path}.txt`,
190
- scheme : `mr` ,
191
- query : `commit=${ file . newSha } &path=${ file . path } ` ,
192
- } ) ;
193
- const parentUri = headUri . with ( { query : `commit=${ file . oldSha } &path=${ file . path } ` } ) ;
194
- await vscode . commands . executeCommand (
195
- `vscode.diff` ,
196
- parentUri ,
197
- headUri ,
198
- `${ file . name } (Merge Request)` ,
199
- { preserveFocus : true } ,
200
- ) ;
201
- } ) ,
207
+ vscode . commands . registerCommand (
208
+ `codingPlugin.showDiff` ,
209
+ async ( file : IFileNode , mr : IMRData ) => {
210
+ const headUri = vscode . Uri . parse ( file . path , false ) . with ( {
211
+ scheme : MRUriScheme ,
212
+ query : `commit=${ file . newSha } &path=${ file . path } ` ,
213
+ } ) ;
214
+ const parentUri = headUri . with ( { query : `commit=${ file . oldSha } &path=${ file . path } ` } ) ;
215
+ await vscode . commands . executeCommand (
216
+ `vscode.diff` ,
217
+ parentUri ,
218
+ headUri ,
219
+ `${ file . name } (Merge Request #${ mr . iid } )` ,
220
+ { preserveFocus : true } ,
221
+ ) ;
222
+
223
+ const commentResp = await codingSrv . getMRComments ( mr . iid ) ;
224
+ const comments = ( commentResp . data as IDiffComment [ ] [ ] )
225
+ . filter ( ( i ) => {
226
+ const first = i [ 0 ] ;
227
+ return ! first . outdated && first . path === file . path ;
228
+ } , [ ] )
229
+ . map ( ( i ) => {
230
+ const root = i [ 0 ] ;
231
+ const isRight = root . change_type === 1 ;
232
+ const isLeft = root . change_type === 2 ;
233
+ const both = root . change_type === 3 ;
234
+
235
+ const rootLine = root . diffFile . diffLines [ root . diffFile . diffLines . length - 1 ] ;
236
+ const lineNum = isLeft ? rootLine . leftNo : rootLine . rightNo ;
237
+ const range = new vscode . Range ( lineNum , 0 , lineNum , 0 ) ;
238
+ const commentList : vscode . Comment [ ] = i . map ( ( c ) => {
239
+ const body = new vscode . MarkdownString ( `${ c . content } ` ) ;
240
+ body . isTrusted = true ;
241
+ const comment : vscode . Comment = {
242
+ mode : vscode . CommentMode . Preview ,
243
+ body : c . content ,
244
+ author : {
245
+ name : `${ c . author . name } (${ c . author . global_key } )` ,
246
+ iconPath : vscode . Uri . parse ( c . author . avatar , false ) ,
247
+ } ,
248
+ } ;
249
+ return comment ;
250
+ } ) ;
251
+ commentController . createCommentThread ( headUri , range , commentList ) ;
252
+ } ) ;
253
+ } ,
254
+ ) ,
255
+ ) ;
256
+
257
+ context . subscriptions . push (
258
+ vscode . commands . registerCommand (
259
+ `codingPlugin.diff.createComment` ,
260
+ async ( reply : vscode . CommentReply ) => {
261
+ replyNote ( reply ) ;
262
+ } ,
263
+ ) ,
202
264
) ;
203
265
204
266
if ( vscode . window . registerWebviewPanelSerializer ) {
0 commit comments