Skip to content

Commit

Permalink
[Fix bbatsov#1500] Add support for recursive project discovery
Browse files Browse the repository at this point in the history
Extend type of `projectile-project-search-path` to allow elements of
form (DIRECTORY . DEPTH) to discover projects at the specified depth.
  • Loading branch information
juergenhoetzel committed Jun 28, 2021
1 parent 1fbe063 commit 0fc2a1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#1680](https://github.com/bbatsov/projectile/pull/1680): Add support for recursive project discovery
* [#1671](https://github.com/bbatsov/projectile/pull/1671)/[#1679](https://github.com/bbatsov/projectile/pull/1679) Allow the `:test-dir` and `:src-dir` options of a project to be set to functions for more flexible test switching.

### Bugs fixed
Expand Down
36 changes: 22 additions & 14 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,13 @@ When set to nil you'll have always add projects explicitly with
(defcustom projectile-project-search-path nil
"List of folders where projectile is automatically going to look for projects.
You can think of something like $PATH, but for projects instead of executables.
Examples of such paths might be ~/projects, ~/work, etc."
Examples of such paths might be ~/projects, ~/work, (~/github . 1) etc.
For elements of form (DIRECTORY . DEPTH), DIRECTORY has to be a
directory and DEPTH an integer that specifies the depth at which to
look for projects."
:group 'projectile
:type '(repeat directory)
:type '(repeat (choice directory (cons directory (integer :tag "Depth"))))
:package-version '(projectile . "1.0.0"))

(defcustom projectile-git-command "git ls-files -zco --exclude-standard"
Expand Down Expand Up @@ -1017,27 +1021,31 @@ The cache is created both in memory and on the hard drive."
(projectile-invalidate-cache nil)))

;;;###autoload
(defun projectile-discover-projects-in-directory (directory)
(defun projectile-discover-projects-in-directory (directory &optional depth)
"Discover any projects in DIRECTORY and add them to the projectile cache.
This function is not recursive and only adds projects with roots
at the top level of DIRECTORY."
(interactive
(list (read-directory-name "Starting directory: ")))
If DEPTH is non-nil recursively descend exactly DEPTH levels below DIRECTORY and
discover projects there."
(if (file-exists-p directory)
(let ((subdirs (directory-files directory t directory-files-no-dot-files-regexp t)))
(mapc
(lambda (dir)
(when (and (file-directory-p dir) (projectile-project-p dir))
(projectile-add-known-project dir)))
subdirs))
(let ((subdirs (directory-files directory t)))
(dolist (dir subdirs)
(when (and (file-directory-p dir)
(not (member (file-name-nondirectory dir) '(".." "."))))
(if (and (numberp depth) (> depth 0))
(projectile-discover-projects-in-directory dir (1- depth))
(when (projectile-project-p dir)
(projectile-add-known-project dir))))))
(message "Project search path directory %s doesn't exist" directory)))

;;;###autoload
(defun projectile-discover-projects-in-search-path ()
"Discover projects in `projectile-project-search-path'.
Invoked automatically when `projectile-mode' is enabled."
(interactive)
(mapcar #'projectile-discover-projects-in-directory projectile-project-search-path))
(dolist (path projectile-project-search-path)
(if (consp path)
(projectile-discover-projects-in-directory (car path) (cdr path))
(projectile-discover-projects-in-directory path 0))))


(defun delete-file-projectile-remove-from-cache (filename &optional _trash)
Expand Down

0 comments on commit 0fc2a1f

Please sign in to comment.