Add Joyride tools for VS Code automation

This commit is contained in:
richrobber2 2025-10-22 16:21:09 -07:00
parent 700daee4d7
commit 273f611cdb
6 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,7 @@
(ns current-selection
(:require ["vscode" :as vscode]))
(defn get-current-selection []
(let [editor vscode/window.activeTextEditor]
(when editor
(.getText (.-document editor) (.-selection editor)))))

5
.joyride/src/hello.cljs Normal file
View File

@ -0,0 +1,5 @@
(ns hello
(:require ["vscode" :as vscode]))
(defn greet []
(vscode/window.showInformationMessage "Hello from custom Joyride script!"))

View File

@ -0,0 +1,5 @@
(ns open-editors
(:require ["vscode" :as vscode]))
(defn get-open-editors []
(map #(.-fileName (.-document %)) vscode/window.visibleTextEditors))

View File

@ -0,0 +1,9 @@
(ns run_command
(:require ["vscode" :as vscode]))
(defn execute-command [cmd & args]
(apply vscode/commands.executeCommand cmd args))
(defn open-file [path]
(let [uri (vscode/Uri.file path)]
(vscode/window.showTextDocument uri)))

View File

@ -0,0 +1,56 @@
(ns terminal.interaction
(:require ["vscode" :as vscode]))
;; Helper function to find a terminal by name
(defn- find-terminal [name]
(first (filter #(= (.-name %) name) (.-terminals vscode/window))))
;; Helper function to notify user
(defn- notify [message]
(vscode/window.showInformationMessage message))
;; List all terminal names
(defn list-terminals []
(map #(.-name %) (.-terminals vscode/window)))
;; Create a new terminal and notify
(defn create-terminal [name]
(let [term (vscode/window.createTerminal name)]
(notify (str "Created terminal: " name))
term))
;; Send command to a terminal, creating it if it doesn't exist
(defn send-command [cmd & [term-name]]
(let [term (if term-name
(or (find-terminal term-name)
(let [new-term (create-terminal term-name)]
new-term))
(or (first (.-terminals vscode/window))
(create-terminal "default")))]
(when term
(.sendText term cmd)
(notify (str "Sent command: " cmd " to " (or term-name "default") " terminal")))))
;; Dispose a terminal by name and notify
(defn dispose-terminal [name]
(let [term (find-terminal name)]
(if term
(do (.dispose term)
(notify (str "Disposed terminal: " name)))
(notify (str "Terminal not found: " name)))))
;; Get the process ID of a terminal (promise)
(defn get-terminal-pid [name]
(when-let [term (find-terminal name)]
(.-processId term)))
;; Get user input via input box (promise)
(defn get-user-input [prompt]
(vscode/window.showInputBox {:prompt prompt}))
;; Select a terminal via quick pick (promise)
(defn select-terminal []
(let [terms (list-terminals)]
(vscode/window.showQuickPick (clj->js terms) {:placeHolder "Select a terminal"})))
;; Note: Output capture is event-based in VS Code API; use onDidWriteTerminalData for advanced cases

View File

@ -0,0 +1,9 @@
(ns workspace-info
(:require ["vscode" :as vscode]))
(defn get-workspace-folders []
(map #(.-name %) (.-workspaceFolders vscode/workspace)))
(defn get-workspace-root []
(when-let [folders (.-workspaceFolders vscode/workspace)]
(.-fsPath (.-uri (first folders)))))