import path from 'path' ; import { DecorationOptions , ExtensionContext , Position , Range , TextEditor , TextEditorDecorationType , ThemeColor , window , } from 'vscode' ; import { CsvEntry } from '../model' ; import { isValidColorDefinition } from './editor-utils' ; import { rangesFromStringDefinition } from './workspace-util' ; export const EDITOR_MAX_LETTER = 1024 ; param context param selections param editor return export const gutterDecorations = ( context , csvEntries , editor ) : TextEditorDecorationType [ ] => { return [ underlineDecoration ( csvEntries , editor ) , commentIconDecoration ( context , csvEntries , editor ) ] ; } ; param context param selections param editor return export const underlineDecoration = ( csvEntries , editor ) : TextEditorDecorationType => { const decoration = window . createTextEditorDecorationType ( { isWholeLine : false , opacity : '0.9' , borderWidth : '1px' , borderColor : '#0f0f0f' , borderStyle : 'none none dashed none' , dark : { borderColor : '#F6F6F6' , } , } ) ; const decorationOptions = [ ] ; csvEntries . forEach ( ( entry ) => { rangesFromStringDefinition ( entry . lines ) . forEach ( ( range ) => { decorationOptions . push ( { range } ) ; } ) ; } ) ; editor . setDecorations ( decoration , decorationOptions ) ; return decoration ; } ; param context param selections param editor return export const commentIconDecoration = ( context , csvEntries , editor ) : TextEditorDecorationType => { const decoration = window . createTextEditorDecorationType ( { isWholeLine : true , after : { contentIconPath : context . asAbsolutePath ( path . join ( 'dist' , 'speech-bubble-light.svg' ) ) , margin : '5px' , } , dark : { after : { contentIconPath : context . asAbsolutePath ( path . join ( 'dist' , 'speech-bubble-dark.svg' ) ) , } , } , } ) ; const decorationOptions = [ ] ; csvEntries . forEach ( ( entry ) => { rangesFromStringDefinition ( entry . lines ) . forEach ( ( range ) => { decorationOptions . push ( { range : new Range ( new Position ( range . start . line , EDITOR_MAX_LETTER ) , new Position ( range . start . line , EDITOR_MAX_LETTER ) ) , } ) ; } ) ; } ) ; editor . setDecorations ( decoration , decorationOptions ) ; return decoration ; } ; param selections param editor return export const colorizedBackgroundDecoration = ( selections , editor , color ) : TextEditorDecorationType => { const backgroundColorDefaultID = 'codereview.code.selection.background' ; const backgroundColorDefault = new ThemeColor ( backgroundColorDefaultID ) ; let backgroundColor ; if ( color === backgroundColorDefaultID ) { backgroundColor = backgroundColorDefault ; } else if ( isValidColorDefinition ( color ) ) { backgroundColor = color ; } else { console . log ( `Invalid background color definition: ${ color }` ) ; backgroundColor = backgroundColorDefault ; } const decoration = window . createTextEditorDecorationType ( { backgroundColor : backgroundColor , } ) ; editor . setDecorations ( decoration , selections ) ; return decoration ; } ;