import { CancellationToken , CodeLens , CodeLensProvider , Range , TextDocument , Command } from 'vscode' ; import { ExportFactory } from './export-factory' ; import { ReviewFileExportSection } from './interfaces' ; import { CsvEntry } from './model' ; import { symbolForPriority } from './utils/editor-utils' ; import { rangesFromStringDefinition } from './utils/workspace-util' ; export class CommentLensProvider implements CodeLensProvider { constructor ( private exportFactory ) { } public provideCodeLenses ( document , token ) { return this . exportFactory . getFilesContainingComments ( ) . then ( ( filesWithComments ) => { const codeLenses = [ ] ; filesWithComments . forEach ( ( el ) => { if ( document . fileName . endsWith ( el . data . group ) ) { el . data . lines . forEach ( ( csvEntry ) => { const fileSection = { group : csvEntry . filename , lines : el . data . lines , } ; const csvRef = csvEntry ; const prio = Number ( csvEntry . priority ) ; const priorityString = prio ? ` | Priority: ${ csvEntry . priority }${ symbolForPriority ( Number ( csvEntry . priority ) ) }` : '' ; const command = { title : `Code Review: ${ csvEntry . title }${ priorityString }` , tooltip : csvEntry . comment , command : 'codeReview.openSelection' , arguments : [ fileSection , csvRef ] , } ; rangesFromStringDefinition ( csvEntry . lines ) . forEach ( ( range ) => { codeLenses . push ( new CodeLens ( range , command ) ) ; } ) ; } ) ; } } ) ; return codeLenses ; } ) ; } }