|
11 | 11 | [com.github.clojure-lsp.intellij.editor :as editor] |
12 | 12 | [com.github.clojure-lsp.intellij.server :as server] |
13 | 13 | [com.github.clojure-lsp.intellij.settings :as settings] |
| 14 | + [com.github.ericdallo.clj4intellij.tasks :as tasks] |
14 | 15 | [com.rpl.proxy-plus :refer [proxy+]]) |
15 | 16 | (:import |
16 | 17 | [com.intellij.execution.configurations GeneralCommandLine] |
|
20 | 21 | [com.redhat.devtools.lsp4ij LSPIJUtils ServerStatus] |
21 | 22 | [com.redhat.devtools.lsp4ij.client LanguageClientImpl] |
22 | 23 | [com.redhat.devtools.lsp4ij.client.features LSPClientFeatures LSPProgressFeature] |
| 24 | + [com.redhat.devtools.lsp4ij.installation LanguageServerInstallerBase] |
23 | 25 | [com.redhat.devtools.lsp4ij.server OSProcessStreamConnectionProvider] |
24 | 26 | [java.io File] |
25 | 27 | [java.util List] |
26 | 28 | [org.eclipse.lsp4j InitializeParams])) |
27 | 29 |
|
28 | 30 | (set! *warn-on-reflection* true) |
29 | 31 |
|
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)) |
32 | 34 |
|
33 | 35 | (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"]] |
40 | 42 | (doto (proxy+ |
41 | 43 | [] |
42 | 44 | OSProcessStreamConnectionProvider) |
|
48 | 50 | (defn -getServerInterface [_] |
49 | 51 | com.github.clojure_lsp.intellij.ClojureLanguageServer) |
50 | 52 |
|
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 | | - |
59 | 53 | (defn ^:private create-temp-file ^VirtualFile |
60 | 54 | [^Project project ^String path ^String text] |
61 | 55 | (let [temp-file (io/file (config/project-cache-path project) path)] |
|
96 | 90 | (defn -createClientFeatures [_] |
97 | 91 | (doto |
98 | 92 | (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) |
110 | 94 | (initializeParams [_ ^InitializeParams params] |
111 | 95 | (.setWorkDoneToken params "clojure-lsp-startup") |
112 | 96 | (.setInitializationOptions params {"dependency-scheme" "jar" |
113 | 97 | "hover" {"arity-on-same-line?" true}})) |
114 | 98 | (findFileByUri ^VirtualFile [_ ^String uri] |
115 | 99 | (find-file-by-uri uri)) |
116 | | - (keepServerAlive [_] true) |
117 | 100 | (handleServerStatusChanged [^LSPClientFeatures this ^ServerStatus server-status] |
118 | 101 | (let [status (keyword (.toString server-status))] |
119 | 102 | (db/assoc-in (.getProject this) [:status] status) |
120 | 103 | (run! #(% status) (db/get-in (.getProject this) [:on-status-changed-fns]))))) |
121 | 104 | (.setProgressFeature (proxy+ [] LSPProgressFeature |
122 | 105 | (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))))))) |
0 commit comments