|
4 | 4 | 1. base: fixed config var `eca.config/initial-config`. |
5 | 5 | 2. env var: searching for a `ECA_CONFIG` env var which should contains a valid json config. |
6 | 6 | 3. local config-file: searching from a local `.eca/config.json` file. |
7 | | - 4. `initializatonOptions` sent in `initialize` request." |
| 7 | + 4. `initializatonOptions` sent in `initialize` request. |
| 8 | +
|
| 9 | + When a `ECA_CONFIGFILE` env var set, it takes precedence and we only deep merge: |
| 10 | + 1. base: fixed config var `eca.config/initial-config`. |
| 11 | + 2. env file: searching for a `ECA_CONFIGFILE` env var which points to a json config file." |
8 | 12 | (:require |
9 | 13 | [camel-snake-kebab.core :as csk] |
10 | 14 | [cheshire.core :as json] |
|
23 | 27 | (def ^:private logger-tag "[CONFIG]") |
24 | 28 |
|
25 | 29 | (def ^:dynamic *env-var-config-error* false) |
| 30 | +(def ^:dynamic *env-file-config-error* false) |
26 | 31 | (def ^:dynamic *global-config-error* false) |
27 | 32 | (def ^:dynamic *local-config-error* false) |
28 | 33 |
|
|
143 | 148 | (logger/warn logger-tag "Error parsing config json:" (.getMessage e))))) |
144 | 149 |
|
145 | 150 | (defn ^:private config-from-envvar* [] |
146 | | - (some-> (System/getenv "ECA_CONFIG") |
| 151 | + (some-> (get-env "ECA_CONFIG") |
147 | 152 | (safe-read-json-string (var *env-var-config-error*)))) |
148 | 153 |
|
149 | 154 | (def ^:private config-from-envvar (memoize config-from-envvar*)) |
150 | 155 |
|
| 156 | +(defn ^:private config-from-envfile* [] |
| 157 | + (when-some [path (get-env "ECA_CONFIGFILE")] |
| 158 | + (let [config-file (io/file path)] |
| 159 | + (when (.exists config-file) |
| 160 | + (safe-read-json-string (slurp config-file) (var *env-file-config-error*)))))) |
| 161 | + |
| 162 | +(def ^:private config-from-envfile (memoize config-from-envfile*)) |
| 163 | + |
151 | 164 | (defn global-config-dir ^File [] |
152 | 165 | (let [xdg-config-home (or (get-env "XDG_CONFIG_HOME") |
153 | 166 | (io/file (get-property "user.home") ".config"))] |
|
265 | 278 | (defn all [db] |
266 | 279 | (let [initialization-config @initialization-config* |
267 | 280 | pure-config? (:pureConfig initialization-config)] |
268 | | - (deep-merge initial-config |
269 | | - (normalize-fields |
270 | | - eca-config-normalization-rules |
271 | | - (deep-merge initialization-config |
272 | | - (when-not pure-config? (config-from-envvar)) |
273 | | - (when-not pure-config? (config-from-global-file)) |
274 | | - (when-not pure-config? (config-from-local-file (:workspace-folders db)))))))) |
| 281 | + (if-some [envfile-config (config-from-envfile)] |
| 282 | + (deep-merge initial-config |
| 283 | + (normalize-fields |
| 284 | + eca-config-normalization-rules |
| 285 | + (deep-merge initialization-config |
| 286 | + (when-not pure-config? envfile-config)))) |
| 287 | + (deep-merge initial-config |
| 288 | + (normalize-fields |
| 289 | + eca-config-normalization-rules |
| 290 | + (deep-merge initialization-config |
| 291 | + (when-not pure-config? (config-from-envvar)) |
| 292 | + (when-not pure-config? (config-from-global-file)) |
| 293 | + (when-not pure-config? (config-from-local-file (:workspace-folders db))))))))) |
275 | 294 |
|
276 | 295 | (defn validation-error [] |
277 | 296 | (cond |
278 | 297 | *env-var-config-error* "ENV" |
| 298 | + *env-file-config-error* "ENVFILE" |
279 | 299 | *global-config-error* "global" |
280 | 300 | *local-config-error* "local" |
281 | 301 |
|
|
0 commit comments