From 87babcc888053aa249ea050b876a77766919dff4 Mon Sep 17 00:00:00 2001 From: Sebastian Weddmark Olsson Date: Sat, 27 Apr 2024 14:13:29 +0200 Subject: [PATCH] find project by rebar.config file --- elisp/edts/edts-project-test.el | 28 ++++++++++++++++++++++++++++ elisp/edts/edts-project.el | 12 ++++++++++++ 2 files changed, 40 insertions(+) diff --git a/elisp/edts/edts-project-test.el b/elisp/edts/edts-project-test.el index 0ae6b815..1d85870a 100644 --- a/elisp/edts/edts-project-test.el +++ b/elisp/edts/edts-project-test.el @@ -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" @@ -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) @@ -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) @@ -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) diff --git a/elisp/edts/edts-project.el b/elisp/edts/edts-project.el index 6c551d29..6bef0266 100644 --- a/elisp/edts/edts-project.el +++ b/elisp/edts/edts-project.el @@ -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))))) @@ -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))