| 1 | import * as vscode from "vscode"; |
| 2 | |
| 3 | import { VerticalDiffCodeLens } from "../../../diff/vertical/manager"; |
| 4 | import { getMetaKeyLabel } from "../../../util/util"; |
| 5 | |
| 6 | export class VerticalDiffCodeLensProvider implements vscode.CodeLensProvider { |
| 7 | private _eventEmitter: vscode.EventEmitter<void> = |
| 8 | new vscode.EventEmitter<void>(); |
| 9 | |
| 10 | onDidChangeCodeLenses: vscode.Event<void> = this._eventEmitter.event; |
| 11 | |
| 12 | public refresh(): void { |
| 13 | this._eventEmitter.fire(); |
| 14 | } |
| 15 | |
| 16 | constructor( |
| 17 | private readonly editorToVerticalDiffCodeLens: Map< |
| 18 | string, |
| 19 | VerticalDiffCodeLens[] |
| 20 | >, |
| 21 | ) {} |
| 22 | |
| 23 | public provideCodeLenses( |
| 24 | document: vscode.TextDocument, |
| 25 | _: vscode.CancellationToken, |
| 26 | ): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> { |
| 27 | const uri = document.uri.toString(); |
| 28 | const blocks = this.editorToVerticalDiffCodeLens.get(uri); |
| 29 | |
| 30 | if (!blocks) { |
| 31 | return []; |
| 32 | } |
| 33 | |
| 34 | const codeLenses: vscode.CodeLens[] = []; |
| 35 | |
| 36 | for (let i = 0; i < blocks.length; i++) { |
| 37 | const block = blocks[i]; |
| 38 | const start = new vscode.Position(block.start, 0); |
| 39 | const range = new vscode.Range( |
| 40 | start, |
| 41 | start.translate(block.numGreen + block.numRed), |
| 42 | ); |
| 43 | |
| 44 | codeLenses.push( |
| 45 | new vscode.CodeLens(range, { |
| 46 | title: `Accept`, |
| 47 | command: "continue.acceptVerticalDiffBlock", |
| 48 | arguments: [uri, i], |
| 49 | }), |
| 50 | new vscode.CodeLens(range, { |
| 51 | title: `Reject`, |
| 52 | command: "continue.rejectVerticalDiffBlock", |
| 53 | arguments: [uri, i], |
| 54 | }), |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | return codeLenses; |
| 59 | } |
| 60 | } |