Skip to content

Commit ef15640

Browse files
committed
feat: automatically reload when picker config is saved
1 parent d7217d9 commit ef15640

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

autoload/fall/command/FallConfig.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ function! fall#command#FallConfig#call() abort
1414
call writefile(readfile(s:fall_config_template), l:path)
1515
endif
1616
execute 'vsplit' fnameescape(l:path)
17+
augroup fall_config
18+
autocmd!
19+
autocmd BufWritePost <buffer> call s:reload()
20+
augroup END
21+
endfunction
22+
23+
function! s:reload() abort
24+
call denops#request('fall', 'picker:reload', [])
1725
endfunction

denops/fall/config.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import type { Denops } from "jsr:@denops/std@^7.3.0";
22

3-
import { refineActionPicker } from "./config/action_picker.ts";
4-
import { refineGlobalConfig } from "./config/global_config.ts";
3+
import {
4+
refineActionPicker,
5+
resetActionPickerParams,
6+
} from "./config/action_picker.ts";
7+
import {
8+
refineGlobalConfig,
9+
resetGlobalConfig,
10+
} from "./config/global_config.ts";
511
import {
612
defineItemPickerFromCurator,
713
defineItemPickerFromSource,
14+
resetItemPickerParams,
815
} from "./config/item_picker.ts";
916

1017
export { getGlobalConfig } from "./config/global_config.ts";
@@ -17,6 +24,7 @@ export {
1724
export async function loadUserConfig(
1825
denops: Denops,
1926
path: string,
27+
{ suffix }: { suffix?: string } = {},
2028
): Promise<void> {
2129
const ctx = {
2230
denops,
@@ -26,7 +34,10 @@ export async function loadUserConfig(
2634
refineGlobalConfig,
2735
};
2836
try {
29-
const { main } = await import(path);
37+
const { main } = await import(`${path}${suffix ?? ""}`);
38+
resetGlobalConfig();
39+
resetActionPickerParams();
40+
resetItemPickerParams();
3041
await main(ctx);
3142
} catch (e) {
3243
console.warn(

denops/fall/config/action_picker.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ const actionPickerParams: ActionPickerParams = {
1818
}),
1919
};
2020

21+
export function resetActionPickerParams(): void {
22+
actionPickerParams.matchers = [fzfMatcher()];
23+
actionPickerParams.coordinator = modernCoordinator({
24+
hidePreview: true,
25+
widthRatio: 0.4,
26+
heightRatio: 0.4,
27+
});
28+
}
29+
2130
export function getActionPickerParams(): Readonly<
2231
ActionPickerParams & GlobalConfig
2332
> {

denops/fall/config/global_config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const globalConfig: GlobalConfig = {
1111
theme: MODERN_THEME,
1212
};
1313

14+
export function resetGlobalConfig(): void {
15+
globalConfig.coordinator = modernLayout();
16+
globalConfig.theme = MODERN_THEME;
17+
}
18+
1419
export function getGlobalConfig(): Readonly<GlobalConfig> {
1520
return globalConfig;
1621
}

denops/fall/config/item_picker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export function listItemPickerNames(): readonly string[] {
2828
return Array.from(itemPickerParamsMap.keys());
2929
}
3030

31+
export function resetItemPickerParams(): void {
32+
itemPickerParamsMap.clear();
33+
}
34+
3135
export function getItemPickerParams(
3236
name: string,
3337
): Readonly<ItemPickerParams<unknown, string> & GlobalConfig> | undefined {

denops/fall/main/picker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "../config.ts";
2525
import { Picker } from "../picker.ts";
2626

27-
let initialized: Promise<void>;
27+
let initialized: Promise<void> | undefined;
2828
let zindex = 50;
2929

3030
export const main: Entrypoint = (denops) => {
@@ -68,15 +68,19 @@ export const main: Entrypoint = (denops) => {
6868
assert(options, isOptions);
6969
return await startPicker(denops, args, screen, params, options);
7070
},
71+
"picker:reload": async () => {
72+
initialized = undefined;
73+
await init(denops, `#${performance.now()}`);
74+
},
7175
};
7276
};
7377

74-
async function init(denops: Denops): Promise<void> {
78+
async function init(denops: Denops, suffix?: string): Promise<void> {
7579
if (initialized) {
7680
return initialized;
7781
}
7882
const path = await denops.eval("expand(g:fall_config_path)") as string;
79-
return (initialized = loadUserConfig(denops, path));
83+
return (initialized = loadUserConfig(denops, path, { suffix }));
8084
}
8185

8286
async function startPicker(

0 commit comments

Comments
 (0)