@@ -10,7 +10,8 @@ import { IRepoInfo, IMRWebViewDetail, ISessionData } from 'src/typings/commonTyp
1010import { GitService } from 'src/common/gitService' ;
1111import { ReviewComment , replyNote } from './reviewCommentController' ;
1212import { 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' ;
1415
1516export async function activate ( context : vscode . ExtensionContext ) {
1617 await GitService . init ( ) ;
@@ -54,13 +55,42 @@ export async function activate(context: vscode.ExtensionContext) {
5455 context . subscriptions . push ( commentController ) ;
5556
5657 commentController . commentingRangeProvider = {
57- provideCommentingRanges : ( document : vscode . TextDocument , token : vscode . CancellationToken ) => {
58+ provideCommentingRanges : async (
59+ document : vscode . TextDocument ,
60+ token : vscode . CancellationToken ,
61+ ) => {
5862 if ( document . uri . scheme !== MRUriScheme ) {
59- return ;
63+ return [ ] ;
6064 }
6165
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+ }
6494 } ,
6595 } ;
6696
@@ -211,9 +241,11 @@ export async function activate(context: vscode.ExtensionContext) {
211241 async ( file : IFileNode , mr : IMRData ) => {
212242 const headUri = vscode . Uri . parse ( file . path , false ) . with ( {
213243 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 } ` ,
215248 } ) ;
216- const parentUri = headUri . with ( { query : `commit=${ file . oldSha } &path=${ file . path } ` } ) ;
217249 await vscode . commands . executeCommand (
218250 `vscode.diff` ,
219251 parentUri ,
@@ -224,6 +256,7 @@ export async function activate(context: vscode.ExtensionContext) {
224256
225257 try {
226258 const commentResp = await codingSrv . getMRComments ( mr . iid ) ;
259+
227260 ( commentResp . data as IDiffComment [ ] [ ] )
228261 . filter ( ( i ) => {
229262 const first = i [ 0 ] ;
@@ -268,15 +301,15 @@ export async function activate(context: vscode.ExtensionContext) {
268301 vscode . commands . registerCommand (
269302 `codingPlugin.diff.createComment` ,
270303 ( reply : vscode . CommentReply ) => {
271- replyNote ( reply ) ;
304+ replyNote ( reply , context ) ;
272305 } ,
273306 ) ,
274307 ) ;
275308 context . subscriptions . push (
276309 vscode . commands . registerCommand (
277310 `codingPlugin.diff.replyComment` ,
278311 ( reply : vscode . CommentReply ) => {
279- replyNote ( reply ) ;
312+ replyNote ( reply , context ) ;
280313 } ,
281314 ) ,
282315 ) ;
0 commit comments