import * as vscode from 'vscode' ; import * as interfaces from './interfaces' ; export default class MergeConflictCodeLensProvider implements vscode . CodeLensProvider , vscode . Disposable { private disposables : vscode . Disposable [ ] = [ ] ; private config : interfaces . IExtensionConfiguration ; constructor ( private context , private tracker ) { } begin ( config ) { this . config = config ; this . disposables . push ( vscode . languages . registerCodeLensProvider ( { pattern : '**/*' } , this ) ) ; } configurationUpdated ( config ) { this . config = config ; } dispose ( ) { if ( this . disposables ) { this . disposables . forEach ( disposable => disposable . dispose ( ) ) ; this . disposables = null ; } } async provideCodeLenses ( document , token ) { if ( ! this . config || ! this . config . enableCodeLens ) { return null ; } let conflicts = await this . tracker . getConflicts ( document ) ; if ( ! conflicts || conflicts . length === 0 ) { return null ; } let items = [ ] ; conflicts . forEach ( conflict => { let acceptCurrentCommand = { command : 'better-merge.accept.current' , title : `Accept current change` , arguments : [ 'known-conflict' , conflict ] } ; let acceptIncomingCommand = { command : 'better-merge.accept.incoming' , title : `Accept incoming change` , arguments : [ 'known-conflict' , conflict ] } ; let acceptBothCommand = { command : 'better-merge.accept.both' , title : `Accept both changes` , arguments : [ 'known-conflict' , conflict ] } ; let diffCommand = { command : 'better-merge.compare' , title : `Compare changes` , arguments : [ conflict ] } ; items . push ( new vscode . CodeLens ( conflict . range , acceptCurrentCommand ) , new vscode . CodeLens ( conflict . range . with ( conflict . range . start . with ( { character : conflict . range . start . character + 1 } ) ) , acceptIncomingCommand ) , new vscode . CodeLens ( conflict . range . with ( conflict . range . start . with ( { character : conflict . range . start . character + 2 } ) ) , acceptBothCommand ) , new vscode . CodeLens ( conflict . range . with ( conflict . range . start . with ( { character : conflict . range . start . character + 3 } ) ) , diffCommand ) ) ; } ) ; return items ; } resolveCodeLens ( codeLens , token ) { return ; } }