|
3 | 3 | :name com.github.clojure_lsp.intellij.extension.LanguageServerFactory
|
4 | 4 | :implements [com.redhat.devtools.lsp4ij.LanguageServerFactory])
|
5 | 5 | (:require
|
| 6 | + [clojure.java.io :as io] |
6 | 7 | [clojure.string :as string]
|
7 |
| - [com.github.clojure-lsp.intellij.db :as db] |
| 8 | + [com.github.clojure-lsp.intellij.client :as lsp-client] |
| 9 | + [com.github.clojure-lsp.intellij.config :as config] |
| 10 | + [com.github.clojure-lsp.intellij.editor :as editor] |
8 | 11 | [com.github.clojure-lsp.intellij.server :as server]
|
9 | 12 | [com.rpl.proxy-plus :refer [proxy+]])
|
10 | 13 | (:import
|
11 | 14 | [com.intellij.execution.configurations GeneralCommandLine]
|
12 | 15 | [com.intellij.openapi.progress ProgressIndicator]
|
13 |
| - [com.intellij.openapi.project Project ProjectLocator] |
14 |
| - [com.intellij.openapi.vfs VirtualFile] |
| 16 | + [com.intellij.openapi.project Project] |
| 17 | + [com.intellij.openapi.vfs LocalFileSystem VirtualFile] |
15 | 18 | [com.redhat.devtools.lsp4ij LSPIJUtils]
|
16 | 19 | [com.redhat.devtools.lsp4ij.client LanguageClientImpl]
|
17 | 20 | [com.redhat.devtools.lsp4ij.client.features LSPClientFeatures LSPProgressFeature]
|
|
50 | 53 | (swap! server assoc :status status :path path)
|
51 | 54 | (server/start! project))))
|
52 | 55 |
|
| 56 | +(defn ^:private create-temp-file ^VirtualFile |
| 57 | + [^Project project ^String path ^String text] |
| 58 | + (let [temp-file (io/file (config/project-cache-path project) path)] |
| 59 | + (io/make-parents temp-file) |
| 60 | + (spit temp-file text) |
| 61 | + (proxy+ [] VirtualFile |
| 62 | + (getName [_] (.getName temp-file)) |
| 63 | + (getFileSystem [_] (LocalFileSystem/getInstance)) |
| 64 | + (getPath [_] (.getCanonicalPath temp-file)) |
| 65 | + (isWritable [_] false) |
| 66 | + (isDirectory [_] false) |
| 67 | + (isValid [_] true) |
| 68 | + (getParent [_] nil) |
| 69 | + (getChildren [_] []) |
| 70 | + (contentsToByteArray [_] (.getBytes text)) |
| 71 | + (getTimeStamp [_] 0) |
| 72 | + (getLength [_] (count (.getBytes text))) |
| 73 | + (refresh [_ _ _ _]) |
| 74 | + (getInputStream [_] (io/input-stream temp-file)) |
| 75 | + (getOutputStream [_ _ _ _] (io/output-stream temp-file)) |
| 76 | + (getModificationStamp [_] -1)))) |
| 77 | + |
| 78 | +(defn ^:private find-file-by-uri [^String uri] |
| 79 | + (if (and (string/starts-with? uri "file:") |
| 80 | + (string/includes? uri ".jar!")) |
| 81 | + (let [fixed-uri (string/replace-first uri "file:" "jar:file:") |
| 82 | + old-vfile (LSPIJUtils/findResourceFor fixed-uri) |
| 83 | + project (editor/guess-project-for old-vfile) |
| 84 | + dependency-contents (lsp-client/dependency-contents fixed-uri project) |
| 85 | + jar-pattern (re-pattern (str "^(jar|zip):(file:.+)!" (System/getProperty "file.separator") "(.+)")) |
| 86 | + path (last (re-find jar-pattern fixed-uri)) |
| 87 | + tmp-file (create-temp-file project path dependency-contents)] |
| 88 | + tmp-file) |
| 89 | + (LSPIJUtils/findResourceFor uri))) |
| 90 | + |
53 | 91 | (defn -createClientFeatures [_]
|
54 | 92 | (doto
|
55 | 93 | (proxy+ [] LSPClientFeatures
|
|
62 | 100 | true
|
63 | 101 |
|
64 | 102 | :not-found
|
65 |
| - (do (install-server (or (.guessProjectForFile (ProjectLocator/getInstance) file) |
66 |
| - (first (db/all-projects)))) |
| 103 | + (do (install-server (editor/guess-project-for file)) |
67 | 104 | false)))
|
68 | 105 | (initializeParams [_ ^InitializeParams params]
|
69 | 106 | (.setWorkDoneToken params "clojure-lsp-startup")
|
70 | 107 | (.setInitializationOptions params {"dependency-scheme" "jar"
|
71 | 108 | "hover" {"arity-on-same-line?" true}}))
|
72 |
| - (findFileByUri [_ ^String uri] |
73 |
| - (if (and (string/starts-with? uri "file:") |
74 |
| - (string/includes? uri ".jar!")) |
75 |
| - (LSPIJUtils/findResourceFor (string/replace-first uri "file:" "jar:file:")) |
76 |
| - (LSPIJUtils/findResourceFor uri)))) |
| 109 | + (findFileByUri ^VirtualFile [_ ^String uri] |
| 110 | + (find-file-by-uri uri))) |
77 | 111 | (.setProgressFeature (proxy+ [] LSPProgressFeature
|
78 | 112 | (updateMessage [_ ^String message ^ProgressIndicator indicator]
|
79 | 113 | (.setText indicator (str "LSP: " message)))))))
|
0 commit comments