|
1 | 1 | (ns leiningen.clojure-lsp
|
2 | 2 | (:refer-clojure :exclude [run!])
|
3 | 3 | (:require
|
| 4 | + [clojure.edn :as edn] |
4 | 5 | [clojure-lsp.main :as lsp]
|
5 | 6 | [leiningen.core.main :as lein-core]))
|
6 | 7 |
|
7 |
| -(defn run! [command-and-options options] |
8 |
| - (let [result (apply lsp/run! (concat command-and-options ["--settings" (str options)]))] |
| 8 | +(defn ^:private has-settings? |
| 9 | + [command-and-options] |
| 10 | + (let [settings-index (.indexOf command-and-options "--settings")] |
| 11 | + (and (>= settings-index 0) |
| 12 | + (not-empty (nth command-and-options (inc settings-index)))))) |
| 13 | + |
| 14 | +(defn ^:private args-with-merged-settings |
| 15 | + [command-and-options project-settings] |
| 16 | + (let [settings-index (inc (.indexOf command-and-options "--settings")) |
| 17 | + settings (edn/read-string (nth command-and-options settings-index))] |
| 18 | + (assoc (vec command-and-options) settings-index (str (merge project-settings settings))))) |
| 19 | + |
| 20 | +(defn args |
| 21 | + [command-and-options project-settings] |
| 22 | + (cond |
| 23 | + (and (not-empty project-settings) (has-settings? command-and-options)) |
| 24 | + (args-with-merged-settings command-and-options project-settings) |
| 25 | + |
| 26 | + (not-empty project-settings) |
| 27 | + (concat command-and-options ["--settings" (str project-settings)]) |
| 28 | + |
| 29 | + :else |
| 30 | + command-and-options)) |
| 31 | + |
| 32 | +(defn ^:private run! |
| 33 | + [command-and-options project-settings] |
| 34 | + (let [result (apply lsp/run! (args command-and-options project-settings))] |
9 | 35 | (when-let [message-fn (:message-fn result)]
|
10 | 36 | (println (message-fn)))
|
11 | 37 | (when (not= 0 (:result-code result))
|
|
15 | 41 | (defn ^:no-project-needed clojure-lsp
|
16 | 42 | "Access clojure-lsp API features"
|
17 | 43 | [project & command-and-options]
|
18 |
| - (let [project-options (or (:clojure-lsp project) {})] |
| 44 | + (let [project-settings (or (:clojure-lsp project) {})] |
19 | 45 | (if lein-core/*info*
|
20 |
| - (run! command-and-options project-options) |
| 46 | + (run! command-and-options project-settings) |
21 | 47 | (with-out-str
|
22 |
| - (run! command-and-options project-options))))) |
| 48 | + (run! command-and-options project-settings))))) |
0 commit comments