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