|
26 | 26 | :chat {:welcomeMessage "Welcome to ECA! What you have in mind?\n\n"} |
27 | 27 | :index {:ignoreFiles [{:type :gitignore}]}}) |
28 | 28 |
|
29 | | -(def ttl-cache-config-ms 5000) |
| 29 | +(defn get-env [env] (System/getenv env)) |
| 30 | +(defn get-property [property] (System/getenv property)) |
| 31 | + |
| 32 | +(def ^:private ttl-cache-config-ms 5000) |
30 | 33 |
|
31 | 34 | (defn ^:private safe-read-json-string [raw-string] |
32 | 35 | (try |
|
40 | 43 |
|
41 | 44 | (def ^:private config-from-envvar (memoize config-from-envvar*)) |
42 | 45 |
|
43 | | -(defn ^:private config-from-file* [roots] |
| 46 | +(defn ^:private config-from-global-file* [] |
| 47 | + (let [xdg-config-home (or (get-env "XDG_CONFIG_HOME") |
| 48 | + (io/file (get-property "user.home") ".config")) |
| 49 | + config-file (io/file xdg-config-home "eca" "config.json")] |
| 50 | + (when (.exists config-file) |
| 51 | + (safe-read-json-string (slurp config-file))))) |
| 52 | + |
| 53 | +(def ^:private config-from-global-file (memoize/ttl config-from-global-file* :ttl/threshold ttl-cache-config-ms)) |
| 54 | + |
| 55 | +(defn ^:private config-from-local-file* [roots] |
44 | 56 | (reduce |
45 | 57 | (fn [final-config {:keys [uri]}] |
46 | 58 | (merge |
|
51 | 63 | {} |
52 | 64 | roots)) |
53 | 65 |
|
54 | | -(def ^:private config-from-local-file (memoize/ttl config-from-file* :ttl/threshold ttl-cache-config-ms)) |
| 66 | +(def ^:private config-from-local-file (memoize/ttl config-from-local-file* :ttl/threshold ttl-cache-config-ms)) |
55 | 67 |
|
56 | 68 | (defn ^:private deep-merge [& maps] |
57 | 69 | (apply merge-with (fn [& args] |
|
70 | 82 | (defn all [db] |
71 | 83 | (deep-merge initial-config |
72 | 84 | (config-from-envvar) |
| 85 | + (config-from-global-file) |
73 | 86 | (config-from-local-file (:workspace-folders db)))) |
0 commit comments