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

cache directory is no longer relative to project root #56

Open
brucestephens opened this issue Dec 5, 2018 · 3 comments
Open

cache directory is no longer relative to project root #56

brucestephens opened this issue Dec 5, 2018 · 3 comments

Comments

@brucestephens
Copy link
Contributor

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
Copy link

kiwonum commented Dec 10, 2018

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
Copy link

rcoacci commented Dec 27, 2018

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
Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants