@@ -10,7 +10,8 @@ import { IRepoInfo, IMRWebViewDetail, ISessionData } from 'src/typings/commonTyp
10
10
import { GitService } from 'src/common/gitService' ;
11
11
import { ReviewComment , replyNote } from './reviewCommentController' ;
12
12
import { MRUriScheme } from 'src/common/contants' ;
13
- import { IDiffComment , IMRData } from 'src/typings/respResult' ;
13
+ import { IDiffComment , IMRData , IFileDiffParam } from 'src/typings/respResult' ;
14
+ import { getDiffLineNumber , isHunkLine } from 'src/common/utils' ;
14
15
15
16
export async function activate ( context : vscode . ExtensionContext ) {
16
17
await GitService . init ( ) ;
@@ -54,13 +55,42 @@ export async function activate(context: vscode.ExtensionContext) {
54
55
context . subscriptions . push ( commentController ) ;
55
56
56
57
commentController . commentingRangeProvider = {
57
- provideCommentingRanges : ( document : vscode . TextDocument , token : vscode . CancellationToken ) => {
58
+ provideCommentingRanges : async (
59
+ document : vscode . TextDocument ,
60
+ token : vscode . CancellationToken ,
61
+ ) => {
58
62
if ( document . uri . scheme !== MRUriScheme ) {
59
- return ;
63
+ return [ ] ;
60
64
}
61
65
62
- const lineCount = document . lineCount ;
63
- return [ new vscode . Range ( 0 , 0 , lineCount - 1 , 0 ) ] ;
66
+ try {
67
+ const params = new URLSearchParams ( decodeURIComponent ( document . uri . query ) ) ;
68
+ const iid = params . get ( 'mr' ) || `` ;
69
+ let param : IFileDiffParam = {
70
+ path : params . get ( 'path' ) ?? `` ,
71
+ base : params . get ( 'leftSha' ) ?? `` ,
72
+ compare : params . get ( 'rightSha' ) ?? `` ,
73
+ mergeRequestId : iid ?? `` ,
74
+ } ;
75
+ const {
76
+ data : { diffLines } ,
77
+ } = await codingSrv . fetchFileDiffs ( param ) ;
78
+ const ret = diffLines . reduce ( ( result , i ) => {
79
+ const isHunk = isHunkLine ( i . text ) ;
80
+ if ( ! isHunk ) {
81
+ return result ;
82
+ }
83
+
84
+ const [ left , right ] = getDiffLineNumber ( i . text ) ;
85
+ const [ start , end ] = params . get ( 'right' ) ? right : left ;
86
+ result . push ( new vscode . Range ( start , 0 , end , 0 ) ) ;
87
+ return result ;
88
+ } , [ ] as vscode . Range [ ] ) ;
89
+ return ret ;
90
+ } catch ( e ) {
91
+ console . error ( 'fetch diff lines failed.' ) ;
92
+ return [ ] ;
93
+ }
64
94
} ,
65
95
} ;
66
96
@@ -211,9 +241,11 @@ export async function activate(context: vscode.ExtensionContext) {
211
241
async ( file : IFileNode , mr : IMRData ) => {
212
242
const headUri = vscode . Uri . parse ( file . path , false ) . with ( {
213
243
scheme : MRUriScheme ,
214
- query : `commit=${ file . newSha } &path=${ file . path } ` ,
244
+ query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=true&mr=${ mr . iid } ` ,
245
+ } ) ;
246
+ const parentUri = headUri . with ( {
247
+ query : `leftSha=${ file . oldSha } &rightSha=${ file . newSha } &path=${ file . path } &right=false&mr=${ mr . iid } ` ,
215
248
} ) ;
216
- const parentUri = headUri . with ( { query : `commit=${ file . oldSha } &path=${ file . path } ` } ) ;
217
249
await vscode . commands . executeCommand (
218
250
`vscode.diff` ,
219
251
parentUri ,
@@ -224,6 +256,7 @@ export async function activate(context: vscode.ExtensionContext) {
224
256
225
257
try {
226
258
const commentResp = await codingSrv . getMRComments ( mr . iid ) ;
259
+
227
260
( commentResp . data as IDiffComment [ ] [ ] )
228
261
. filter ( ( i ) => {
229
262
const first = i [ 0 ] ;
@@ -268,15 +301,15 @@ export async function activate(context: vscode.ExtensionContext) {
268
301
vscode . commands . registerCommand (
269
302
`codingPlugin.diff.createComment` ,
270
303
( reply : vscode . CommentReply ) => {
271
- replyNote ( reply ) ;
304
+ replyNote ( reply , context ) ;
272
305
} ,
273
306
) ,
274
307
) ;
275
308
context . subscriptions . push (
276
309
vscode . commands . registerCommand (
277
310
`codingPlugin.diff.replyComment` ,
278
311
( reply : vscode . CommentReply ) => {
279
- replyNote ( reply ) ;
312
+ replyNote ( reply , context ) ;
280
313
} ,
281
314
) ,
282
315
) ;
0 commit comments