@@ -133,6 +133,20 @@ export function undecorate(
133133 }
134134}
135135
136+ export function listDecorations (
137+ denops : Denops ,
138+ bufnr : number ,
139+ ) : Promise < Decoration [ ] > {
140+ switch ( denops . meta . host ) {
141+ case "vim" :
142+ return vimListDecorations ( denops , bufnr ) ;
143+ case "nvim" :
144+ return nvimListDecorations ( denops , bufnr ) ;
145+ default :
146+ unreachable ( denops . meta . host ) ;
147+ }
148+ }
149+
136150function uniq < T > ( array : readonly T [ ] ) : T [ ] {
137151 return [ ...new Set ( array ) ] ;
138152}
@@ -192,6 +206,33 @@ async function vimUndecorate(
192206 } ) ;
193207}
194208
209+ async function vimListDecorations (
210+ denops : Denops ,
211+ bufnr : number ,
212+ ) : Promise < Decoration [ ] > {
213+ const props = await vimFn . prop_list ( denops , 1 , {
214+ bufnr,
215+ end_lnum : - 1 ,
216+ } ) as {
217+ col : number ;
218+ end : number ;
219+ id : number ;
220+ length : number ;
221+ lnum : number ;
222+ start : number ;
223+ type : string ;
224+ type_bufnr : number ;
225+ } [ ] ;
226+ return props
227+ . filter ( ( prop ) => prop . type . startsWith ( `${ prefix } :` ) )
228+ . map ( ( prop ) => ( {
229+ line : prop . lnum ,
230+ column : prop . col ,
231+ length : prop . length ,
232+ highlight : prop . type . split ( ":" ) . pop ( ) as string ,
233+ } ) ) ;
234+ }
235+
195236async function nvimDecorate (
196237 denops : Denops ,
197238 bufnr : number ,
@@ -224,3 +265,38 @@ async function nvimUndecorate(
224265 const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
225266 await nvimFn . nvim_buf_clear_namespace ( denops , bufnr , ns , start , end ) ;
226267}
268+
269+ async function nvimListDecorations (
270+ denops : Denops ,
271+ bufnr : number ,
272+ ) : Promise < Decoration [ ] > {
273+ const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
274+ const extmarks = await nvimFn . nvim_buf_get_extmarks (
275+ denops ,
276+ bufnr ,
277+ ns ,
278+ 0 ,
279+ - 1 ,
280+ { details : true } ,
281+ ) as [
282+ extmark_id : number ,
283+ row : number ,
284+ col : number ,
285+ {
286+ hl_group : string ;
287+ hl_eol : boolean ;
288+ end_right_gravity : boolean ;
289+ priority : number ;
290+ right_gravity : boolean ;
291+ end_col : number ;
292+ ns_id : number ;
293+ end_row : number ;
294+ } ,
295+ ] [ ] ;
296+ return extmarks . map ( ( extmark ) => ( {
297+ line : extmark [ 1 ] + 1 ,
298+ column : extmark [ 2 ] + 1 ,
299+ length : extmark [ 3 ] . end_col - extmark [ 2 ] ,
300+ highlight : extmark [ 3 ] . hl_group ,
301+ } ) ) ;
302+ }
0 commit comments