Skip to content

Commit fbc478c

Browse files
committed
💪 Add prefix constant to simplify the code
1 parent 7634dad commit fbc478c

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

buffer/decoration.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import * as nvimFn from "../function/nvim/mod.ts";
77

88
const cacheKey = "denops_std/buffer/decoration/vimDecorate/rs@1";
99

10+
const prefix = "denops_std:buffer:decoration:decorate";
11+
1012
export interface Decoration {
1113
/**
1214
* Line number
@@ -140,8 +142,7 @@ async function vimDecorate(
140142
bufnr: number,
141143
decorations: Decoration[],
142144
): Promise<void> {
143-
const toPropType = (n: string) =>
144-
`denops_std:buffer:decoration:decorate:${n}`;
145+
const toPropType = (n: string) => `${prefix}:${n}`;
145146
const rs = (denops.context[cacheKey] ?? new Set()) as Set<string>;
146147
denops.context[cacheKey] = rs;
147148
const hs = uniq(decorations.map((v) => v.highlight)).filter((v) =>
@@ -180,9 +181,9 @@ async function vimUndecorate(
180181
end_lnum: end,
181182
}) as { id: string; type: string }[];
182183
const propIds = new Set(
183-
propList.filter((p) =>
184-
p.type.startsWith("denops_std:buffer:decoration:decorate:")
185-
).map((p) => p.id),
184+
propList
185+
.filter((p) => p.type.startsWith(`${prefix}:`))
186+
.map((p) => p.id),
186187
);
187188
await batch(denops, async (denops) => {
188189
for (const propId of propIds) {
@@ -196,10 +197,7 @@ async function nvimDecorate(
196197
bufnr: number,
197198
decorations: Decoration[],
198199
): Promise<void> {
199-
const ns = await nvimFn.nvim_create_namespace(
200-
denops,
201-
"denops_std:buffer:decoration:decorate",
202-
);
200+
const ns = await nvimFn.nvim_create_namespace(denops, prefix);
203201
for (const chunk of itertools.chunked(decorations, 1000)) {
204202
await batch(denops, async (denops) => {
205203
for (const deco of chunk) {
@@ -223,9 +221,6 @@ async function nvimUndecorate(
223221
start: number,
224222
end: number,
225223
): Promise<void> {
226-
const ns = await nvimFn.nvim_create_namespace(
227-
denops,
228-
"denops_std:buffer:decoration:decorate",
229-
);
224+
const ns = await nvimFn.nvim_create_namespace(denops, prefix);
230225
await nvimFn.nvim_buf_clear_namespace(denops, bufnr, ns, start, end);
231226
}

0 commit comments

Comments
 (0)