Commit 6234d072 authored by Fangrui Song's avatar Fangrui Song

Make cquery-project-roots a root matcher

parent 12ce064b
......@@ -51,11 +51,13 @@
(defsubst cquery--root-from-func (func)
(and (fboundp func) (ignore-errors (funcall func))))
(cl-defun cquery--get-root ()
"Return the root directory of a cquery project."
(cl-defun cquery-project-roots-matcher ()
(cl-loop for root in cquery-project-roots do
(when (string-prefix-p (expand-file-name root) buffer-file-name)
(cl-return-from cquery--get-root root)))
(cl-return-from cquery--get-root root))))
(cl-defun cquery--get-root ()
"Return the root directory of a cquery project."
(cl-loop for matcher in cquery-project-root-matchers do
(-when-let (root (cl-typecase matcher
(string (cquery--root-from-file matcher))
......
......@@ -86,17 +86,17 @@ Relative to the project root directory."
(defcustom cquery-project-roots
nil
"A list of project roots that will be matched against the source filename first
to get the project root before consulting `cquery-project-root-matchers'.
to get the project root.
This is useful when your project has subprojects. Otherwise `projectile' and
`project' may think the file resides in a subproject and thus the file
does not belong to the current workspace.
This is used by `cquery-project-roots-matcher', useful when your project has
subprojects. Otherwise `projectile' and `project' may think the file resides
in a subproject and thus does not belong to the current workspace.
"
:type '(repeat directory)
:group 'cquery)
(defcustom cquery-project-root-matchers
'(projectile-project-root "compile_commands.json" ".cquery")
'(cquery-project-roots-matcher projectile-project-root "compile_commands.json" ".cquery")
"List of matchers that are used to locate the cquery project roots.
Each matcher is run in order, and the first successful (non-nil) matcher
determines the project root.
......@@ -107,7 +107,7 @@ upwards through the project directory structure and return the first
matching file.
A `function' entry define a callable function that either returns workspace's
root location or `nil' if another matcher should be used instead.
root location or `nil' if subsequent matchers should be used instead.
"
:type '(repeat (choice (file) (function)))
:group 'cquery)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment