Skip to content

Commit 824e9fe

Browse files
committed
Use new lsp4ij install api
1 parent db38460 commit 824e9fe

File tree

2 files changed

+53
-54
lines changed

2 files changed

+53
-54
lines changed

src/main/clojure/com/github/clojure_lsp/intellij/extension/language_server_factory.clj

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020
[com.redhat.devtools.lsp4ij LSPIJUtils ServerStatus]
2121
[com.redhat.devtools.lsp4ij.client LanguageClientImpl]
2222
[com.redhat.devtools.lsp4ij.client.features LSPClientFeatures LSPProgressFeature]
23+
[com.redhat.devtools.lsp4ij.installation LanguageServerInstallerBase]
2324
[com.redhat.devtools.lsp4ij.server OSProcessStreamConnectionProvider]
2425
[java.io File]
2526
[java.util List]
2627
[org.eclipse.lsp4j InitializeParams]))
2728

2829
(set! *warn-on-reflection* true)
2930

30-
(defonce ^:private server (atom {:status :not-found
31-
:path nil}))
31+
(defonce ^:private server-path* (atom nil))
32+
(defonce ^:private server-installing* (atom false))
3233

3334
(defn -createConnectionProvider [_ ^Project _project]
34-
(let [server-path (loop []
35-
(Thread/sleep 100)
36-
(or (settings/server-path)
37-
(some-> ^File (:path @server) .getCanonicalPath)
38-
(recur)))
39-
command [server-path "listen"]]
35+
(let [path (loop []
36+
(Thread/sleep 100)
37+
(or (settings/server-path)
38+
(some-> ^File @server-path* .getCanonicalPath)
39+
(recur)))
40+
command [path "listen"]]
4041
(doto (proxy+
4142
[]
4243
OSProcessStreamConnectionProvider)
@@ -48,14 +49,6 @@
4849
(defn -getServerInterface [_]
4950
com.github.clojure_lsp.intellij.ClojureLanguageServer)
5051

51-
(defn ^:private install-server [project]
52-
(swap! server assoc :status :installing)
53-
(server/install-server
54-
project
55-
(fn [{:keys [status path]}]
56-
(swap! server assoc :status status :path path)
57-
(server/start! project))))
58-
5952
(defn ^:private create-temp-file ^VirtualFile
6053
[^Project project ^String path ^String text]
6154
(let [temp-file (io/file (config/project-cache-path project) path)]
@@ -96,28 +89,30 @@
9689
(defn -createClientFeatures [_]
9790
(doto
9891
(proxy+ [] LSPClientFeatures
99-
(isEnabled [_this ^VirtualFile file]
100-
(case (:status @server)
101-
:installing
102-
false
103-
104-
:installed
105-
true
106-
107-
:not-found
108-
(do (install-server (editor/guess-project-for file))
109-
false)))
92+
(keepServerAlive [_] true)
11093
(initializeParams [_ ^InitializeParams params]
11194
(.setWorkDoneToken params "clojure-lsp-startup")
11295
(.setInitializationOptions params {"dependency-scheme" "jar"
11396
"hover" {"arity-on-same-line?" true}}))
11497
(findFileByUri ^VirtualFile [_ ^String uri]
11598
(find-file-by-uri uri))
116-
(keepServerAlive [_] true)
11799
(handleServerStatusChanged [^LSPClientFeatures this ^ServerStatus server-status]
118100
(let [status (keyword (.toString server-status))]
119101
(db/assoc-in (.getProject this) [:status] status)
120102
(run! #(% status) (db/get-in (.getProject this) [:on-status-changed-fns])))))
121103
(.setProgressFeature (proxy+ [] LSPProgressFeature
122104
(updateMessage [_ ^String message ^ProgressIndicator indicator]
123-
(.setText indicator (str "LSP: " message)))))))
105+
(.setText indicator (str "LSP: " message)))))
106+
(.setServerInstaller (proxy+ [] LanguageServerInstallerBase
107+
(checkServerInstalled [_ _indicator]
108+
(let [{:keys [status path]} (server/server-install-status)]
109+
(if (identical? :installed status)
110+
(do
111+
(when-not @server-path* (reset! server-path* path))
112+
true)
113+
false)))
114+
(install [^LSPClientFeatures this indicator]
115+
(when-not @server-installing*
116+
(reset! server-installing* true)
117+
(reset! server-path* (server/install-server! (.getProject this) indicator))
118+
(reset! server-installing* false)))))))

src/main/clojure/com/github/clojure_lsp/intellij/server.clj

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,38 @@
7171
(db/assoc-in project [:downloaded-server-path] dest-path)
7272
(logger/info "Downloaded clojure-lsp to" dest-path)))
7373

74-
(defn install-server [project installed-fn]
75-
(tasks/run-background-task!
76-
project
77-
"LSP: install clojure-lsp"
78-
(fn [indicator]
79-
(let [download-path (config/download-server-path)
80-
server-version-path (config/download-server-version-path)
81-
latest-version* (delay (try (string/trim (slurp latest-version-uri)) (catch Exception _ nil)))
82-
custom-server-path (settings/server-path)]
83-
(cond
84-
custom-server-path
85-
(installed-fn {:status :installed :path custom-server-path})
74+
(defn server-install-status []
75+
(let [download-path (config/download-server-path)
76+
server-version-path (config/download-server-version-path)
77+
latest-version* (delay (try (string/trim (slurp latest-version-uri)) (catch Exception _ nil)))
78+
custom-server-path (settings/server-path)]
79+
(cond
80+
custom-server-path
81+
{:status :installed :path custom-server-path}
82+
83+
(and (.exists download-path)
84+
(or (not @latest-version*) ;; on network connection issues we use any downloaded server
85+
(= (try (slurp server-version-path) (catch Exception _ :error-checking-local-version))
86+
@latest-version*)))
87+
{:status :installed :path download-path}
8688

87-
(and (.exists download-path)
88-
(or (not @latest-version*) ;; on network connection issues we use any downloaded server
89-
(= (try (slurp server-version-path) (catch Exception _ :error-checking-local-version))
90-
@latest-version*)))
91-
(installed-fn {:status :installed :path download-path})
89+
@latest-version*
90+
{:status :not-installed :path download-path :version @latest-version* :version-path server-version-path}
9291

93-
@latest-version*
94-
(do (download-server! project indicator download-path server-version-path @latest-version*)
95-
(installed-fn {:status :installed :path download-path}))
92+
:else
93+
{:status :error})))
9694

97-
:else
98-
(notification/show-notification! {:project project
99-
:type :error
100-
:title "Clojure LSP download error"
101-
:message "There is no server downloaded and there was a network issue to download the latest one"}))))))
95+
(defn install-server! [project indicator]
96+
(Thread/sleep 3000)
97+
(let [{:keys [status path version version-path]} (server-install-status)]
98+
(case status
99+
:installed path
100+
:not-installed (do (download-server! project indicator path version-path version)
101+
path)
102+
(notification/show-notification! {:project project
103+
:type :error
104+
:title "Clojure LSP download error"
105+
:message "There is no server downloaded and there was a network issue to download the latest one"}))))
102106

103107
(defn start! [^Project project]
104108
(.start (LanguageServerManager/getInstance project) "clojure-lsp"))

0 commit comments

Comments
 (0)