Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next release #11

Merged
merged 11 commits into from
Dec 14, 2024
24 changes: 0 additions & 24 deletions .github/workflows/document.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,3 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

changelog:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --verbose
env:
OUTPUT: CHANGELOG.adoc
GITHUB_REPO: ${{ github.repository }}

- run: |
git diff
git config --global user.email "[email protected]"
git config --global user.name "github-actions"
git add CHANGELOG.adoc
git commit -m "Update CHANGELOG" || exit 0
git push
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: release
on: workflow_dispatch

jobs:
tag_and_release:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Calendar Version
id: calendar-version
uses: harm-matthias-harms/calendar-version@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: ncipollo/release-action@v1
with:
tag: ${{ steps.calendar-version.outputs.new-tag }}-alpha
skipIfReleaseExists: true
generateReleaseNotes: true

changelog:
needs: [tag_and_release]
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --verbose
env:
OUTPUT: CHANGELOG.adoc
GITHUB_REPO: ${{ github.repository }}

- run: |
git diff
git config --global user.email "[email protected]"
git config --global user.name "github-actions"
git add CHANGELOG.adoc
git commit -m "Update CHANGELOG" || exit 0
git push
6 changes: 3 additions & 3 deletions cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ commit_parsers = [
{ message = "^deps", group = "Changed" },
{ message = "^breaking", group = "Removed" },
{ message = "^docs", skip = true },
{ message = "^style", group = "Changed" },
{ message = "^refactor", group = "Changed" },
{ message = "^test", group = "Fixed" },
{ message = "^style", skip = true },
{ message = "^refactor", skip = true },
{ message = "^test", skip = true },
{ message = "^chore", skip = true },
]
# filter out the commits that are not matched by commit parsers
Expand Down
2 changes: 1 addition & 1 deletion dev/analysis.edn

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion src/elin/constant/jack_in.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,31 @@
(def clojure-cli :clojure-cli)
(def leiningen :leiningen)
(def babashka :babashka)
(def squint :squint)
(def nbb :nbb)

(def supported-project-types [clojure-cli babashka])
(def supported-project-types
[clojure-cli
babashka
squint
nbb])

(def clojure-command
(or (System/getenv "ELIN_REPL_CLOJURE_CLI_CMD")
"clj"))

(def babashka-command
(or (System/getenv "ELIN_REPL_BABASHKA_CMD")
"bb"))

(def squint-command
(or (System/getenv "ELIN_REPL_SQUINT_CMD")
"squint"))

(def nbb-command
(or (System/getenv "ELIN_REPL_NBB_CMD")
"nbb"))

(def deno-command
(or (System/getenv "ELIN_REPL_DENO_CMD")
"deno"))
3 changes: 3 additions & 0 deletions src/elin/constant/nrepl.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(ns elin.constant.nrepl)

(def lang-clojure "clojure")
(def lang-clojurescript "clojurescript")

