Skip to content

Commit 6db918c

Browse files
committed
☕ To specify which docs to apply to common functions
1 parent 437a441 commit 6db918c

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

scripts/gen-function/gen-function.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import * as path from "https://deno.land/std@0.183.0/path/mod.ts";
66
import { parse } from "./parse.ts";
77
import { format } from "./format.ts";
8+
import { DOCS_OVERRIDES } from "./override.ts";
89
import { transform } from "./transform.ts";
910
import { downloadString } from "../utils.ts";
1011

@@ -62,12 +63,20 @@ const nvimFnSet = difference(
6263
manualFnSet,
6364
);
6465

66+
const nvimDefMap = new Map(nvimDefs.map((def) => [def.fn, def]));
67+
const commonDefs = vimDefs
68+
.map((vimDef) =>
69+
DOCS_OVERRIDES[vimDef.fn] === "nvim"
70+
? { ...vimDef, docs: nvimDefMap.get(vimDef.fn)!.docs }
71+
: vimDef
72+
);
73+
6574
const commonFnSet = intersection(vimFnSet, nvimFnSet);
6675
const vimOnlyFnSet = difference(vimFnSet, nvimFnSet);
6776
const nvimOnlyFnSet = difference(nvimFnSet, vimFnSet);
6877

6978
const commonCode = format(
70-
vimDefs.filter((def) => commonFnSet.has(def.fn)),
79+
commonDefs.filter((def) => commonFnSet.has(def.fn)),
7180
);
7281
const vimOnlyCode = format(
7382
vimDefs.filter((def) => vimOnlyFnSet.has(def.fn)),
@@ -89,7 +98,7 @@ await Deno.writeTextFile(
8998
nvimOnlyCode.join("\n"),
9099
);
91100

92-
await transform(resolvePath(commonManualModule), vimDefs);
101+
await transform(resolvePath(commonManualModule), commonDefs);
93102
await transform(resolvePath(vimManualModule), vimDefs);
94103
await transform(resolvePath(nvimManualModule), nvimDefs);
95104

scripts/gen-function/override.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { DocsType } from "./types.ts";
2+
3+
/**
4+
* Mapping between function name to `DocsType`.
5+
*/
6+
export const DOCS_OVERRIDES: Readonly<Record<string, DocsType>> = {
7+
has: "nvim",
8+
};

scripts/gen-function/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export type Definition = {
1111
docs: string;
1212
vars: Variant[];
1313
};
14+
15+
export type DocsType = "vim" | "nvim";

scripts/gen-option/gen-option.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import * as path from "https://deno.land/std@0.183.0/path/mod.ts";
66
import { parse } from "./parse.ts";
77
import { format } from "./format.ts";
8+
import { DOCS_OVERRIDES } from "./override.ts";
89
import { transform } from "./transform.ts";
910
import { downloadString } from "../utils.ts";
1011

@@ -58,12 +59,20 @@ const nvimOptionSet = difference(
5859
manualOptionSet,
5960
);
6061

62+
const nvimDefMap = new Map(nvimDefs.map((def) => [def.name, def]));
63+
const commonDefs = vimDefs
64+
.map((vimDef) =>
65+
DOCS_OVERRIDES[vimDef.name] === "nvim"
66+
? { ...vimDef, docs: nvimDefMap.get(vimDef.name)!.docs }
67+
: vimDef
68+
);
69+
6170
const commonOptionSet = intersection(vimOptionSet, nvimOptionSet);
6271
const vimOnlyOptionSet = difference(vimOptionSet, nvimOptionSet);
6372
const nvimOnlyOptionSet = difference(nvimOptionSet, vimOptionSet);
6473

6574
const commonCode = format(
66-
vimDefs.filter((def) => commonOptionSet.has(def.name)),
75+
commonDefs.filter((def) => commonOptionSet.has(def.name)),
6776
".",
6877
);
6978
const vimOnlyCode = format(
@@ -88,7 +97,7 @@ await Deno.writeTextFile(
8897
nvimOnlyCode.join("\n"),
8998
);
9099

91-
await transform(resolvePath(commonManualModule), vimDefs);
100+
await transform(resolvePath(commonManualModule), commonDefs);
92101
await transform(resolvePath(vimManualModule), vimDefs);
93102
await transform(resolvePath(nvimManualModule), nvimDefs);
94103

scripts/gen-option/override.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { DocsType } from "./types.ts";
2+
3+
/**
4+
* Mapping between function name to `DocsType`.
5+
*/
6+
export const DOCS_OVERRIDES: Readonly<Record<string, DocsType>> = {};

scripts/gen-option/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ export type OptionScope = typeof OPTION_SCOPES[number];
2020
export function isOptionScope(x: unknown): x is OptionScope {
2121
return OPTION_SCOPES.includes(x as OptionScope);
2222
}
23+
24+
export type DocsType = "vim" | "nvim";

0 commit comments

Comments
 (0)