Skip to content

Commit

Permalink
Adjust trace level of running server
Browse files Browse the repository at this point in the history
  • Loading branch information
mainej committed Oct 12, 2022
1 parent 342b9ed commit 716e250
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Editor
- Add refactorings to change param order of `defn`/`defmacro`, also changing call sites. #1131
- Avoid shadowing existing locals when restructuring keys. #1229
- Let editors control whether the server's log includes traces of the messages they are exchanging. https://github.com/clojure-lsp/lsp4clj/issues/27

## 2022.10.05-16.39.51

Expand Down
2 changes: 1 addition & 1 deletion bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:git/sha "ce060c12a25b552b864dc90f8fb344a2eb91ea9d"}

medley/medley {:mvn/version "1.4.0"}
com.github.clojure-lsp/lsp4clj {:mvn/version "1.3.1"}
com.github.clojure-lsp/lsp4clj {:mvn/version "1.4.0"}
;; com.github.clojure-lsp/lsp4clj {:local/root "../../lsp4clj"}
org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
:git/sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}}
Expand Down
2 changes: 1 addition & 1 deletion cli/bb.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:paths ["integration-test"]
:min-bb-version "0.4.0"
:deps {medley/medley {:mvn/version "1.4.0"}
com.github.clojure-lsp/lsp4clj {:mvn/version "1.3.1"}
com.github.clojure-lsp/lsp4clj {:mvn/version "1.4.0"}
;; com.github.clojure-lsp/lsp4clj {:local/root "../../lsp4clj"}
org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
:git/sha "8df0712896f596680da7a32ae44bb000b7e45e68"}}
Expand Down
7 changes: 6 additions & 1 deletion cli/src/clojure_lsp/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@
"See https://clojure-lsp.io/settings/ for detailed documentation."]
(string/join \newline)))

(def ^:private trace-levels
#{"off" "messages" "verbose"})

(defn ^:private cli-options []
[["-h" "--help" "Print the available commands and its options"]
[nil "--version" "Print clojure-lsp version"]
[nil "--verbose" "Use stdout for clojure-lsp logs instead of default log settings"]
[nil "--trace" "Enable trace logs between client and server, for debugging."]
[nil "--trace LEVEL" "Enable trace logs between client and server, for debugging. Set to 'messages' for basic traces, or 'verbose' for more detailed traces."
:default "off"
:validate [trace-levels (str "Must be in " trace-levels)]]
["-s" "--settings SETTINGS" "Optional settings as edn to use for the specified command. For all available settings, check https://clojure-lsp.io/settings"
:id :settings
:validate [#(try (edn/read-string %) true (catch Exception _ false))
Expand Down
12 changes: 9 additions & 3 deletions cli/src/clojure_lsp/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@
(:capabilities params)
(client-settings params)
(some-> params :work-done-token str))
(when-let [trace-level (:trace params)]
(lsp.server/set-trace-level server trace-level))
(when-let [parent-process-id (:process-id params)]
(lsp.liveness-probe/start! parent-process-id log-wrapper-fn #(exit server)))
{:capabilities (capabilities (settings/all @db*))})
Expand Down Expand Up @@ -492,6 +494,9 @@
(logger/error e# (format "Error during async task %s" ~task-name))))
(recur))))

(defmethod lsp.server/receive-notification "$/setTrace" [_ {:keys [server]} {:keys [value]}]
(lsp.server/set-trace-level server value))

(defn ^:private spawn-async-tasks!
[{:keys [producer current-changes-chan diagnostics-chan
watched-files-chan edits-chan] :as components}]
Expand Down Expand Up @@ -539,15 +544,16 @@
;; db/db*, so it can be inspected in the nREPL.
(alter-var-root #'db/db* (constantly db*))))

(defn run-server! [trace?]
(defn run-server! [trace-level]
(lsp.server/discarding-stdout
(let [timbre-logger (->TimbreLogger)
log-path (logger/setup timbre-logger)
db (assoc db/initial-db :log-path log-path)
db* (atom db)
log-ch (async/chan (async/sliding-buffer 20))
server (lsp.io-server/stdio-server (cond-> {:log-ch log-ch}
trace? (assoc :trace-ch log-ch)))
server (lsp.io-server/stdio-server {:log-ch log-ch
:trace-ch log-ch
:trace-level trace-level})
producer (ClojureLspProducer. server db*)
components {:db* db*
:logger timbre-logger
Expand Down
2 changes: 1 addition & 1 deletion lib/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
org.benf/cfr {:mvn/version "0.152"}

babashka/fs {:mvn/version "0.1.11"}
com.github.clojure-lsp/lsp4clj {:mvn/version "1.3.1"}
com.github.clojure-lsp/lsp4clj {:mvn/version "1.4.0"}
;; com.github.clojure-lsp/lsp4clj {:local/root "../../lsp4clj"}
}
:paths ["src" "resources"]
Expand Down

0 comments on commit 716e250

Please sign in to comment.