(def array-key-set
#{"status" "sessions" "classpath"
;; cider-nrepl complete op
Expand Down
3 changes: 2 additions & 1 deletion src/elin/function/connect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

(defn connect
[{:as elin :component/keys [interceptor]}
{:keys [hostname port wait?]}]
{:keys [hostname port language wait?]}]
(let [context (-> elin
(e.u.map/select-keys-by-namespace :component)
(assoc :hostname hostname
:port port
:language language
:wait? wait?))
connect-fn (fn [{:as ctx :component/keys [nrepl]
:keys [error hostname port language port-file wait?]}]
Expand Down
88 changes: 57 additions & 31 deletions src/elin/function/jack_in.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
[clojure.edn :as edn]
[clojure.java.io :as io]
[elin.constant.jack-in :as e.c.jack-in]
[elin.constant.nrepl :as e.c.nrepl]
[elin.error :as e]
[elin.protocol.host :as e.p.host]
[elin.util.nrepl :as e.u.nrepl]
[elin.util.process :as e.u.process]))

(def ^:private clojure-command
(or (System/getenv "ELIN_REPL_CLOJURE_CLI_CMD")
"clj"))

(def ^:private babashka-command
(or (System/getenv "ELIN_REPL_BABASHKA_CMD")
"bb"))

(def ^:private elin-root-dir
(-> (io/file *file*)
(.getParentFile)
Expand Down Expand Up @@ -67,26 +60,59 @@
(edn/read-string)
(get-in [:__elin_internal__ :command])))

(defn generate-command
([project-type port]
(generate-command project-type port []))
([project-type port optional-args]
(condp = project-type
e.c.jack-in/clojure-cli
(concat [clojure-command]
optional-args
["-Sdeps" (pr-str {:deps (:deps command-config)})
"-M" "-m" "nrepl.cmdline"
"--port" (str port)
"--middleware" (pr-str (:middlewares command-config))
"--interactive"])

e.c.jack-in/babashka
[babashka-command
"nrepl-server"
(str "localhost:" port)]

(e/unsupported))))
(defmulti generate-command
(fn [project-type _port _optional-args]
project-type))

(defmethod generate-command :default
[_ _ _]
(e/unsupported))

(defmethod generate-command e.c.jack-in/clojure-cli
[_ port optional-args]
{:language e.c.nrepl/lang-clojure
:command (concat [e.c.jack-in/clojure-command]
optional-args
["-Sdeps" (pr-str {:deps (:deps command-config)})
"-M" "-m" "nrepl.cmdline"
"--port" (str port)
"--middleware" (pr-str (:middlewares command-config))
"--interactive"])})

(defmethod generate-command e.c.jack-in/babashka
[_ port _]
{:language e.c.nrepl/lang-clojure
:command [e.c.jack-in/babashka-command
"nrepl-server"
(str "localhost:" port)]})

(defmethod generate-command e.c.jack-in/squint
[_ port _]
(e/let [squint-cmd (cond
(e.u.process/executable? e.c.jack-in/squint-command)
[e.c.jack-in/squint-command]

(e.u.process/executable? e.c.jack-in/deno-command)
[e.c.jack-in/deno-command "run" "-A" "npm:squint-cljs@latest"]

:else
(e/not-found {:message "squint of deno command is required"}))]
{:language e.c.nrepl/lang-clojurescript
:command (concat squint-cmd ["nrepl-server" ":port" (str port)])}))

(defmethod generate-command e.c.jack-in/nbb
[_ port _]
(e/let [nbb-cmd (cond
(e.u.process/executable? e.c.jack-in/nbb-command)
[e.c.jack-in/nbb-command]

(e.u.process/executable? e.c.jack-in/deno-command)
[e.c.jack-in/deno-command "run" "-A" "npm:nbb@latest"]

:else
(e/not-found {:message "nbb or deno command is required"}))]
{:language e.c.nrepl/lang-clojure
:command (concat nbb-cmd ["nrepl-server" ":port" (str port)])}))

(defn port->process-id
[port]
Expand All @@ -101,7 +127,7 @@
[project-type project-file] (select-project options path)
project-root-dir (parent-absolute-path project-file)
port (e.u.nrepl/get-free-port)
args (->> (generate-command project-type port)
(cons {:dir project-root-dir}))]
{:keys [language command]} (generate-command project-type port [])
args (cons {:dir project-root-dir} command)]
(e.u.process/start (port->process-id port) args)
port)))
{:language language :port port})))
14 changes: 7 additions & 7 deletions src/elin/handler/connect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
(defn jack-in
"Launch nREPL server according to the project detected from the current file and connect to it."
[{:as elin :component/keys [host]}]
(let [port (e.f.jack-in/launch-process elin)]
(e.message/info host (format "Wainting to connect to localhost:%s" port))
(connect* elin {:hostname "localhost" :port port :wait? true})))
(let [{:keys [language port]} (e.f.jack-in/launch-process elin)]
(e.message/info host (format "Waiting to connect to localhost:%s" port))
(connect* elin {:hostname "localhost" :port port :language language :wait? true})))

