Commit ca21ea43 authored by Fangrui Song's avatar Fangrui Song

Use cquery-project-roots, projectile-project-root to detect project root

parent 6db9b2d1
......@@ -47,11 +47,16 @@
(cons (lsp--position-to-point (gethash "start" range))
(lsp--position-to-point (gethash "end" range))))
(defun cquery--get-root ()
(cl-defun cquery--get-root ()
"Return the root directory of a cquery project."
(expand-file-name (or (locate-dominating-file default-directory "compile_commands.json")
(locate-dominating-file default-directory ".cquery")
(user-error "Could not find cquery project root"))))
(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)))
(or
(and (require 'projectile nil t) (projectile-project-root))
(expand-file-name (or (locate-dominating-file default-directory "compile_commands.json")
(locate-dominating-file default-directory ".cquery")
(user-error "Could not find cquery project root")))))
(defun cquery--is-cquery-buffer(&optional buffer)
"Return non-nil if current buffer is using the cquery client"
......
......@@ -268,7 +268,7 @@ If nil, disable semantic highlighting."
(append
(--map-indexed
`(defface ,(intern (format "cquery-sem-%s-face-%S" kind it-index))
'((t :foreground ,it)) ".")
'((t :foreground ,it)) "." :group 'cquery)
(symbol-value colors))
(list
`(setq ,(intern (format "cquery-sem-%s-faces" kind))
......
......@@ -71,6 +71,18 @@ Relative to the project root directory."
:type '(repeat string)
:group 'cquery)
(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 `projectile' or `project'.
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.
"
:type '(repeat directory)
:group 'cquery)
;; ---------------------------------------------------------------------
;; Other cquery-specific methods
;; ---------------------------------------------------------------------
......
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