cquery-project / emacs-cquery

Emacs client for cquery, a low-latency language server supporting multi-million line C++ code-bases
116 stars 14 forks source link

cache directory is no longer relative to project root #56

Open brucestephens opened 5 years ago

brucestephens commented 5 years ago

Before the very recent change (to use the new lsp API), .cquery_cached_index was put in the project root. Now it ends up in the directory containing the first file you edit, which is surely unintended (though will work OK if you have all source files in one directory).

(The problem is presumably cquery--get-init-params using default-directory. I can get my expected behaviour by setting cquery-cache-dir-function to a suitable find-project-root function.)

kiwonum commented 5 years ago

Right, I also had a similar issue. A quick fix, which I have now, is to add the following hack into your init file.

(eval-after-load "cquery"
  '(defun cquery--get-init-params ()
     `(,@cquery-extra-init-params
       :cacheDirectory ,(file-name-as-directory
             (funcall cquery-cache-dir-function (lsp--suggest-project-root)))
       :highlight (:enabled ,(or (and cquery-sem-highlight-method t) :json-false))
       :emitInactiveRegions ,(or cquery-enable-inactive-region :json-false))))
rcoacci commented 5 years ago

Before the very recent change (to use the new lsp API), .cquery_cached_index was put in the project root. Now it ends up in the directory containing the first file you edit, which is surely unintended (though will work OK if you have all source files in one directory).

(The problem is presumably cquery--get-init-params using default-directory. I can get my expected behaviour by setting cquery-cache-dir-function to a suitable find-project-root function.)

Can you share your workaround?

brucestephens commented 5 years ago

Can you share your workaround?

Something like this:

(defun cquery-root ()
  (let ((root (cquery--get-root))
        (isroot nil))
    (cond (root
           (dolist (f '("compile_commands.json" "build/compile_commands.json"))
             (setq isroot (or isroot (file-exists-p (expand-file-name f root)))))))
    (if isroot
        root
      nil)))

(defun cquery-cache-dir (dir)
  (expand-file-name cquery-cache-dir (cquery-root)))
(setq cquery-cache-dir-function #'cquery-cache-dir)