(def ^:private ?InstantParams
[:catn
Expand All @@ -91,12 +91,12 @@
"Launch nREPL server of the specified project and connect to it."
[{:as elin :component/keys [host] :keys [message]}]
(let [[{:keys [project]} error] (e.u.param/parse ?InstantParams (:params message))
port (when-not error
(e.f.jack-in/launch-process elin {:forced-project (keyword project)}))]
{:keys [port language]} (when-not error
(e.f.jack-in/launch-process elin {:forced-project (keyword project)}))]
(if error
(e.message/error host "Invalid parameter" error)
(do (e.message/info host (format "Wainting to connect to localhost:%s" port))
(connect* elin {:hostname "localhost" :port port :wait? true})))))
(do (e.message/info host (format "Waiting to connect to localhost:%s" port))
(connect* elin {:hostname "localhost" :port port :language language :wait? true})))))

(defn switch
"Switch the current nREPL connection to another connected one."
Expand Down
3 changes: 2 additions & 1 deletion src/elin/interceptor/connect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
[clojure.core.async :as async]
[elin.constant.interceptor :as e.c.interceptor]
[elin.constant.nrepl :as e.c.nrepl]
[elin.function.jack-in :as e.f.jack-in]
[elin.protocol.host :as e.p.host]
[elin.protocol.interceptor :as e.p.interceptor]
Expand All @@ -17,7 +18,7 @@
(defn- find-clojure-port-file
[cwd]
(when-let [file (e.u.file/find-file-in-parent-directories cwd ".nrepl-port")]
{:language "clojure"
{:language e.c.nrepl/lang-clojure
:port-file (.getAbsolutePath file)
:port (some->> file slurp Long/parseLong)}))

Expand Down
6 changes: 4 additions & 2 deletions src/elin/interceptor/connect/shadow_cljs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[clojure.java.io :as io]
[clojure.string :as str]
[elin.constant.interceptor :as e.c.interceptor]
[elin.constant.nrepl :as e.c.nrepl]
[elin.function.evaluate :as e.f.evaluate]
[elin.function.select :as e.f.select]
[elin.protocol.host :as e.p.host]
Expand All @@ -26,7 +27,7 @@
(when-let [file (some-> (e.u.file/find-file-in-parent-directories cwd ".shadow-cljs")
(io/file "nrepl.port"))]
(when (.exists file)
{:language "clojurescript"
{:language e.c.nrepl/lang-clojurescript
:port-file (.getAbsolutePath file)
:port (some->> file slurp Long/parseLong)})))

Expand Down Expand Up @@ -58,7 +59,8 @@

:leave (-> (fn [{:as ctx :component/keys [nrepl]}]
(let [{:keys [language port-file]} (e.p.nrepl/current-client nrepl)]
(when (and (= "clojurescript" language)
(when (and (= e.c.nrepl/lang-clojurescript language)
(string? port-file)
(str/includes? port-file "shadow-cljs"))

(let [build-id (-> (e.f.evaluate/evaluate-code ctx shadow-cljs-build-ids-code)
Expand Down
5 changes: 4 additions & 1 deletion src/elin/schema/nrepl.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns elin.schema.nrepl
(:require
[elin.constant.nrepl :as e.c.nrepl]
[elin.schema :as e.schema]
[malli.util :as m.util])
(:import
Expand Down Expand Up @@ -33,7 +34,9 @@
[:initial-namespace [:maybe string?]]
[:version [:map-of keyword? any?]]
[:port-file [:maybe string?]]
[:language [:maybe [:enum "clojure" "clojurescript"]]]])
[:language [:maybe [:enum
e.c.nrepl/lang-clojure
e.c.nrepl/lang-clojurescript]]]])

(def ?Manager
[:map-of int? [:map
Expand Down
10 changes: 10 additions & 0 deletions src/elin/util/process.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@
[process-id]
(when-let [process (get @manager process-id)]
(proc/destroy process)))

(defn- executable?*
[command]
(try
(let [process (proc/process [command])]
(proc/destroy process)
true)
(catch Exception _
false)))
(def executable? (memoize executable?*))
Loading
Loading