@@ -7,7 +7,14 @@ import * as nvimFn from "../function/nvim/mod.ts";
7
7
8
8
const cacheKey = "denops_std/buffer/decoration/vimDecorate/rs@1" ;
9
9
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
+ } ;
11
18
12
19
export interface Decoration {
13
20
/**
@@ -64,12 +71,13 @@ export function decorate(
64
71
denops : Denops ,
65
72
bufnr : number ,
66
73
decorations : readonly Decoration [ ] ,
74
+ options : Readonly < DecorateOptions > = { } ,
67
75
) : Promise < void > {
68
76
switch ( denops . meta . host ) {
69
77
case "vim" :
70
- return vimDecorate ( denops , bufnr , decorations ) ;
78
+ return vimDecorate ( denops , bufnr , decorations , options ) ;
71
79
case "nvim" :
72
- return nvimDecorate ( denops , bufnr , decorations ) ;
80
+ return nvimDecorate ( denops , bufnr , decorations , options ) ;
73
81
default :
74
82
unreachable ( denops . meta . host ) ;
75
83
}
@@ -122,12 +130,13 @@ export function undecorate(
122
130
bufnr : number ,
123
131
start = 0 ,
124
132
end = - 1 ,
133
+ options : Readonly < DecorateOptions > = { } ,
125
134
) : Promise < void > {
126
135
switch ( denops . meta . host ) {
127
136
case "vim" :
128
- return vimUndecorate ( denops , bufnr , start , end ) ;
137
+ return vimUndecorate ( denops , bufnr , start , end , options ) ;
129
138
case "nvim" :
130
- return nvimUndecorate ( denops , bufnr , start , end ) ;
139
+ return nvimUndecorate ( denops , bufnr , start , end , options ) ;
131
140
default :
132
141
unreachable ( denops . meta . host ) ;
133
142
}
@@ -136,12 +145,13 @@ export function undecorate(
136
145
export function listDecorations (
137
146
denops : Denops ,
138
147
bufnr : number ,
148
+ options : Readonly < DecorateOptions > = { } ,
139
149
) : Promise < Decoration [ ] > {
140
150
switch ( denops . meta . host ) {
141
151
case "vim" :
142
- return vimListDecorations ( denops , bufnr ) ;
152
+ return vimListDecorations ( denops , bufnr , options ) ;
143
153
case "nvim" :
144
- return nvimListDecorations ( denops , bufnr ) ;
154
+ return nvimListDecorations ( denops , bufnr , options ) ;
145
155
default :
146
156
unreachable ( denops . meta . host ) ;
147
157
}
@@ -155,7 +165,9 @@ async function vimDecorate(
155
165
denops : Denops ,
156
166
bufnr : number ,
157
167
decorations : readonly Decoration [ ] ,
168
+ options : Readonly < DecorateOptions > = { } ,
158
169
) : Promise < void > {
170
+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
159
171
const toPropType = ( n : string ) => `${ prefix } :${ n } ` ;
160
172
const rs = ( denops . context [ cacheKey ] ?? new Set ( ) ) as Set < string > ;
161
173
denops . context [ cacheKey ] = rs ;
@@ -190,7 +202,9 @@ async function vimUndecorate(
190
202
bufnr : number ,
191
203
start : number ,
192
204
end : number ,
205
+ options : Readonly < DecorateOptions > ,
193
206
) : Promise < void > {
207
+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
194
208
const propList = await vimFn . prop_list ( denops , start + 1 , {
195
209
bufnr,
196
210
end_lnum : end ,
@@ -210,7 +224,9 @@ async function vimUndecorate(
210
224
async function vimListDecorations (
211
225
denops : Denops ,
212
226
bufnr : number ,
227
+ options : Readonly < DecorateOptions > ,
213
228
) : Promise < Decoration [ ] > {
229
+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
214
230
const props = await vimFn . prop_list ( denops , 1 , {
215
231
bufnr,
216
232
end_lnum : - 1 ,
@@ -238,7 +254,9 @@ async function nvimDecorate(
238
254
denops : Denops ,
239
255
bufnr : number ,
240
256
decorations : readonly Decoration [ ] ,
257
+ options : Readonly < DecorateOptions > ,
241
258
) : Promise < void > {
259
+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
242
260
const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
243
261
for ( const chunk of itertools . chunked ( decorations , 1000 ) ) {
244
262
await batch ( denops , async ( denops ) => {
@@ -262,15 +280,19 @@ async function nvimUndecorate(
262
280
bufnr : number ,
263
281
start : number ,
264
282
end : number ,
283
+ options : Readonly < DecorateOptions > ,
265
284
) : Promise < void > {
285
+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
266
286
const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
267
287
await nvimFn . nvim_buf_clear_namespace ( denops , bufnr , ns , start , end ) ;
268
288
}
269
289
270
290
async function nvimListDecorations (
271
291
denops : Denops ,
272
292
bufnr : number ,
293
+ options : Readonly < DecorateOptions > ,
273
294
) : Promise < Decoration [ ] > {
295
+ const prefix = options . namespace ?? `${ PREFIX } :${ denops . name } ` ;
274
296
const ns = await nvimFn . nvim_create_namespace ( denops , prefix ) ;
275
297
const extmarks = await nvimFn . nvim_buf_get_extmarks (
276
298
denops ,
0 commit comments