@@ -23,12 +23,40 @@ export default class MergeConflictContentProvider implements vscode.TextDocument
2323
2424 async provideTextDocumentContent ( uri : vscode . Uri ) : Promise < string | null > {
2525 try {
26- const { scheme, range } = JSON . parse ( uri . query ) as { scheme : string ; range : { line : number , character : number } [ ] } ;
27- const [ start , end ] = range ;
26+ const { type, scheme, range, fullRange, ranges } = JSON . parse ( uri . query ) as { type : string , scheme : string ; range : { line : number , character : number } [ ] , fullRange : { line : number , character : number } [ ] , ranges : [ { line : number , character : number } [ ] , { line : number , character : number } [ ] ] [ ] } ;
2827
29- const document = await vscode . workspace . openTextDocument ( uri . with ( { scheme, query : '' } ) ) ;
30- const text = document . getText ( new vscode . Range ( start . line , start . character , end . line , end . character ) ) ;
31- return text ;
28+ if ( type === 'full' ) {
29+ // complete diff
30+ const document = await vscode . workspace . openTextDocument ( uri . with ( { scheme, query : '' } ) ) ;
31+
32+ let text = '' ;
33+ let lastPosition = new vscode . Position ( 0 , 0 ) ;
34+ ranges . forEach ( rangeObj => {
35+ let [ range , fullRange ] = rangeObj ;
36+ const [ start , end ] = range ;
37+ const [ fullStart , fullEnd ] = fullRange ;
38+
39+ text += document . getText ( new vscode . Range ( lastPosition . line , lastPosition . character , fullStart . line , fullStart . character ) ) ;
40+ text += document . getText ( new vscode . Range ( start . line , start . character , end . line , end . character ) ) ;
41+ lastPosition = new vscode . Position ( fullEnd . line , fullEnd . character ) ;
42+ } ) ;
43+
44+ let documentEnd = document . lineAt ( document . lineCount - 1 ) . range . end ;
45+ text += document . getText ( new vscode . Range ( lastPosition . line , lastPosition . character , documentEnd . line , documentEnd . character ) ) ;
46+
47+ return text ;
48+ } else {
49+ const [ start , end ] = range ;
50+ const [ fullStart , fullEnd ] = fullRange ;
51+ const mergeConflictConfig = vscode . workspace . getConfiguration ( 'merge-conflict' ) ;
52+ const context = Math . max ( 0 , mergeConflictConfig . get < number > ( 'diffViewContext' ) || 0 ) ;
53+ const document = await vscode . workspace . openTextDocument ( uri . with ( { scheme, query : '' } ) ) ;
54+ const text =
55+ document . getText ( new vscode . Range ( Math . max ( 0 , fullStart . line - context ) , 0 , fullStart . line , fullStart . character ) )
56+ + document . getText ( new vscode . Range ( start . line , start . character , end . line , end . character ) )
57+ + document . getText ( new vscode . Range ( fullEnd . line , fullEnd . character , Math . min ( document . lineCount , fullEnd . line + context + 1 ) , 0 ) ) ;
58+ return text ;
59+ }
3260 }
3361 catch ( ex ) {
3462 await vscode . window . showErrorMessage ( 'Unable to show comparison' ) ;
0 commit comments