|
4 | 4 | :implements [com.intellij.openapi.startup.StartupActivity
|
5 | 5 | com.intellij.openapi.project.DumbAware])
|
6 | 6 | (:require
|
| 7 | + [camel-snake-kebab.core :as csk] |
7 | 8 | [com.github.clojure-lsp.intellij.client :as lsp-client]
|
| 9 | + [com.github.clojure-lsp.intellij.db :as db] |
| 10 | + [com.github.clojure-lsp.intellij.editor :as editor] |
8 | 11 | [com.github.ericdallo.clj4intellij.action :as action]
|
9 | 12 | [com.github.ericdallo.clj4intellij.logger :as logger]
|
10 |
| - [com.rpl.proxy-plus :refer [proxy+]]) |
| 13 | + [com.github.ericdallo.clj4intellij.tasks :as tasks] |
| 14 | + [com.github.ericdallo.clj4intellij.util :as util]) |
11 | 15 | (:import
|
12 | 16 | [com.github.clojure_lsp.intellij Icons]
|
13 |
| - [com.intellij.openapi.actionSystem ActionManager AnActionEvent KeyboardShortcut] |
14 |
| - [com.intellij.openapi.keymap KeymapManager] |
15 |
| - [com.intellij.openapi.project Project] |
16 |
| - [com.redhat.devtools.lsp4ij.commands LSPCommandAction] |
17 |
| - [javax.swing Icon KeyStroke])) |
| 17 | + [com.intellij.openapi.actionSystem AnActionEvent CommonDataKeys] |
| 18 | + [com.intellij.openapi.editor Editor] |
| 19 | + [com.intellij.openapi.project Project])) |
18 | 20 |
|
19 | 21 | (set! *warn-on-reflection* true)
|
20 | 22 |
|
|
65 | 67 | {:name "raise-sexp" :text "Raise sexpr" :description "Raise current sexpr (Paredit)" :keyboard-shortcut {:first "alt R" :replace-all true}}
|
66 | 68 | {:name "kill-sexp" :text "Kill sexpr" :description "Kill current sexpr (Paredit)" :keyboard-shortcut {:first "alt K" :replace-all true}}])
|
67 | 69 |
|
68 |
| -#_{:clj-kondo/ignore [:unused-binding]} |
69 |
| -(defn register-command! |
70 |
| - [& {:keys [project id title description icon args use-shortcut-of keyboard-shortcut on-performed]}] |
71 |
| - (let [manager (ActionManager/getInstance) |
72 |
| - keymap-manager (KeymapManager/getInstance) |
73 |
| - keymap (.getActiveKeymap keymap-manager) |
74 |
| - action (proxy+ ClojureLSPCommand [] LSPCommandAction |
75 |
| - (commandPerformed [_ _command ^AnActionEvent event] |
76 |
| - (lsp-client/execute-command id title)))] |
77 |
| - |
78 |
| - (.setText (.getTemplatePresentation action) ^String title) |
79 |
| - (.setIcon (.getTemplatePresentation action) ^Icon icon) |
80 |
| - (when-not (.getAction manager id) |
81 |
| - (.registerAction manager id action) |
82 |
| - (when use-shortcut-of |
83 |
| - (.addShortcut keymap |
84 |
| - id |
85 |
| - (first (.getShortcuts (.getShortcutSet (.getAction manager use-shortcut-of)))))) |
86 |
| - (when keyboard-shortcut |
87 |
| - (let [k-shortcut (KeyboardShortcut. (KeyStroke/getKeyStroke ^String (:first keyboard-shortcut)) |
88 |
| - (some-> ^String (:second keyboard-shortcut) KeyStroke/getKeyStroke))] |
89 |
| - (when (empty? (.getShortcuts keymap id)) |
90 |
| - (.addShortcut keymap id k-shortcut)) |
91 |
| - (when (:replace-all keyboard-shortcut) |
92 |
| - (doseq [[conflict-action-id shortcuts] (.getConflicts keymap id k-shortcut)] |
93 |
| - (doseq [shortcut shortcuts] |
94 |
| - (.removeShortcut keymap conflict-action-id shortcut)))))) |
95 |
| - action))) |
| 70 | +(defn ^:private on-action-performed [command-name text project ^AnActionEvent event] |
| 71 | + (when-let [editor ^Editor (.getData event CommonDataKeys/EDITOR)] |
| 72 | + (let [[line character] (util/editor->cursor-position editor)] |
| 73 | + (tasks/run-background-task! |
| 74 | + project |
| 75 | + "LSP: refactoring" |
| 76 | + (fn [_] |
| 77 | + (lsp-client/execute-command command-name text [(editor/editor->uri editor) line character] project)))))) |
96 | 78 |
|
97 | 79 | (defn -runActivity [_this ^Project project]
|
98 |
| - (doseq [{:keys [name text args description use-shortcut-of keyboard-shortcut]} clojure-lsp-commands] |
99 |
| - (register-command! :id name |
100 |
| - :project project |
101 |
| - :title text |
102 |
| - :description description |
103 |
| - :args args |
104 |
| - :icon Icons/CLOJURE |
105 |
| - :keyboard-shortcut keyboard-shortcut |
106 |
| - :use-shortcut-of use-shortcut-of)) |
| 80 | + (doseq [{:keys [name text description use-shortcut-of keyboard-shortcut]} clojure-lsp-commands] |
| 81 | + (action/register-action! :id (str "ClojureLSP." (csk/->PascalCase name)) |
| 82 | + :title text |
| 83 | + :description description |
| 84 | + :icon Icons/CLOJURE |
| 85 | + :keyboard-shortcut keyboard-shortcut |
| 86 | + :use-shortcut-of use-shortcut-of |
| 87 | + :on-performed (partial on-action-performed name text project))) |
107 | 88 | (action/register-group! :id "ClojureLSP.Refactors"
|
108 | 89 | :popup true
|
109 | 90 | :text "Clojure refactors"
|
110 | 91 | :icon Icons/CLOJURE
|
111 | 92 | :children (concat [{:type :add-to-group :group-id "RefactoringMenu" :anchor :first}]
|
112 |
| - (mapv (fn [{:keys [name]}] {:type :reference :ref name}) clojure-lsp-commands) |
| 93 | + (mapv (fn [{:keys [name]}] {:type :reference :ref (str "ClojureLSP." (csk/->PascalCase name))}) clojure-lsp-commands) |
113 | 94 | [{:type :separator}]))
|
114 | 95 | (logger/info "Actions registered"))
|
| 96 | + |
| 97 | +(comment |
| 98 | + (-runActivity nil (first (db/all-projects)))) |
0 commit comments