Skip to content

Commit cca040c

Browse files
authored
use new install API from lsp4ij (#68)
* Reapply "Use new lsp4ij install api" This reverts commit 0d31c21. * Reapply "Improve server installation fixing concurrency bugs + using lsp4ij install API" This reverts commit 5349fa7.
1 parent 9fff7e6 commit cca040c

File tree

3 files changed

+59
-58
lines changed

3 files changed

+59
-58
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- Fix comment form complain about missing paren.
6+
- Improve server installation fixing concurrency bugs + using lsp4ij install API.
67

78
## 3.0.2
89

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

+28-29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[com.github.clojure-lsp.intellij.editor :as editor]
1212
[com.github.clojure-lsp.intellij.server :as server]
1313
[com.github.clojure-lsp.intellij.settings :as settings]
14+
[com.github.ericdallo.clj4intellij.tasks :as tasks]
1415
[com.rpl.proxy-plus :refer [proxy+]])
1516
(:import
1617
[com.intellij.execution.configurations GeneralCommandLine]
@@ -20,23 +21,24 @@
2021
[com.redhat.devtools.lsp4ij LSPIJUtils ServerStatus]
2122
[com.redhat.devtools.lsp4ij.client LanguageClientImpl]
2223
[com.redhat.devtools.lsp4ij.client.features LSPClientFeatures LSPProgressFeature]
24+
[com.redhat.devtools.lsp4ij.installation LanguageServerInstallerBase]
2325
[com.redhat.devtools.lsp4ij.server OSProcessStreamConnectionProvider]
2426
[java.io File]
2527
[java.util List]
2628
[org.eclipse.lsp4j InitializeParams]))
2729

2830
(set! *warn-on-reflection* true)
2931

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

3335
(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"]]
36+
(let [path (loop []
37+
(Thread/sleep 100)
38+
(or (settings/server-path)
39+
(some-> ^File @server-path* .getCanonicalPath)
40+
(recur)))
41+
command [path "listen"]]
4042
(doto (proxy+
4143
[]
4244
OSProcessStreamConnectionProvider)
@@ -48,14 +50,6 @@
4850
(defn -getServerInterface [_]
4951
com.github.clojure_lsp.intellij.ClojureLanguageServer)
5052

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-
5953
(defn ^:private create-temp-file ^VirtualFile
6054
[^Project project ^String path ^String text]
6155
(let [temp-file (io/file (config/project-cache-path project) path)]
@@ -96,28 +90,33 @@
9690
(defn -createClientFeatures [_]
9791
(doto
9892
(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)))
93+
(keepServerAlive [_] true)
11094
(initializeParams [_ ^InitializeParams params]
11195
(.setWorkDoneToken params "clojure-lsp-startup")
11296
(.setInitializationOptions params {"dependency-scheme" "jar"
11397
"hover" {"arity-on-same-line?" true}}))
11498
(findFileByUri ^VirtualFile [_ ^String uri]
11599
(find-file-by-uri uri))
116-
(keepServerAlive [_] true)
117100
(handleServerStatusChanged [^LSPClientFeatures this ^ServerStatus server-status]
118101
(let [status (keyword (.toString server-status))]
119102
(db/assoc-in (.getProject this) [:status] status)
120103
(run! #(% status) (db/get-in (.getProject this) [:on-status-changed-fns])))))
121104
(.setProgressFeature (proxy+ [] LSPProgressFeature
122105
(updateMessage [_ ^String message ^ProgressIndicator indicator]
123-
(.setText indicator (str "LSP: " message)))))))
106+
(.setText indicator (str "LSP: " message)))))
107+
(.setServerInstaller (proxy+ [] LanguageServerInstallerBase
108+
(getInstallationTaskTitle [_] "LSP: installing clojure-lsp")
109+
(progressCheckingServerInstalled [_ indicator] (tasks/set-progress indicator "LSP: checking for clojure-lsp"))
110+
(progressInstallingServer [_ indicator] (tasks/set-progress indicator "LSP: downloading clojure-lsp"))
111+
(checkServerInstalled [_ _indicator]
112+
(let [{:keys [status path]} (server/server-install-status)]
113+
(if (identical? :installed status)
114+
(do
115+
(when-not @server-path* (reset! server-path* path))
116+
true)
117+
false)))
118+
(install [^LanguageServerInstallerBase this _indicator]
119+
(when-not @server-installing*
120+
(reset! server-installing* true)
121+
(reset! server-path* (server/install-server! (.getProject (.getClientFeatures this))))
122+
(reset! server-installing* false)))))))

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

+30-29
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
[com.github.clojure-lsp.intellij.notification :as notification]
88
[com.github.clojure-lsp.intellij.server :as server]
99
[com.github.clojure-lsp.intellij.settings :as settings]
10-
[com.github.ericdallo.clj4intellij.logger :as logger]
11-
[com.github.ericdallo.clj4intellij.tasks :as tasks])
10+
[com.github.ericdallo.clj4intellij.logger :as logger])
1211
(:import
1312
[com.intellij.openapi.project Project]
1413
[com.intellij.openapi.project Project]
@@ -53,8 +52,7 @@
5352
(clojure.java.io/copy stream dest-file))
5453
(recur (.getNextEntry stream))))))
5554

56-
(defn ^:private download-server! [project indicator ^File download-path ^File server-version-path latest-version]
57-
(tasks/set-progress indicator "LSP: downloading clojure-lsp")
55+
(defn ^:private download-server! [project ^File download-path ^File server-version-path latest-version]
5856
(let [platform (os-name)
5957
arch (os-arch)
6058
artifact-name (get-in artifacts [platform arch])
@@ -71,34 +69,37 @@
7169
(db/assoc-in project [:downloaded-server-path] dest-path)
7270
(logger/info "Downloaded clojure-lsp to" dest-path)))
7371

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})
72+
(defn server-install-status []
73+
(let [download-path (config/download-server-path)
74+
server-version-path (config/download-server-version-path)
75+
latest-version* (delay (try (string/trim (slurp latest-version-uri)) (catch Exception _ nil)))
76+
custom-server-path (settings/server-path)]
77+
(cond
78+
custom-server-path
79+
{:status :installed :path custom-server-path}
80+
81+
(and (.exists download-path)
82+
(or (not @latest-version*) ;; on network connection issues we use any downloaded server
83+
(= (try (slurp server-version-path) (catch Exception _ :error-checking-local-version))
84+
@latest-version*)))
85+
{:status :installed :path download-path}
8686

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})
87+
@latest-version*
88+
{:status :not-installed :path download-path :version @latest-version* :version-path server-version-path}
9289

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

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"}))))))
93+
(defn install-server! [project]
94+
(let [{:keys [status path version version-path]} (server-install-status)]
95+
(case status
96+
:installed path
97+
:not-installed (do (download-server! project path version-path version)
98+
path)
99+
(notification/show-notification! {:project project
100+
:type :error
101+
:title "Clojure LSP download error"
102+
:message "There is no server downloaded and there was a network issue to download the latest one"}))))
102103

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

0 commit comments

Comments
 (0)