@@ -53,6 +53,7 @@ export async function activate(context: vscode.ExtensionContext) {
5353 'Merge request diff comments' ,
5454 ) ;
5555 context . subscriptions . push ( commentController ) ;
56+ const commentResolveData : { [ key : string ] : boolean } = { } ;
5657
5758 commentController . commentingRangeProvider = {
5859 provideCommentingRanges : async (
@@ -65,12 +66,12 @@ export async function activate(context: vscode.ExtensionContext) {
6566
6667 try {
6768 const params = new URLSearchParams ( decodeURIComponent ( document . uri . query ) ) ;
68- const iid = params . get ( 'mr ' ) || `` ;
69+ const mrId = params . get ( 'id ' ) || `` ;
6970 let param : IFileDiffParam = {
7071 path : params . get ( 'path' ) ?? `` ,
7172 base : params . get ( 'leftSha' ) ?? `` ,
7273 compare : params . get ( 'rightSha' ) ?? `` ,
73- mergeRequestId : iid ?? `` ,
74+ mergeRequestId : mrId ?? `` ,
7475 } ;
7576 const {
7677 data : { diffLines } ,
@@ -83,7 +84,9 @@ export async function activate(context: vscode.ExtensionContext) {
8384
8485 const [ left , right ] = getDiffLineNumber ( i . text ) ;
8586 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+ }
8790 return result ;
8891 } , [ ] as vscode . Range [ ] ) ;
8992 return ret ;
@@ -241,10 +244,10 @@ export async function activate(context: vscode.ExtensionContext) {
241244 async ( file : IFileNode , mr : IMRData ) => {
242245 const headUri = vscode . Uri . parse ( file . path , false ) . with ( {
243246 scheme : MRUriScheme ,
244- query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=true&mr=${ mr . iid } ` ,
247+ query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=true&mr=${ mr . iid } &id= ${ mr . id } ` ,
245248 } ) ;
246249 const parentUri = headUri . with ( {
247- query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=false&mr=${ mr . iid } ` ,
250+ query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=false&mr=${ mr . iid } &id= ${ mr . id } ` ,
248251 } ) ;
249252 await vscode . commands . executeCommand (
250253 `vscode.diff` ,
@@ -254,43 +257,49 @@ export async function activate(context: vscode.ExtensionContext) {
254257 { preserveFocus : true } ,
255258 ) ;
256259
260+ const identifier = `${ mr . iid } /${ file . path } ` ;
261+ if ( commentResolveData [ identifier ] ) {
262+ return ;
263+ }
264+
257265 try {
258266 const commentResp = await codingSrv . getMRComments ( mr . iid ) ;
259267
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 ;
268+ const validComments = ( commentResp . data as IDiffComment [ ] [ ] ) . filter ( ( i ) => {
269+ const first = i [ 0 ] ;
270+ return ! first . outdated && first . path === file . path ;
271+ } , [ ] ) ;
272+
273+ validComments . forEach ( ( i ) => {
274+ const root = i [ 0 ] ;
275+ const isLeft = root . change_type === 2 ;
276+ const isRight = root . change_type === 1 ;
269277
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 ) ;
278+ const rootLine = root . diffFile . diffLines [ root . diffFile . diffLines . length - 1 ] ;
279+ const lineNum = isLeft ? rootLine . leftNo - 1 : rootLine . rightNo - 1 ;
280+ const range = new vscode . Range ( lineNum - 1 , 0 , lineNum - 1 , 0 ) ;
273281
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 ;
282+ const commentList : vscode . Comment [ ] = i . map ( ( c ) => {
283+ const body = new vscode . MarkdownString ( tdService . turndown ( c . content ) ) ;
284+ body . isTrusted = true ;
285+ const comment : vscode . Comment = {
286+ mode : vscode . CommentMode . Preview ,
287+ body,
288+ author : {
289+ name : `${ c . author . name } (${ c . author . global_key } )` ,
290+ iconPath : vscode . Uri . parse ( c . author . avatar , false ) ,
291+ } ,
292+ } ;
293+ return comment ;
293294 } ) ;
295+ const commentThread = commentController . createCommentThread (
296+ isRight ? headUri : parentUri ,
297+ range ,
298+ commentList ,
299+ ) ;
300+ commentThread . collapsibleState = vscode . CommentThreadCollapsibleState . Expanded ;
301+ } ) ;
302+ commentResolveData [ identifier ] = true ;
294303 } finally {
295304 }
296305 } ,
@@ -300,16 +309,23 @@ export async function activate(context: vscode.ExtensionContext) {
300309 context . subscriptions . push (
301310 vscode . commands . registerCommand (
302311 `codingPlugin.diff.createComment` ,
303- ( reply : vscode . CommentReply ) => {
312+ async ( reply : vscode . CommentReply ) => {
304313 replyNote ( reply , context ) ;
305314 } ,
306315 ) ,
307316 ) ;
308317 context . subscriptions . push (
309318 vscode . commands . registerCommand (
310319 `codingPlugin.diff.replyComment` ,
311- ( reply : vscode . CommentReply ) => {
320+ async ( reply : vscode . CommentReply ) => {
312321 replyNote ( reply , context ) ;
322+ const params = new URLSearchParams ( decodeURIComponent ( reply . thread . uri . query ) ) ;
323+ const isRight = params . get ( 'right' ) === `true` ;
324+ const noteable_id = params . get ( 'id' ) ; // mr index id
325+ const commitId = isRight ? params . get ( 'rightSha' ) : params . get ( 'leftSha' ) ;
326+ const content = encodeURIComponent ( reply . text ) ;
327+ const noteable_type = `MergeRequestBean` ;
328+ const change_type = isRight ? 1 : 2 ;
313329 } ,
314330 ) ,
315331 ) ;
0 commit comments