@@ -1986,21 +1986,29 @@ want to watch."
1986
1986
(not (lsp--string-match-any ignored-directories full-path)))))
1987
1987
1988
1988
1989
- (defun lsp--all-watchable-directories (dir ignored-directories)
1989
+ (defun lsp--all-watchable-directories (dir ignored-directories &optional visited )
1990
1990
"Traverse DIR recursively returning a list of paths that should have watchers.
1991
- IGNORED-DIRECTORIES will be used for exclusions"
1991
+ IGNORED-DIRECTORIES will be used for exclusions.
1992
+ VISITED is used to track already-visited directories to avoid infinite loops."
1992
1993
(let* ((dir (if (f-symlink? dir)
1993
1994
(file-truename dir)
1994
- dir)))
1995
- (apply #'nconc
1996
- ;; the directory itself is assumed to be part of the set
1997
- (list dir)
1998
- ;; collect all subdirectories that are watchable
1999
- (-map
2000
- (lambda (path) (lsp--all-watchable-directories (f-join dir path) ignored-directories))
2001
- ;; but only look at subdirectories that are watchable
2002
- (-filter (lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories))
2003
- (directory-files dir))))))
1995
+ dir))
1996
+ ;; Initialize visited directories if not provided
1997
+ (visited (or visited (make-hash-table :test 'equal))))
1998
+ (if (gethash dir visited)
1999
+ ;; If the directory has already been visited, skip it
2000
+ nil
2001
+ ;; Mark the current directory as visited
2002
+ (puthash dir t visited)
2003
+ (apply #'nconc
2004
+ ;; the directory itself is assumed to be part of the set
2005
+ (list dir)
2006
+ ;; collect all subdirectories that are watchable
2007
+ (-map
2008
+ (lambda (path) (lsp--all-watchable-directories (f-join dir path) ignored-directories visited))
2009
+ ;; but only look at subdirectories that are watchable
2010
+ (-filter (lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories))
2011
+ (directory-files dir)))))))
2004
2012
2005
2013
(defun lsp-watch-root-folder (dir callback ignored-files ignored-directories &optional watch warn-big-repo?)
2006
2014
"Create recursive file notification watch in DIR.
0 commit comments