-
-
Save maxrothman/395c078454eed5bd108d153b33107637 to your computer and use it in GitHub Desktop.
Add symbols by making ;; MARK comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns user-activate | |
(:require ["vscode" :as vscode] | |
[joyride.core :as joyride])) | |
(defonce !db (atom {:disposables []})) | |
;; To make the activation script re-runnable we dispose of | |
;; event handlers and such that we might have registered | |
;; in previous runs. | |
(defn- clear-disposables! [] | |
(run! (fn [disposable] | |
(.dispose disposable)) | |
(:disposables @!db)) | |
(swap! !db assoc :disposables [])) | |
;; Pushing the disposables on the extension context's | |
;; subscriptions will make VS Code dispose of them when the | |
;; Joyride extension is deactivated. | |
(defn- push-disposable [disposable] | |
(swap! !db update :disposables conj disposable) | |
(-> (joyride/extension-context) | |
.-subscriptions | |
(.push disposable))) | |
;;; MARK Hello | |
(defn line-seq [document] | |
(map #(.lineAt document %) (range (.-lineCount document)))) | |
(def key-type | |
(->> vscode/SymbolKind | |
js->clj | |
(some #(when (= "Key" (second %)) (first %))))) | |
(def mark #"\s*;;; MARK (.*)") | |
(defn provide-symbols [document] | |
(if (< (.-lineCount document) 5000) | |
(->> (line-seq document) | |
(map-indexed #(vector %1 (-> (re-matches mark (.-text %2)) second))) | |
(filter (comp some? second)) | |
(map #(vscode/SymbolInformation. | |
(second %) ;Symbol name | |
key-type ;Symbol kind | |
"" ;Container name | |
(vscode/Location. (.-uri document) | |
(vscode/Position. (first %) 0)))) | |
clj->js) | |
[])) | |
(def symbol-provider | |
#js {"provideDocumentSymbols" provide-symbols}) | |
(defn- my-main [] | |
(println "Hello World, from Workspace activate.cljs script") | |
(clear-disposables!) | |
(push-disposable (.. vscode/languages (registerDocumentSymbolProvider | |
"clojure" | |
symbol-provider)))) | |
(when (= (joyride/invoked-script) joyride/*file*) | |
(my-main)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment