Skip to content

Commit

Permalink
Use project top-level for lsp-mode workspace root (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
bustercopley authored Apr 20, 2024
1 parent ac07247 commit 2eccb30
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lean4-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,21 @@ enabled and disabled respectively.")

(defun lean4-create-lsp-workspace ()
"Create an LSP workspace.
This will allow us to use Emacs when a repo contains multiple lean packages."
(when-let ((file-name (buffer-file-name))
(root (vc-find-root (buffer-file-name)
"lakefile.lean")))
(lsp-workspace-folders-add root)))
Starting from `(buffer-file-name)`, repeatedly look up the
directory hierarchy for a directory containing a file
\"lakefile.lean\", and use the last such directory found, if any.
This allows us to edit files in child packages using the settings
of the parent project."
(let (root)
(when-let ((file-name (buffer-file-name)))
(while-let ((dir (locate-dominating-file file-name "lakefile.lean")))
;; We found a lakefile, but maybe it belongs to a package.
;; Continue looking until there are no more lakefiles.
(setq root dir
file-name (file-name-directory (directory-file-name dir)))))
(when root
(lsp-workspace-folders-add root))))

;; Automode List
;;;###autoload
Expand Down

0 comments on commit 2eccb30

Please sign in to comment.