Skip to content

Commit 77c96ee

Browse files
committed
feat: add @fall-config module that is published as config
1 parent a9e6558 commit 77c96ee

File tree

11 files changed

+306
-23
lines changed

11 files changed

+306
-23
lines changed

.github/workflows/jsr.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: jsr
2+
3+
env:
4+
DENO_VERSION: 2.x
5+
6+
on:
7+
push:
8+
tags:
9+
- "v*"
10+
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- uses: denoland/setup-deno@v2
23+
with:
24+
deno-version: ${{ env.DENO_VERSION }}
25+
- name: Publish
26+
run: |
27+
deno run -A jsr:@david/publish-on-tag@0.1.4

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,14 @@ jobs:
121121
os: ${{ runner.os }}
122122
files: ./coverage.lcov
123123
token: ${{ secrets.CODECOV_TOKEN }}
124+
125+
jsr-publish:
126+
runs-on: ubuntu-latest
127+
steps:
128+
- uses: actions/checkout@v4
129+
- uses: denoland/setup-deno@v2
130+
with:
131+
deno-version: "2.x"
132+
- name: Publish (dry-run)
133+
run: |
134+
deno publish --dry-run

deno.jsonc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
{
2+
"name": "@vim-fall/config",
3+
"version": "0.0.0",
4+
"exports": {
5+
".": "./denops/@fall-config/mod.ts",
6+
"./config": "./denops/@fall-config/config.ts",
7+
"./derivable": "./denops/@fall-config/derivable.ts"
8+
},
9+
"publish": {
10+
"include": [
11+
"**/*.ts",
12+
"./denops/@fall-config/README.md",
13+
"LICENSE"
14+
],
15+
"exclude": [
16+
".script/**",
17+
"*_test.ts",
18+
"*_bench.ts",
19+
"./denops/fall/**"
20+
]
21+
},
222
"exclude": [
323
"docs/**",
424
".coverage/**"

denops/@fall-config/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 🍂 fall-config
2+
3+
[![JSR](https://jsr.io/badges/@vim-fall/config)](https://jsr.io/@vim-fall/config)
4+
[![Deno](https://img.shields.io/badge/Deno%202.x-333?logo=deno&logoColor=fff)](#)
5+
[![Test](https://github.com/vim-fall/fall.vim/actions/workflows/test.yml/badge.svg)](https://github.com/vim-fall/fall.vim/actions/workflows/test.yml)
6+
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7+
8+
Module to configure [Fall](https://github.com/vim-fall/fall.vim), a Vim/Neovim
9+
fuzzy finder plugin powered by
10+
[Denops](https://github.com/vim-denops/denops.vim).
11+
12+
## License
13+
14+
This repository is licensed under the MIT License, as detailed in the
15+
[LICENSE](./LICENSE) file. By contributing, you agree that any modifications you
16+
submit will also be licensed under the MIT License.

denops/@fall-config/config.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import type { Denops } from "jsr:@denops/std@^7.3.2";
2+
import type {
3+
Action,
4+
Coordinator,
5+
Curator,
6+
Detail,
7+
Matcher,
8+
Previewer,
9+
Renderer,
10+
Sorter,
11+
Source,
12+
Theme,
13+
} from "jsr:@vim-fall/core@^0.2.1";
14+
15+
import type { Derivable, DerivableArray, DerivableMap } from "./derivable.ts";
16+
17+
/**
18+
* Represents a collection of actions that can be invoked.
19+
*
20+
* @template T - The type of items the actions operate on.
21+
* @template A - The type representing the default action name.
22+
*/
23+
export type Actions<T extends Detail, A extends string> =
24+
& Record<string, Action<T>>
25+
& { [key in A]: Action<T> };
26+
27+
/**
28+
* Parameters required to configure an item picker.
29+
*
30+
* @template T - The type of items in the picker.
31+
* @template A - The type representing the default action name.
32+
*/
33+
export type ItemPickerParams<T extends Detail, A extends string> = {
34+
name: string;
35+
source: Source<T>;
36+
actions: Actions<T, NoInfer<A>>;
37+
defaultAction: A;
38+
matchers: [Matcher<NoInfer<T>>, ...Matcher<NoInfer<T>>[]];
39+
sorters?: Sorter<NoInfer<T>>[];
40+
renderers?: Renderer<NoInfer<T>>[];
41+
previewers?: Previewer<NoInfer<T>>[];
42+
coordinator?: Coordinator;
43+
theme?: Theme;
44+
};
45+
46+
/**
47+
* Parameters required to configure an action picker.
48+
*/
49+
export type ActionPickerParams = {
50+
matchers: [Matcher<Action<Detail>>, ...Matcher<Action<Detail>>[]];
51+
sorters?: Sorter<Action<Detail>>[];
52+
renderers?: Renderer<Action<Detail>>[];
53+
previewers?: Previewer<Action<Detail>>[];
54+
coordinator?: Coordinator;
55+
theme?: Theme;
56+
};
57+
58+
/**
59+
* Global configuration settings.
60+
*/
61+
export type GlobalConfig = {
62+
coordinator: Coordinator;
63+
theme: Theme;
64+
};
65+
66+
/**
67+
* Defines an item picker based on a source and matchers.
68+
*
69+
* @template T - The type of items handled by the picker.
70+
* @template A - The type representing the default action name.
71+
*/
72+
export type DefineItemPickerFromSource = <T extends Detail, A extends string>(
73+
name: string,
74+
source: Derivable<Source<T>>,
75+
params: {
76+
actions: DerivableMap<Actions<NoInfer<T>, NoInfer<A>>>;
77+
defaultAction: A;
78+
matchers: DerivableArray<[Matcher<NoInfer<T>>, ...Matcher<NoInfer<T>>[]]>;
79+
sorters?: DerivableArray<Sorter<NoInfer<T>>[]>;
80+
renderers?: DerivableArray<Renderer<NoInfer<T>>[]>;
81+
previewers?: DerivableArray<Previewer<NoInfer<T>>[]>;
82+
coordinator?: Derivable<Coordinator>;
83+
theme?: Derivable<Theme>;
84+
},
85+
) => void;
86+
87+
/**
88+
* Defines an item picker based on a curator.
89+
*
90+
* @template T - The type of items handled by the picker.
91+
* @template A - The type representing the default action name.
92+
*/
93+
export type DefineItemPickerFromCurator = <T extends Detail, A extends string>(
94+
name: string,
95+
curator: Derivable<Curator<T>>,
96+
params: {
97+
actions: DerivableMap<Actions<NoInfer<T>, NoInfer<A>>>;
98+
defaultAction: A;
99+
sorters?: DerivableArray<Sorter<NoInfer<T>>[]>;
100+
renderers?: DerivableArray<Renderer<NoInfer<T>>[]>;
101+
previewers?: DerivableArray<Previewer<NoInfer<T>>[]>;
102+
coordinator?: Derivable<Coordinator>;
103+
theme?: Derivable<Theme>;
104+
},
105+
) => void;
106+
107+
/**
108+
* Refines the configuration for an action picker.
109+
*/
110+
export type RefineActionPicker = (
111+
params: {
112+
matchers: DerivableArray<
113+
[Matcher<Action<Detail>>, ...Matcher<Action<Detail>>[]]
114+
>;
115+
sorters?: DerivableArray<Sorter<Action<Detail>>[]>;
116+
renderers?: DerivableArray<Renderer<Action<Detail>>[]>;
117+
previewers?: DerivableArray<Previewer<Action<Detail>>[]>;
118+
coordinator?: Derivable<Coordinator>;
119+
theme?: Derivable<Theme>;
120+
},
121+
) => void;
122+
123+
/**
124+
* Refines the global configuration, allowing customization of global coordinator and theme.
125+
*/
126+
export type RefineGlobalConfig = (
127+
params: {
128+
coordinator?: Derivable<Coordinator>;
129+
theme?: Derivable<Theme>;
130+
},
131+
) => void;
132+
133+
/**
134+
* The entrypoint for configuring the picker environment.
135+
*
136+
* @param params - An object containing various picker setup functions and the Denops instance.
137+
*/
138+
export type Entrypoint = (params: {
139+
denops: Denops;
140+
defineItemPickerFromSource: DefineItemPickerFromSource;
141+
defineItemPickerFromCurator: DefineItemPickerFromCurator;
142+
refineActionPicker: RefineActionPicker;
143+
refineGlobalConfig: RefineGlobalConfig;
144+
}) => void | Promise<void>;

denops/@fall-config/derivable.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// deno-lint-ignore-file no-explicit-any
2+
type NonFunction<T> = T extends (...args: any[]) => any ? never : T;
3+
4+
/**
5+
* A type that represents a value that can be either `T` or a function that returns `T`.
6+
* Ensures `T` is not a function type.
7+
*/
8+
export type Derivable<T extends NonFunction<unknown>> = T | (() => T);
9+
10+
/**
11+
* A map type where each property can either be of type `T` or a function that returns `T`.
12+
*/
13+
export type DerivableMap<M extends Record<string, NonFunction<unknown>>> = {
14+
[K in keyof M]: Derivable<M[K]>;
15+
};
16+
17+
/**
18+
* An array type where each element can either be of type `T` or a function that returns `T`.
19+
*/
20+
export type DerivableArray<A extends NonFunction<unknown>[]> = {
21+
[K in keyof A]: Derivable<A[K]>;
22+
};
23+
24+
/**
25+
* Gets the value of a derivable, resolving it if it is a function.
26+
*
27+
* @param value - The derivable value or function.
28+
* @returns The resolved value of type `T`.
29+
*/
30+
export function derive<T extends NonFunction<unknown>>(value: Derivable<T>): T {
31+
return value instanceof Function ? value() : value;
32+
}
33+
34+
/**
35+
* Resolves all derivables in a map, returning the resolved values.
36+
*
37+
* @param map - An object where each property may be a derivable.
38+
* @returns A new object with each property resolved.
39+
*/
40+
export function deriveMap<
41+
M extends Record<PropertyKey, unknown>,
42+
R extends { [K in keyof M]: M[K] extends Derivable<infer T> ? T : M[K] },
43+
>(map: M): R {
44+
return Object.fromEntries(
45+
Object.entries(map).map(([k, v]) => {
46+
return [k, derive(v)];
47+
}),
48+
) as R;
49+
}
50+
51+
/**
52+
* Resolves all derivables in an array, returning the resolved values.
53+
*
54+
* @param array - An array where each element may be a derivable.
55+
* @returns A new array with each element resolved.
56+
*/
57+
export function deriveArray<
58+
A extends NonFunction<any>[],
59+
R extends { [K in keyof A]: A[K] extends Derivable<infer T> ? T : A[K] },
60+
>(array: A): R {
61+
return array.map((v) => derive(v)) as R;
62+
}

denops/@fall-config/mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./config.ts";
2+
export * from "./derivable.ts";

denops/fall/config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ import {
1414
resetItemPickerParams,
1515
} from "./config/item_picker.ts";
1616

17-
export { getGlobalConfig } from "./config/global_config.ts";
18-
export { getActionPickerParams } from "./config/action_picker.ts";
19-
export {
20-
getItemPickerParams,
21-
listItemPickerNames,
22-
} from "./config/item_picker.ts";
23-
2417
export async function loadUserConfig(
2518
denops: Denops,
2619
path: string,
@@ -49,3 +42,10 @@ export async function loadUserConfig(
4942
await main(ctx);
5043
}
5144
}
45+
46+
export { getGlobalConfig } from "./config/global_config.ts";
47+
export { getActionPickerParams } from "./config/action_picker.ts";
48+
export {
49+
getItemPickerParams,
50+
listItemPickerNames,
51+
} from "./config/item_picker.ts";

denops/fall/config/action_picker.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
import { modern } from "jsr:@vim-fall/std@^0.4.0/builtin/coordinator/modern";
2+
import { fzf as fzfMatcher } from "jsr:@vim-fall/std@^0.4.0/builtin/matcher/fzf";
3+
14
import type {
25
ActionPickerParams,
36
GlobalConfig,
47
RefineActionPicker,
5-
} from "jsr:@vim-fall/std@^0.4.0/config";
6-
import { modern as modernCoordinator } from "jsr:@vim-fall/std@^0.4.0/builtin/coordinator/modern";
7-
import { fzf as fzfMatcher } from "jsr:@vim-fall/std@^0.4.0/builtin/matcher/fzf";
8-
import { derive, deriveArray } from "jsr:@vim-fall/std@^0.4.0/util/derivable";
9-
8+
} from "../../@fall-config/config.ts";
9+
import { derive, deriveArray } from "../../@fall-config/derivable.ts";
1010
import { getGlobalConfig } from "./global_config.ts";
1111

1212
const actionPickerParams: ActionPickerParams = {
1313
matchers: [fzfMatcher()],
14-
coordinator: modernCoordinator({
14+
coordinator: modern({
1515
hidePreview: true,
1616
widthRatio: 0.4,
1717
heightRatio: 0.4,
@@ -20,7 +20,7 @@ const actionPickerParams: ActionPickerParams = {
2020

2121
export function resetActionPickerParams(): void {
2222
actionPickerParams.matchers = [fzfMatcher()];
23-
actionPickerParams.coordinator = modernCoordinator({
23+
actionPickerParams.coordinator = modern({
2424
hidePreview: true,
2525
widthRatio: 0.4,
2626
heightRatio: 0.4,

denops/fall/config/global_config.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
import { modern as modern } from "jsr:@vim-fall/std@^0.4.0/builtin/coordinator/modern";
2+
import { MODERN_THEME } from "jsr:@vim-fall/std@^0.4.0/builtin/theme/modern";
3+
14
import type {
25
GlobalConfig,
36
RefineGlobalConfig,
4-
} from "jsr:@vim-fall/std@^0.4.0/config";
5-
import { modern as modernLayout } from "jsr:@vim-fall/std@^0.4.0/builtin/coordinator/modern";
6-
import { MODERN_THEME } from "jsr:@vim-fall/std@^0.4.0/builtin/theme/modern";
7-
import { derive } from "jsr:@vim-fall/std@^0.4.0/util/derivable";
7+
} from "../../@fall-config/config.ts";
8+
import { derive } from "../../@fall-config/derivable.ts";
89

910
const globalConfig: GlobalConfig = {
10-
coordinator: modernLayout(),
11+
coordinator: modern(),
1112
theme: MODERN_THEME,
1213
};
1314

1415
export function resetGlobalConfig(): void {
15-
globalConfig.coordinator = modernLayout();
16+
globalConfig.coordinator = modern();
1617
globalConfig.theme = MODERN_THEME;
1718
}
1819

0 commit comments

Comments
 (0)