|
11 | 11 | [com.github.ericdallo.clj4intellij.action :as action]
|
12 | 12 | [com.github.ericdallo.clj4intellij.logger :as logger]
|
13 | 13 | [com.github.ericdallo.clj4intellij.tasks :as tasks]
|
14 |
| - [com.github.ericdallo.clj4intellij.util :as util]) |
| 14 | + [com.github.ericdallo.clj4intellij.util :as util] |
| 15 | + [com.rpl.proxy-plus :refer [proxy+]]) |
15 | 16 | (:import
|
16 | 17 | [com.github.clojure_lsp.intellij Icons]
|
17 |
| - [com.intellij.openapi.actionSystem AnActionEvent CommonDataKeys] |
| 18 | + [com.google.gson JsonPrimitive] |
| 19 | + [com.intellij.openapi.actionSystem |
| 20 | + ActionManager |
| 21 | + ActionUpdateThread |
| 22 | + AnActionEvent |
| 23 | + CommonDataKeys] |
18 | 24 | [com.intellij.openapi.editor Editor]
|
19 |
| - [com.intellij.openapi.project Project])) |
| 25 | + [com.intellij.openapi.project Project] |
| 26 | + [com.redhat.devtools.lsp4ij LanguageServerManager] |
| 27 | + [com.redhat.devtools.lsp4ij.commands LSPCommand LSPCommandAction] |
| 28 | + [com.redhat.devtools.lsp4ij.usages LSPUsageType LSPUsagesManager LocationData])) |
20 | 29 |
|
21 | 30 | (set! *warn-on-reflection* true)
|
22 | 31 |
|
|
76 | 85 | (fn [_]
|
77 | 86 | (lsp-client/execute-command command-name text [(editor/editor->uri editor) line character] project))))))
|
78 | 87 |
|
| 88 | +(defn register-command! |
| 89 | + [& {:keys [id on-performed]}] |
| 90 | + (let [manager (ActionManager/getInstance) |
| 91 | + action (proxy+ [] LSPCommandAction |
| 92 | + (commandPerformed [_ command event] (on-performed command event)) |
| 93 | + (getCommandPerformedThread [_] ActionUpdateThread/EDT))] |
| 94 | + (when-not (.getAction manager id) |
| 95 | + (.registerAction manager id action) |
| 96 | + action))) |
| 97 | + |
| 98 | +(defn ^:private code-lens-references-performed [^Project project ^LSPCommand command ^AnActionEvent event] |
| 99 | + (let [uri (.getAsString ^JsonPrimitive (.getArgumentAt command 0)) |
| 100 | + line (dec (.getAsInt ^JsonPrimitive (.getArgumentAt command 1))) |
| 101 | + character (dec (.getAsInt ^JsonPrimitive (.getArgumentAt command 2))) |
| 102 | + references (lsp-client/references uri line character project) |
| 103 | + language-server @(.getLanguageServer (LanguageServerManager/getInstance project) "clojure-lsp")] |
| 104 | + (.findShowUsagesInPopup |
| 105 | + (LSPUsagesManager/getInstance project) |
| 106 | + (mapv #(LocationData. % language-server) references) |
| 107 | + LSPUsageType/References |
| 108 | + (.getDataContext event) |
| 109 | + (.getInputEvent event)))) |
| 110 | + |
79 | 111 | (defn -runActivity [_this ^Project project]
|
80 | 112 | (doseq [{:keys [name text description use-shortcut-of keyboard-shortcut]} clojure-lsp-commands]
|
81 | 113 | (action/register-action! :id (str "ClojureLSP." (csk/->PascalCase name))
|
|
85 | 117 | :keyboard-shortcut keyboard-shortcut
|
86 | 118 | :use-shortcut-of use-shortcut-of
|
87 | 119 | :on-performed (partial on-action-performed name text project)))
|
| 120 | + (register-command! :id "code-lens-references" |
| 121 | + :on-performed (partial code-lens-references-performed project)) |
88 | 122 | (action/register-group! :id "ClojureLSP.Refactors"
|
89 | 123 | :popup true
|
90 | 124 | :text "Clojure refactors"
|
|
0 commit comments