@@ -53,6 +53,7 @@ export async function activate(context: vscode.ExtensionContext) {
53
53
'Merge request diff comments' ,
54
54
) ;
55
55
context . subscriptions . push ( commentController ) ;
56
+ let commentThread : vscode . CommentThread ;
56
57
57
58
commentController . commentingRangeProvider = {
58
59
provideCommentingRanges : async (
@@ -65,12 +66,12 @@ export async function activate(context: vscode.ExtensionContext) {
65
66
66
67
try {
67
68
const params = new URLSearchParams ( decodeURIComponent ( document . uri . query ) ) ;
68
- const iid = params . get ( 'mr ' ) || `` ;
69
+ const mrId = params . get ( 'id ' ) || `` ;
69
70
let param : IFileDiffParam = {
70
71
path : params . get ( 'path' ) ?? `` ,
71
72
base : params . get ( 'leftSha' ) ?? `` ,
72
73
compare : params . get ( 'rightSha' ) ?? `` ,
73
- mergeRequestId : iid ?? `` ,
74
+ mergeRequestId : mrId ?? `` ,
74
75
} ;
75
76
const {
76
77
data : { diffLines } ,
@@ -83,7 +84,9 @@ export async function activate(context: vscode.ExtensionContext) {
83
84
84
85
const [ left , right ] = getDiffLineNumber ( i . text ) ;
85
86
const [ start , end ] = params . get ( 'right' ) === `true` ? right : left ;
86
- result . push ( new vscode . Range ( start , 0 , end , 0 ) ) ;
87
+ if ( start > 0 ) {
88
+ result . push ( new vscode . Range ( start - 1 , 0 , end , 0 ) ) ;
89
+ }
87
90
return result ;
88
91
} , [ ] as vscode . Range [ ] ) ;
89
92
return ret ;
@@ -239,12 +242,13 @@ export async function activate(context: vscode.ExtensionContext) {
239
242
vscode . commands . registerCommand (
240
243
`codingPlugin.showDiff` ,
241
244
async ( file : IFileNode , mr : IMRData ) => {
245
+ commentThread ?. dispose ( ) ;
242
246
const headUri = vscode . Uri . parse ( file . path , false ) . with ( {
243
247
scheme : MRUriScheme ,
244
- query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=true&mr=${ mr . iid } ` ,
248
+ query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=true&mr=${ mr . iid } &id= ${ mr . id } ` ,
245
249
} ) ;
246
250
const parentUri = headUri . with ( {
247
- query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=false&mr=${ mr . iid } ` ,
251
+ query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=false&mr=${ mr . iid } &id= ${ mr . id } ` ,
248
252
} ) ;
249
253
await vscode . commands . executeCommand (
250
254
`vscode.diff` ,
@@ -257,40 +261,40 @@ export async function activate(context: vscode.ExtensionContext) {
257
261
try {
258
262
const commentResp = await codingSrv . getMRComments ( mr . iid ) ;
259
263
260
- ( commentResp . data as IDiffComment [ ] [ ] )
261
- . filter ( ( i ) => {
262
- const first = i [ 0 ] ;
263
- return ! first . outdated && first . path === file . path ;
264
- } , [ ] )
265
- . forEach ( ( i ) => {
266
- const root = i [ 0 ] ;
267
- const isLeft = root . change_type === 2 ;
268
- const isRight = root . change_type === 1 ;
264
+ const validComments = ( commentResp . data as IDiffComment [ ] [ ] ) . filter ( ( i ) => {
265
+ const first = i [ 0 ] ;
266
+ return ! first . outdated && first . path === file . path ;
267
+ } , [ ] ) ;
268
+
269
+ validComments . forEach ( ( i ) => {
270
+ const root = i [ 0 ] ;
271
+ const isLeft = root . change_type === 2 ;
272
+ const isRight = root . change_type === 1 ;
269
273
270
- const rootLine = root . diffFile . diffLines [ root . diffFile . diffLines . length - 1 ] ;
271
- const lineNum = isLeft ? rootLine . leftNo - 1 : rootLine . rightNo - 1 ;
272
- const range = new vscode . Range ( lineNum - 1 , 0 , lineNum - 1 , 0 ) ;
274
+ const rootLine = root . diffFile . diffLines [ root . diffFile . diffLines . length - 1 ] ;
275
+ const lineNum = isLeft ? rootLine . leftNo - 1 : rootLine . rightNo - 1 ;
276
+ const range = new vscode . Range ( lineNum - 1 , 0 , lineNum - 1 , 0 ) ;
273
277
274
- const commentList : vscode . Comment [ ] = i . map ( ( c ) => {
275
- const body = new vscode . MarkdownString ( tdService . turndown ( c . content ) ) ;
276
- body . isTrusted = true ;
277
- const comment : vscode . Comment = {
278
- mode : vscode . CommentMode . Preview ,
279
- body,
280
- author : {
281
- name : `${ c . author . name } (${ c . author . global_key } )` ,
282
- iconPath : vscode . Uri . parse ( c . author . avatar , false ) ,
283
- } ,
284
- } ;
285
- return comment ;
286
- } ) ;
287
- const commentThread = commentController . createCommentThread (
288
- isRight ? headUri : parentUri ,
289
- range ,
290
- commentList ,
291
- ) ;
292
- commentThread . collapsibleState = vscode . CommentThreadCollapsibleState . Expanded ;
278
+ const commentList : vscode . Comment [ ] = i . map ( ( c ) => {
279
+ const body = new vscode . MarkdownString ( tdService . turndown ( c . content ) ) ;
280
+ body . isTrusted = true ;
281
+ const comment : vscode . Comment = {
282
+ mode : vscode . CommentMode . Preview ,
283
+ body,
284
+ author : {
285
+ name : `${ c . author . name } (${ c . author . global_key } )` ,
286
+ iconPath : vscode . Uri . parse ( c . author . avatar , false ) ,
287
+ } ,
288
+ } ;
289
+ return comment ;
293
290
} ) ;
291
+ commentThread = commentController . createCommentThread (
292
+ isRight ? headUri : parentUri ,
293
+ range ,
294
+ commentList ,
295
+ ) ;
296
+ commentThread . collapsibleState = vscode . CommentThreadCollapsibleState . Expanded ;
297
+ } ) ;
294
298
} finally {
295
299
}
296
300
} ,
@@ -300,16 +304,23 @@ export async function activate(context: vscode.ExtensionContext) {
300
304
context . subscriptions . push (
301
305
vscode . commands . registerCommand (
302
306
`codingPlugin.diff.createComment` ,
303
- ( reply : vscode . CommentReply ) => {
307
+ async ( reply : vscode . CommentReply ) => {
304
308
replyNote ( reply , context ) ;
305
309
} ,
306
310
) ,
307
311
) ;
308
312
context . subscriptions . push (
309
313
vscode . commands . registerCommand (
310
314
`codingPlugin.diff.replyComment` ,
311
- ( reply : vscode . CommentReply ) => {
315
+ async ( reply : vscode . CommentReply ) => {
312
316
replyNote ( reply , context ) ;
317
+ const params = new URLSearchParams ( decodeURIComponent ( reply . thread . uri . query ) ) ;
318
+ const isRight = params . get ( 'right' ) === `true` ;
319
+ const noteable_id = params . get ( 'id' ) ; // mr index id
320
+ const commitId = isRight ? params . get ( 'rightSha' ) : params . get ( 'leftSha' ) ;
321
+ const content = encodeURIComponent ( reply . text ) ;
322
+ const noteable_type = `MergeRequestBean` ;
323
+ const change_type = isRight ? 1 : 2 ;
313
324
} ,
314
325
) ,
315
326
) ;
0 commit comments