Skip to content

Commit f9962b6

Browse files
committed
feat: Add new question to skip or retry classpath scan during startup if failed
1 parent 3543f40 commit f9962b6

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Add refactoring `Restructure keys`, the inverse of `Destructure keys`. #1170
2929
- Add refactorings to convert between `(:x m)` and `(get m :x)` or `(:y (:x m))` and `(get-in m [:x :y])`. #1172
3030
- Add support to imported java class on completion. #1193
31+
- Add new question to skip or retry classpath scan during startup if failed.
3132

3233
## 2022.07.24-18.25.43
3334

cli/src/clojure_lsp/server.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@
126126
:actions actions}
127127
(conform-or-log ::coercer/show-message-request)
128128
(lsp.server/send-request server "window/showMessageRequest"))
129-
response (lsp.server/deref-or-cancel request 10e3 ::timeout)]
129+
;; High timeout as we probably want to wait some time for user input
130+
response (lsp.server/deref-or-cancel request 10e5 ::timeout)]
130131
(when-not (= response ::timeout)
131132
(:title response)))))
132133

lib/src/clojure_lsp/classpath.clj

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,34 @@
7272
{:command command
7373
:error (.getMessage e)}))))
7474

75+
(defn ^:private lookup-classpath-handling-error! [project-spec root-path producer]
76+
(let [{:keys [command error paths]} (lookup-classpath! root-path project-spec)
77+
retry-action "Retry"
78+
ignore-action "Ignore"]
79+
(if error
80+
(do
81+
(logger/error (format "Error while looking up classpath info in %s. Error: %s" (str root-path) error))
82+
(if-let [chosen-action (producer/show-message-request
83+
producer
84+
(format (str "LSP classpath lookup failed when running `%s`. Some features may not work properly if ignored.\n\n"
85+
"Error: %s\n\nChoose an option:") command error)
86+
:warning
87+
[{:title retry-action}
88+
{:title ignore-action}])]
89+
(if (= retry-action chosen-action)
90+
(recur project-spec root-path producer)
91+
(do
92+
(logger/warn (format "Classpath lookup retry skipped by user"))
93+
paths))
94+
(logger/warn (format "Invalid classpath lookup option, skipping lookup"))))
95+
paths)))
96+
7597
(defn scan-classpath! [{:keys [db* producer]}]
7698
(let [db @db*
7799
root-path (shared/uri->path (:project-root-uri db))]
78100
(->> (settings/get db [:project-specs])
79101
(filter (partial valid-project-spec? root-path))
80-
(map #(lookup-classpath! root-path %))
81-
(map (fn [{:keys [command error paths]}]
82-
(when error
83-
(logger/error (format "Error while looking up classpath info in %s. Error: %s" (str root-path) error))
84-
(producer/show-message producer (format "Classpath lookup failed when running `%s`. Some features may not work properly. Error: %s" command error) :error error))
85-
paths))
102+
(mapv #(lookup-classpath-handling-error! % root-path producer))
86103
(reduce set/union))))
87104

88105
(defn ^:private classpath-cmd->windows-safe-classpath-cmd

lib/src/clojure_lsp/crawler.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@
223223
(analyze-external-classpath! root-path (-> @db* :settings :source-paths) classpath progress-token components))
224224
(logger/info "Caching db for next startup...")
225225
(upsert-db-cache! @db*))))
226-
227226
(publish-task-progress producer (:resolving-config task-list) progress-token)
228227
(when-let [classpath-settings (and (config/classpath-config-paths? settings)
229228
(:classpath @db*)

0 commit comments

Comments
 (0)