Skip to content

Commit 0d31c21

Browse files
committed
Revert "Use new lsp4ij install api"
This reverts commit 4eb6296.
1 parent d6e48f2 commit 0d31c21

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
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]
1514
[com.rpl.proxy-plus :refer [proxy+]])
1615
(:import
1716
[com.intellij.execution.configurations GeneralCommandLine]
@@ -21,24 +20,23 @@
2120
[com.redhat.devtools.lsp4ij LSPIJUtils ServerStatus]
2221
[com.redhat.devtools.lsp4ij.client LanguageClientImpl]
2322
[com.redhat.devtools.lsp4ij.client.features LSPClientFeatures LSPProgressFeature]
24-
[com.redhat.devtools.lsp4ij.installation LanguageServerInstallerBase]
2523
[com.redhat.devtools.lsp4ij.server OSProcessStreamConnectionProvider]
2624
[java.io File]
2725
[java.util List]
2826
[org.eclipse.lsp4j InitializeParams]))
2927

3028
(set! *warn-on-reflection* true)
3129

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

3533
(defn -createConnectionProvider [_ ^Project _project]
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"]]
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"]]
4240
(doto (proxy+
4341
[]
4442
OSProcessStreamConnectionProvider)
@@ -50,6 +48,14 @@
5048
(defn -getServerInterface [_]
5149
com.github.clojure_lsp.intellij.ClojureLanguageServer)
5250

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+
5359
(defn ^:private create-temp-file ^VirtualFile
5460
[^Project project ^String path ^String text]
5561
(let [temp-file (io/file (config/project-cache-path project) path)]
@@ -90,33 +96,28 @@
9096
(defn -createClientFeatures [_]
9197
(doto
9298
(proxy+ [] LSPClientFeatures
93-
(keepServerAlive [_] true)
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)))
94110
(initializeParams [_ ^InitializeParams params]
95111
(.setWorkDoneToken params "clojure-lsp-startup")
96112
(.setInitializationOptions params {"dependency-scheme" "jar"
97113
"hover" {"arity-on-same-line?" true}}))
98114
(findFileByUri ^VirtualFile [_ ^String uri]
99115
(find-file-by-uri uri))
116+
(keepServerAlive [_] true)
100117
(handleServerStatusChanged [^LSPClientFeatures this ^ServerStatus server-status]
101118
(let [status (keyword (.toString server-status))]
102119
(db/assoc-in (.getProject this) [:status] status)
103120
(run! #(% status) (db/get-in (.getProject this) [:on-status-changed-fns])))))
104121
(.setProgressFeature (proxy+ [] LSPProgressFeature
105122
(updateMessage [_ ^String message ^ProgressIndicator indicator]
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)))))))
123+
(.setText indicator (str "LSP: " message)))))))

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

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
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])
10+
[com.github.ericdallo.clj4intellij.logger :as logger]
11+
[com.github.ericdallo.clj4intellij.tasks :as tasks])
1112
(:import
1213
[com.intellij.openapi.project Project]
1314
[com.intellij.openapi.project Project]
@@ -52,7 +53,8 @@
5253
(clojure.java.io/copy stream dest-file))
5354
(recur (.getNextEntry stream))))))
5455

55-
(defn ^:private download-server! [project ^File download-path ^File server-version-path latest-version]
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")
5658
(let [platform (os-name)
5759
arch (os-arch)
5860
artifact-name (get-in artifacts [platform arch])
@@ -69,37 +71,34 @@
6971
(db/assoc-in project [:downloaded-server-path] dest-path)
7072
(logger/info "Downloaded clojure-lsp to" dest-path)))
7173

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}
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})
8686

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

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

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"}))))
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"}))))))
103102

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

0 commit comments

Comments
 (0)