Skip to content

Commit 330e099

Browse files
committed
add root path to run script for better project detection
1 parent acd5a46 commit 330e099

3 files changed

Lines changed: 8 additions & 32 deletions

File tree

src/defold/editor_config.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
(let [os (determine-os)
2222
[run-file content]
2323
(case os
24-
:linux ["run.sh" (format "#!/usr/bin/env bash\n%s --config \"%s\" run launch-neovim \"%s\" \"$1\" $2" (escape-spaces bb-path) (bb-edn) config-path)]
25-
:mac ["run.sh" (format "#!/usr/bin/env bash\nexport PATH=\"/usr/bin:/usr/local/bin:$PATH\"\n%s --config \"%s\" run launch-neovim \"%s\" \"$1\" $2" (escape-spaces bb-path) (bb-edn) config-path)]
26-
:windows ["run.bat" (format "@echo off\r\n\"%s\" --config \"%s\" run launch-neovim \"%s\" \"%%~1\" %%2" bb-path (bb-edn) config-path)]
24+
:linux ["run.sh" (format "#!/usr/bin/env bash\n%s --config \"%s\" run launch-neovim \"%s\" \"$(realpath .)\" \"$1\" $2" (escape-spaces bb-path) (bb-edn) config-path)]
25+
:mac ["run.sh" (format "#!/usr/bin/env bash\nexport PATH=\"/usr/bin:/usr/local/bin:$PATH\"\n%s --config \"%s\" run launch-neovim \"%s\" \"$(realpath .)\" \"$1\" $2" (escape-spaces bb-path) (bb-edn) config-path)]
26+
:windows ["run.bat" (format "@echo off\r\n\"%s\" --config \"%s\" run launch-neovim \"%s\" \"%CD%\" \"%%~1\" %%2" bb-path (bb-edn) config-path)]
2727
:unknown (let [ex (ex-info "Can't create runner script for unknown operating system" {})]
2828
(log/error (ex-message ex) ex)
2929
(throw ex)))

src/defold/launcher.clj

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@
1111
seq-replace-var windows?]]
1212
[taoensso.timbre :as log]))
1313

14-
(defn- find-project-root-from-file [file]
15-
(loop [current-dir (fs/parent (fs/path file))]
16-
(if-not current-dir
17-
(throw (ex-info (str "Could not determine Defold project from path: " file) {}))
18-
(let [target (fs/path current-dir "game.project")]
19-
(if (fs/exists? target)
20-
(str current-dir)
21-
(recur (fs/parent current-dir)))))))
22-
23-
; TODO: #33 this is not a good solution, but it works for most use cases presumably
24-
(defn- find-project-root-from-file-or-use-old-one [file]
25-
(let [path (cache-dir "defold.nvim")
26-
last-used (str (fs/path path ".last-used-project-root"))]
27-
(fs/create-dirs path)
28-
(try
29-
(let [project-root (find-project-root-from-file file)]
30-
(spit last-used project-root)
31-
project-root)
32-
(catch Throwable t
33-
(log/error (ex-message t))
34-
(assert (fs/exists? last-used))
35-
(slurp last-used)))))
36-
3714
(defn- runtime-dir [project-root]
3815
(let [p (cache-dir "defold.nvim" "runtime" (project-id project-root))]
3916
(fs/create-dirs p)
@@ -172,11 +149,10 @@
172149
"terminal" (create-terminal-launcher cfg neovim)
173150
(throw (ex-info (format "Unknown launcher type: %s" (cfg "type")) {:launcher-config cfg}))))
174151

175-
(defn run [launcher-config file-name line]
152+
(defn run [launcher-config root-dir file-name line]
176153
(let [neovim (str (fs/which "nvim"))
177154
launcher (create-launcher launcher-config neovim)
178155
line (when line (Integer/parseInt line))
179-
root-dir (find-project-root-from-file-or-use-old-one file-name)
180156
class-name (format base-class-name (project-id root-dir))
181157
edit-cmd (make-neovim-edit-command file-name line)]
182158
(when (or (nil? (:cmd launcher)) (not (command-exists? (:cmd launcher))))

src/defold/main.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@
6464
(print-json (editor/send-command cmd)))
6565

6666
(defmethod run :launch-neovim
67-
([_ config-file filename]
67+
([_ config-file root-dir filename]
6868
(let [conf (parse-config config-file)]
69-
(launcher/run (get-in conf ["plugin_config" "launcher"]) filename nil)))
70-
([_ config-file filename line]
69+
(launcher/run (get-in conf ["plugin_config" "launcher"]) root-dir filename nil)))
70+
([_ config-file root-dir filename line]
7171
(let [conf (parse-config config-file)]
72-
(launcher/run (get-in conf ["plugin_config" "launcher"]) filename line))))
72+
(launcher/run (get-in conf ["plugin_config" "launcher"]) root-dir filename line))))
7373

7474
(defmethod run :focus-neovim [_ _ root-dir]
7575
(print-json (focus/focus-neovim root-dir)))

0 commit comments

Comments
 (0)