|
|
@@ -18,8 +18,8 @@
|
|
|
[frontend.format :as format]))
|
|
|
|
|
|
(defonce lsp-enabled?
|
|
|
- (and (util/electron?)
|
|
|
- (= (storage/get "developer-mode") "true")))
|
|
|
+ (and (util/electron?)
|
|
|
+ (= (storage/get "developer-mode") "true")))
|
|
|
|
|
|
(defn invoke-exported-api
|
|
|
[type & args]
|
|
|
@@ -45,26 +45,26 @@
|
|
|
[refresh?]
|
|
|
(if (or refresh? (nil? (:plugin/marketplace-pkgs @state/state)))
|
|
|
(p/create
|
|
|
- (fn [resolve reject]
|
|
|
- (-> (util/fetch plugins-url
|
|
|
- (fn [res]
|
|
|
- (let [pkgs (:packages res)]
|
|
|
- (state/set-state! :plugin/marketplace-pkgs pkgs)
|
|
|
- (resolve pkgs)))
|
|
|
- reject)
|
|
|
- (p/catch reject))))
|
|
|
+ (fn [resolve reject]
|
|
|
+ (-> (util/fetch plugins-url
|
|
|
+ (fn [res]
|
|
|
+ (let [pkgs (:packages res)]
|
|
|
+ (state/set-state! :plugin/marketplace-pkgs pkgs)
|
|
|
+ (resolve pkgs)))
|
|
|
+ reject)
|
|
|
+ (p/catch reject))))
|
|
|
(p/resolved (:plugin/marketplace-pkgs @state/state))))
|
|
|
|
|
|
(defn load-marketplace-stats
|
|
|
[refresh?]
|
|
|
(if (or refresh? (nil? (:plugin/marketplace-stats @state/state)))
|
|
|
(p/create
|
|
|
- (fn [resolve reject]
|
|
|
- (util/fetch stats-url
|
|
|
- (fn [res]
|
|
|
- (state/set-state! :plugin/marketplace-stats res)
|
|
|
- (resolve nil))
|
|
|
- reject)))
|
|
|
+ (fn [resolve reject]
|
|
|
+ (util/fetch stats-url
|
|
|
+ (fn [res]
|
|
|
+ (state/set-state! :plugin/marketplace-stats res)
|
|
|
+ (resolve nil))
|
|
|
+ reject)))
|
|
|
(p/resolved nil)))
|
|
|
|
|
|
(defn installed?
|
|
|
@@ -77,30 +77,30 @@
|
|
|
(when-not (and (:plugin/installing @state/state)
|
|
|
(installed? id))
|
|
|
(p/create
|
|
|
- (fn [resolve]
|
|
|
- (state/set-state! :plugin/installing mft)
|
|
|
- (ipc/ipc "installMarketPlugin" mft)
|
|
|
- (resolve id)))))
|
|
|
+ (fn [resolve]
|
|
|
+ (state/set-state! :plugin/installing mft)
|
|
|
+ (ipc/ipc "installMarketPlugin" mft)
|
|
|
+ (resolve id)))))
|
|
|
|
|
|
(defn update-marketplace-plugin
|
|
|
[{:keys [id] :as pkg} error-handler]
|
|
|
(when-not (and (:plugin/installing @state/state)
|
|
|
(not (installed? id)))
|
|
|
(p/catch
|
|
|
- (p/then
|
|
|
- (do (state/set-state! :plugin/installing pkg)
|
|
|
- (load-marketplace-plugins false))
|
|
|
- (fn [mfts]
|
|
|
- (if-let [mft (some #(if (= (:id %) id) %) mfts)]
|
|
|
- (do
|
|
|
- (ipc/ipc "updateMarketPlugin" (merge (dissoc pkg :logger) mft)))
|
|
|
- (throw (js/Error. (str ":central-not-matched " id))))
|
|
|
- true))
|
|
|
-
|
|
|
- (fn [^js e]
|
|
|
- (error-handler "Update Error: remote error")
|
|
|
- (state/set-state! :plugin/installing nil)
|
|
|
- (js/console.error e)))))
|
|
|
+ (p/then
|
|
|
+ (do (state/set-state! :plugin/installing pkg)
|
|
|
+ (load-marketplace-plugins false))
|
|
|
+ (fn [mfts]
|
|
|
+ (if-let [mft (some #(if (= (:id %) id) %) mfts)]
|
|
|
+ (do
|
|
|
+ (ipc/ipc "updateMarketPlugin" (merge (dissoc pkg :logger) mft)))
|
|
|
+ (throw (js/Error. (str ":central-not-matched " id))))
|
|
|
+ true))
|
|
|
+
|
|
|
+ (fn [^js e]
|
|
|
+ (error-handler "Update Error: remote error")
|
|
|
+ (state/set-state! :plugin/installing nil)
|
|
|
+ (js/console.error e)))))
|
|
|
|
|
|
(defn get-plugin-inst
|
|
|
[id]
|
|
|
@@ -124,18 +124,18 @@
|
|
|
(if (installed? id)
|
|
|
(when-let [^js pl (get-plugin-inst id)] ;; update
|
|
|
(p/then
|
|
|
- (.reload pl)
|
|
|
- #(do
|
|
|
+ (.reload pl)
|
|
|
+ #(do
|
|
|
;;(if theme (select-a-plugin-theme id))
|
|
|
- (notifications/show!
|
|
|
- (str (t :plugin/update) (t :plugins) ": " name " - " (.-version (.-options pl))) :success))))
|
|
|
+ (notifications/show!
|
|
|
+ (str (t :plugin/update) (t :plugins) ": " name " - " (.-version (.-options pl))) :success))))
|
|
|
|
|
|
(do ;; register new
|
|
|
(p/then
|
|
|
- (js/LSPluginCore.register (bean/->js {:key id :url dst}))
|
|
|
- (fn [] (if theme (js/setTimeout #(select-a-plugin-theme id) 300))))
|
|
|
+ (js/LSPluginCore.register (bean/->js {:key id :url dst}))
|
|
|
+ (fn [] (if theme (js/setTimeout #(select-a-plugin-theme id) 300))))
|
|
|
(notifications/show!
|
|
|
- (str (t :plugin/installed) (t :plugins) ": " name) :success))))
|
|
|
+ (str (t :plugin/installed) (t :plugins) ": " name) :success))))
|
|
|
|
|
|
:error
|
|
|
(let [[msg type] (case (keyword (string/replace payload #"^[\s\:]+" ""))
|
|
|
@@ -146,9 +146,9 @@
|
|
|
[payload :error])]
|
|
|
|
|
|
(notifications/show!
|
|
|
- (str
|
|
|
- (if (= :error type) "[Install Error]" "")
|
|
|
- msg) type)
|
|
|
+ (str
|
|
|
+ (if (= :error type) "[Install Error]" "")
|
|
|
+ msg) type)
|
|
|
|
|
|
(js/console.error payload))
|
|
|
|
|
|
@@ -188,15 +188,37 @@
|
|
|
[pid]
|
|
|
(swap! state/state md/dissoc-in [:plugin/installed-commands (keyword pid)]))
|
|
|
|
|
|
+(def keybinding-mode-handler-map
|
|
|
+ {:global :shortcut.handler/editor-global
|
|
|
+ :non-editing :shortcut.handler/global-non-editing-only
|
|
|
+ :editing :shortcut.handler/block-editing-only})
|
|
|
+
|
|
|
(defn simple-cmd->palette-cmd
|
|
|
- [pid {:keys [key label type desc] :as cmd} action]
|
|
|
- (let [palette-cmd {:id (keyword (str "plugin." pid "/" key))
|
|
|
- :desc (or desc label)
|
|
|
- :action (fn []
|
|
|
- (state/pub-event!
|
|
|
- [:exec-plugin-cmd {:type type :key key :pid pid :cmd cmd :action action}]))}]
|
|
|
+ [pid {:keys [key label type desc keybinding] :as cmd} action]
|
|
|
+ (let [palette-cmd {:id (keyword (str "plugin." pid "/" key))
|
|
|
+ :desc (or desc label)
|
|
|
+ :shortcut (when-let [shortcut (:binding keybinding)]
|
|
|
+ (if util/mac?
|
|
|
+ (or (:mac keybinding) shortcut)
|
|
|
+ shortcut))
|
|
|
+ :handler-id (let [mode (or (:mode keybinding) :global)]
|
|
|
+ (get keybinding-mode-handler-map (keyword mode)))
|
|
|
+ :action (fn []
|
|
|
+ (state/pub-event!
|
|
|
+ [:exec-plugin-cmd {:type type :key key :pid pid :cmd cmd :action action}]))}]
|
|
|
palette-cmd))
|
|
|
|
|
|
+(defn simple-cmd-keybinding->shortcut-args
|
|
|
+ [pid key keybinding]
|
|
|
+ (let [id (keyword (str "plugin." pid "/" key))
|
|
|
+ binding (:binding keybinding)
|
|
|
+ binding (if util/mac?
|
|
|
+ (or (:mac keybinding) binding)
|
|
|
+ binding)
|
|
|
+ mode (or (:mode keybinding) :global)
|
|
|
+ mode (get keybinding-mode-handler-map (keyword mode))]
|
|
|
+ [mode id {:binding binding}]))
|
|
|
+
|
|
|
(defn register-plugin-simple-command
|
|
|
;; action => [:action-key :event-key]
|
|
|
[pid {:keys [key label type] :as cmd} action]
|
|
|
@@ -245,11 +267,11 @@
|
|
|
(when-not (string/blank? content)
|
|
|
(let [content (if-not (string/blank? url)
|
|
|
(string/replace
|
|
|
- content #"!\[[^\]]*\]\((.*?)\s*(\"(?:.*[^\"])\")?\s*\)"
|
|
|
- (fn [[matched link]]
|
|
|
- (if (and link (not (string/starts-with? link "http")))
|
|
|
- (string/replace matched link (util/node-path.join url link))
|
|
|
- matched)))
|
|
|
+ content #"!\[[^\]]*\]\((.*?)\s*(\"(?:.*[^\"])\")?\s*\)"
|
|
|
+ (fn [[matched link]]
|
|
|
+ (if (and link (not (string/starts-with? link "http")))
|
|
|
+ (string/replace matched link (util/node-path.join url link))
|
|
|
+ matched)))
|
|
|
content)]
|
|
|
(format/to-html content :markdown (mldoc/default-config :markdown))))
|
|
|
(catch js/Error e
|
|
|
@@ -316,11 +338,11 @@
|
|
|
(defn- get-user-default-plugins
|
|
|
[]
|
|
|
(p/catch
|
|
|
- (p/let [files ^js (ipc/ipc "getUserDefaultPlugins")
|
|
|
- files (js->clj files)]
|
|
|
- (map #(hash-map :url %) files))
|
|
|
- (fn [e]
|
|
|
- (js/console.error e))))
|
|
|
+ (p/let [files ^js (ipc/ipc "getUserDefaultPlugins")
|
|
|
+ files (js->clj files)]
|
|
|
+ (map #(hash-map :url %) files))
|
|
|
+ (fn [e]
|
|
|
+ (js/console.error e))))
|
|
|
|
|
|
;; components
|
|
|
(rum/defc lsp-indicator < rum/reactive
|
|
|
@@ -338,76 +360,76 @@
|
|
|
(let [el (js/document.createElement "div")]
|
|
|
(.appendChild js/document.body el)
|
|
|
(rum/mount
|
|
|
- (lsp-indicator) el))
|
|
|
+ (lsp-indicator) el))
|
|
|
|
|
|
(state/set-state! :plugin/indicator-text "LOADING")
|
|
|
|
|
|
(p/then
|
|
|
- (p/let [root (get-ls-dotdir-root)
|
|
|
- _ (.setupPluginCore js/LSPlugin (bean/->js {:localUserConfigRoot root :dotConfigRoot root}))
|
|
|
+ (p/let [root (get-ls-dotdir-root)
|
|
|
+ _ (.setupPluginCore js/LSPlugin (bean/->js {:localUserConfigRoot root :dotConfigRoot root}))
|
|
|
|
|
|
- clear-commands! (fn [pid]
|
|
|
+ clear-commands! (fn [pid]
|
|
|
;; commands
|
|
|
- (unregister-plugin-slash-command pid)
|
|
|
- (invoke-exported-api "unregister_plugin_simple_command" pid)
|
|
|
- (unregister-plugin-ui-items pid))
|
|
|
-
|
|
|
- _ (doto js/LSPluginCore
|
|
|
- (.on "registered"
|
|
|
- (fn [^js pl]
|
|
|
- (register-plugin
|
|
|
- (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
|
|
|
-
|
|
|
- (.on "reloaded"
|
|
|
- (fn [^js pl]
|
|
|
- (register-plugin
|
|
|
- (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
|
|
|
-
|
|
|
- (.on "unregistered" (fn [pid]
|
|
|
- (let [pid (keyword pid)]
|
|
|
+ (unregister-plugin-slash-command pid)
|
|
|
+ (invoke-exported-api "unregister_plugin_simple_command" pid)
|
|
|
+ (unregister-plugin-ui-items pid))
|
|
|
+
|
|
|
+ _ (doto js/LSPluginCore
|
|
|
+ (.on "registered"
|
|
|
+ (fn [^js pl]
|
|
|
+ (register-plugin
|
|
|
+ (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
|
|
|
+
|
|
|
+ (.on "reloaded"
|
|
|
+ (fn [^js pl]
|
|
|
+ (register-plugin
|
|
|
+ (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
|
|
|
+
|
|
|
+ (.on "unregistered" (fn [pid]
|
|
|
+ (let [pid (keyword pid)]
|
|
|
;; effects
|
|
|
- (unregister-plugin-themes pid)
|
|
|
+ (unregister-plugin-themes pid)
|
|
|
;; plugins
|
|
|
- (swap! state/state md/dissoc-in [:plugin/installed-plugins pid])
|
|
|
+ (swap! state/state md/dissoc-in [:plugin/installed-plugins pid])
|
|
|
;; commands
|
|
|
- (clear-commands! pid))))
|
|
|
-
|
|
|
- (.on "unlink-plugin" (fn [pid]
|
|
|
- (let [pid (keyword pid)]
|
|
|
- (ipc/ipc "uninstallMarketPlugin" (name pid)))))
|
|
|
-
|
|
|
- (.on "beforereload" (fn [^js pl]
|
|
|
- (let [pid (.-id pl)]
|
|
|
- (clear-commands! pid)
|
|
|
- (unregister-plugin-themes pid false))))
|
|
|
-
|
|
|
- (.on "disabled" (fn [pid]
|
|
|
- (clear-commands! pid)
|
|
|
- (unregister-plugin-themes pid)))
|
|
|
-
|
|
|
- (.on "theme-changed" (fn [^js themes]
|
|
|
- (swap! state/state assoc :plugin/installed-themes
|
|
|
- (vec (mapcat (fn [[pid vs]] (mapv #(assoc % :pid pid) (bean/->clj vs))) (bean/->clj themes))))))
|
|
|
-
|
|
|
- (.on "theme-selected" (fn [^js opts]
|
|
|
- (let [opts (bean/->clj opts)
|
|
|
- url (:url opts)
|
|
|
- mode (:mode opts)]
|
|
|
- (when mode (state/set-theme! mode))
|
|
|
- (state/set-state! :plugin/selected-theme url))))
|
|
|
-
|
|
|
- (.on "settings-changed" (fn [id ^js settings]
|
|
|
- (let [id (keyword id)]
|
|
|
- (when (and settings
|
|
|
- (contains? (:plugin/installed-plugins @state/state) id))
|
|
|
- (update-plugin-settings id (bean/->clj settings)))))))
|
|
|
-
|
|
|
- default-plugins (get-user-default-plugins)
|
|
|
-
|
|
|
- _ (.register js/LSPluginCore (bean/->js (if (seq default-plugins) default-plugins [])) true)])
|
|
|
- #(do
|
|
|
- (state/set-state! :plugin/indicator-text "END")
|
|
|
- (callback))))
|
|
|
+ (clear-commands! pid))))
|
|
|
+
|
|
|
+ (.on "unlink-plugin" (fn [pid]
|
|
|
+ (let [pid (keyword pid)]
|
|
|
+ (ipc/ipc "uninstallMarketPlugin" (name pid)))))
|
|
|
+
|
|
|
+ (.on "beforereload" (fn [^js pl]
|
|
|
+ (let [pid (.-id pl)]
|
|
|
+ (clear-commands! pid)
|
|
|
+ (unregister-plugin-themes pid false))))
|
|
|
+
|
|
|
+ (.on "disabled" (fn [pid]
|
|
|
+ (clear-commands! pid)
|
|
|
+ (unregister-plugin-themes pid)))
|
|
|
+
|
|
|
+ (.on "theme-changed" (fn [^js themes]
|
|
|
+ (swap! state/state assoc :plugin/installed-themes
|
|
|
+ (vec (mapcat (fn [[pid vs]] (mapv #(assoc % :pid pid) (bean/->clj vs))) (bean/->clj themes))))))
|
|
|
+
|
|
|
+ (.on "theme-selected" (fn [^js opts]
|
|
|
+ (let [opts (bean/->clj opts)
|
|
|
+ url (:url opts)
|
|
|
+ mode (:mode opts)]
|
|
|
+ (when mode (state/set-theme! mode))
|
|
|
+ (state/set-state! :plugin/selected-theme url))))
|
|
|
+
|
|
|
+ (.on "settings-changed" (fn [id ^js settings]
|
|
|
+ (let [id (keyword id)]
|
|
|
+ (when (and settings
|
|
|
+ (contains? (:plugin/installed-plugins @state/state) id))
|
|
|
+ (update-plugin-settings id (bean/->clj settings)))))))
|
|
|
+
|
|
|
+ default-plugins (get-user-default-plugins)
|
|
|
+
|
|
|
+ _ (.register js/LSPluginCore (bean/->js (if (seq default-plugins) default-plugins [])) true)])
|
|
|
+ #(do
|
|
|
+ (state/set-state! :plugin/indicator-text "END")
|
|
|
+ (callback))))
|
|
|
|
|
|
(defn setup!
|
|
|
"setup plugin core handler"
|