@@ -7,7 +7,14 @@ import * as nvimFn from "../function/nvim/mod.ts";
77
88const cacheKey = "denops_std/buffer/decoration/vimDecorate/rs@1" ;
99
10- const prefix = "denops_std:buffer:decoration:decorate" ;
10+ const PREFIX = "denops_std:buffer:decoration:decorate" ;
11+
12+ export type DecorateOptions = {
13+ /**
14+ * Decoration namespace
15+ */
16+ namespace ?: string ;
17+ } ;
1118
1219export interface Decoration {
1320 /**
@@ -64,12 +71,13 @@ export function decorate(
6471 denops : Denops ,
6572 bufnr : number ,
6673 decorations : readonly Decoration [ ] ,
74+ options : Readonly < DecorateOptions > = { } ,
6775) : Promise < void > {
6876 switch ( denops . meta . host ) {
6977 case "vim" :
70- return vimDecorate ( denops , bufnr , decorations ) ;
78+ return vimDecorate ( denops , bufnr , decorations , options ) ;
7179 case "nvim" :
72- return nvimDecorate ( denops , bufnr , decorations ) ;
80+ return nvimDecorate ( denops , bufnr , decorations , options ) ;
7381 default :
7482 unreachable ( denops . meta . host ) ;
7583 }
@@ -122,12 +130,13 @@ export function undecorate(
122130 bufnr : number ,
123131 start = 0 ,
124132 end = - 1 ,
133+ options : Readonly < DecorateOptions > = { } ,
125134) : Promise < void > {
126135 switch ( denops . meta . host ) {
127136 case "vim" :
128- return vimUndecorate ( denops , bufnr , start , end ) ;
137+ return vimUndecorate ( denops , bufnr , start , end , options ) ;
129138 case "nvim" :
130- return nvimUndecorate ( denops , bufnr , start , end ) ;
139+ return nvimUndecorate ( denops , bufnr , start , end , options ) ;
131140 default :
132141 unreachable ( denops . meta . host ) ;
133142 }
@@ -136,12 +145,13 @@ export function undecorate(
136145export function listDecorations (
137146 denops : Denops ,
138147 bufnr : number ,
148+ options : Readonly < DecorateOptions > = { } ,
139149) : Promise < Decoration [ ] > {
140150 switch ( denops . meta . host ) {
141151 case "vim" :
142- return vimListDecorations ( denops , bufnr ) ;
152+ return vimListDecorations ( denops , bufnr , options ) ;
143153 case "nvim" :
144- return nvimListDecorations ( denops , bufnr ) ;
154+ return nvimListDecorations ( denops , bufnr , options ) ;
145155 default :
146156 unreachable ( denops . meta . host ) ;
147157 }
@@ -155,7 +165,9 @@ async function vimDecorate(
155165 denops : Denops ,
156166 bufnr : number ,
157167 decorations : readonly Decoration [ ] ,
168+ options : Readonly < DecorateOptions > = { } ,
158169) : Promise < void > {
170+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
159171 const toPropType = ( n : string ) => `${ prefix } :${ n } ` ;
160172 const rs = ( denops . context [ cacheKey ] ?? new Set ( ) ) as Set < string > ;
161173 denops . context [ cacheKey ] = rs ;
@@ -190,7 +202,9 @@ async function vimUndecorate(
190202 bufnr : number ,
191203 start : number ,
192204 end : number ,
205+ options : Readonly < DecorateOptions > ,
193206) : Promise < void > {
207+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
194208 const propList = await vimFn . prop_list ( denops , start + 1 , {
195209 bufnr,
196210 end_lnum : end ,
@@ -210,7 +224,9 @@ async function vimUndecorate(
210224async function vimListDecorations (
211225 denops : Denops ,
212226 bufnr : number ,
227+ options : Readonly < DecorateOptions > ,
213228) : Promise < Decoration [ ] > {
229+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
214230 const props = await vimFn . prop_list ( denops , 1 , {
215231 bufnr,
216232 end_lnum : - 1 ,
@@ -238,7 +254,9 @@ async function nvimDecorate(
238254 denops : Denops ,
239255 bufnr : number ,
240256 decorations : readonly Decoration [ ] ,
257+ options : Readonly < DecorateOptions > ,
241258) : Promise < void > {
259+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
242260 const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
243261 for ( const chunk of itertools . chunked ( decorations , 1000 ) ) {
244262 await batch ( denops , async ( denops ) => {
@@ -262,15 +280,19 @@ async function nvimUndecorate(
262280 bufnr : number ,
263281 start : number ,
264282 end : number ,
283+ options : Readonly < DecorateOptions > ,
265284) : Promise < void > {
285+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
266286 const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
267287 await nvimFn . nvim_buf_clear_namespace ( denops , bufnr , ns , start , end ) ;
268288}
269289
270290async function nvimListDecorations (
271291 denops : Denops ,
272292 bufnr : number ,
293+ options : Readonly < DecorateOptions > ,
273294) : Promise < Decoration [ ] > {
295+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
274296 const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
275297 const extmarks = await nvimFn . nvim_buf_get_extmarks (
276298 denops ,
0 commit comments