Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use project top-level for lsp-mode workspace root #48

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading