Skip to content

Commit

Permalink
find project by rebar.config file
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiw committed Apr 27, 2024
1 parent 5c3cded commit 87babcc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions elisp/edts/edts-project-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@
(lambda (f) nil)))
(edts-project--find-project-root "/foo/bar/baz/bam"))))

(edts-test-case edts-project-suite edts-project--find-rebar-root-test ()
"Tests edts-project--find-project-root"
(should (string= "/foo"
(cl-letf (((symbol-function 'f-exists?)
(lambda (f) (equal f "/foo/rebar.config"))))
(edts-project--find-rebar-root "/foo/bar/baz/bam"))))
(should-not (cl-letf (((symbol-function 'f-exists?)
(lambda (f) nil))
(edts-project--find-rebar-root "/foo/bar/baz/bam")))))

(edts-test-case edts-project-suite edts-project--find-otp-root-test ()
"Tests edts-project--find-project-root"
(should (string= "/foo"
Expand Down Expand Up @@ -98,6 +108,20 @@
(should (equal "project"
(cl-letf (((symbol-function 'edts-project--find-project-root)
(lambda (f) "project"))
((symbol-function 'edts-project--find-rebar-root)
(lambda (f) "rebar"))
((symbol-function 'edts-project--find-otp-root)
(lambda (f) "otp"))
((symbol-function 'edts-project--find-temp-root)
(lambda (f) "temp"))
((symbol-function 'f-this-file)
(lambda () "/foo/bar/baz/src/foo")))
(edts-project--find-root "/foo/bar/baz/src"))))
(should (equal "rebar"
(cl-letf (((symbol-function 'edts-project--find-project-root)
(lambda (f) nil))
((symbol-function 'edts-project--find-rebar-root)
(lambda (f) "rebar"))
((symbol-function 'edts-project--find-otp-root)
(lambda (f) "otp"))
((symbol-function 'edts-project--find-temp-root)
Expand All @@ -108,6 +132,8 @@
(should (equal "otp"
(cl-letf (((symbol-function 'edts-project--find-project-root)
(lambda (f) nil))
((symbol-function 'edts-project--find-rebar-root)
(lambda (f) nil))
((symbol-function 'edts-project--find-otp-root)
(lambda (f) "otp"))
((symbol-function 'edts-project--find-temp-root)
Expand All @@ -118,6 +144,8 @@
(should (equal "temp"
(cl-letf (((symbol-function 'edts-project--find-project-root)
(lambda (f) nil))
((symbol-function 'edts-project--find-rebar-root)
(lambda (f) nil))
((symbol-function 'edts-project--find-otp-root)
(lambda (f) nil))
((symbol-function 'edts-project--find-temp-root)
Expand Down
12 changes: 12 additions & 0 deletions elisp/edts/edts-project.el
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ underneath a project root to be subprojects of that super project.")
(when (f-this-file)
(let ((dir (or dir (f-dirname (f-this-file)))))
(or (edts-project--find-project-root dir)
(edts-project--find-rebar-root dir)
(edts-project--find-otp-root dir)
(edts-project--find-temp-root dir)))))

Expand All @@ -78,6 +79,17 @@ underneath a project root to be subprojects of that super project.")
(setq dir (f-dirname dir))))
root))

(defun edts-project--find-rebar-root (dir)
"Try to find the top-most rebar.config above current buffer's file."
(interactive)
(let (stop root)
(while (and (not stop) (not (f-root? dir)))
(if (f-exists? (f-join dir "rebar.config"))
(setq root dir
stop t)
(setq dir (f-dirname dir))))
root))

(defun edts-project--find-otp-root (dir)
(f-traverse-upwards (lambda (path)
(when (not (f-root? path))
Expand Down

0 comments on commit 87babcc

Please sign in to comment.