-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconf.ts
91 lines (82 loc) · 2.64 KB
/
conf.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { resolve } from "jsr:@std/path@^1.0.1/resolve";
let conf: Config | undefined;
/**
* Configuration settings for denops testing.
*/
export interface Config {
/**
* Local path to the denops.vim repository.
* It refers to the environment variable 'DENOPS_TEST_DENOPS_PATH'.
*/
denopsPath: string;
/**
* Path to the Vim executable (default: "vim").
* It refers to the environment variable 'DENOPS_TEST_VIM_EXECUTABLE'.
*/
vimExecutable: string;
/**
* Path to the Neovim executable (default: "nvim").
* It refers to the environment variable 'DENOPS_TEST_NVIM_EXECUTABLE'.
*/
nvimExecutable: string;
/**
* Print Vim messages (echomsg).
* It refers to the environment variable 'DENOPS_TEST_VERBOSE'.
*/
verbose: boolean;
/**
* Timeout for connecting to Vim/Neovim.
* It refers to the environment variable 'DENOPS_TEST_CONNECT_TIMEOUT'.
*/
connectTimeout?: number;
}
/**
* Retrieves the configuration settings for denops testing.
* If the configuration has already been retrieved, it returns the cached
* configuration. Otherwise, it reads the environment variables and constructs
* the configuration object.
*
* It reads environment variables below:
*
* - `DENOPS_TEST_DENOPS_PATH`: Local path to the denops.vim repository (required)
* - `DENOPS_TEST_VIM_EXECUTABLE`: Path to the Vim executable (default: "vim")
* - `DENOPS_TEST_NVIM_EXECUTABLE`: Path to the Neovim executable (default: "nvim")
* - `DENOPS_TEST_VERBOSE`: `1` or `true` to print Vim messages (echomsg)
* - `DENOPS_TEST_CONNECT_TIMEOUT`: Timeout [ms] for connecting to Vim/Neovim (default: 30000)
*
* It throws an error if the environment variable 'DENOPS_TEST_DENOPS_PATH' is
* not set.
*/
export function getConfig(): Config {
if (conf) {
return conf;
}
const denopsPath = Deno.env.get("DENOPS_TEST_DENOPS_PATH");
if (!denopsPath) {
throw new Error(
"Environment variable 'DENOPS_TEST_DENOPS_PATH' is required",
);
}
const verbose = Deno.env.get("DENOPS_TEST_VERBOSE");
const connectTimeout = Number.parseInt(
Deno.env.get("DENOPS_TEST_CONNECT_TIMEOUT") ?? "",
);
conf = {
denopsPath: resolve(denopsPath),
vimExecutable: Deno.env.get("DENOPS_TEST_VIM_EXECUTABLE") ?? "vim",
nvimExecutable: Deno.env.get("DENOPS_TEST_NVIM_EXECUTABLE") ?? "nvim",
verbose: verbose === "1" || verbose === "true",
connectTimeout: Number.isNaN(connectTimeout) || connectTimeout <= 0
? undefined
: connectTimeout,
};
return conf;
}
/** @internal for test */
function resetConfig(newConf?: Config): void {
conf = newConf;
}
/** @internal */
export const _internal = {
resetConfig,
};