import { FloatFactory , workspace } from "coc.nvim" ; import { PublishDecorationsParams } from "./metalsProtocol" ; import { DecorationOptions } from "./portedProtocol" ; export default class DecorationProvider { private currentDecorations : DecorationOptions [ ] = [ ] ; private decorationNameSpace = workspace . createNameSpace ( "worksheetDecorations" ) ; private floatFactory : FloatFactory ; constructor ( floatFactory ) { this . floatFactory = floatFactory ; } public async setDecorations ( decorationParams ) { const doc = workspace . getDocument ( decorationParams . uri ) ; const { buffer } = doc ; buffer . clearNamespace ( this . decorationNameSpace ) ; this . currentDecorations = [ ] ; decorationParams . options . forEach ( ( option ) => { this . currentDecorations . push ( option ) ; buffer . setVirtualText ( this . decorationNameSpace , option . range . end . line , [ [ option . renderOptions ?. after ?. contentText ?. replace ( "//" , "‣" ) ?? "" , "Comment" , ] , ] ) ; } ) ; } public async showHover ( ) { const { position } = await workspace . getCurrentState ( ) ; const hoverText = this . currentDecorations . find ( ( decoration ) => decoration . range . end . line === position . line ) ; if ( hoverText && typeof hoverText . hoverMessage !== "string" && hoverText . hoverMessage ) { await this . floatFactory . create ( [ { content : hoverText . hoverMessage . value , filetype : hoverText . hoverMessage . kind , } , ] , true , 0 ) ; } } public clearDecorations ( bufnr ) { const doc = workspace . getDocument ( bufnr ) ; const { buffer } = doc ; buffer . clearNamespace ( this . decorationNameSpace ) ; this . currentDecorations = [ ] ; } }