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

cquery-use-default-rainbow-sem-highlight and non indexed projects #3

Closed kvaneesh closed 6 years ago

kvaneesh commented 6 years ago

I have projects that don't have compile_commands.json present. Should I expect the semantic high light to impact display of the code there? Below is the two snapshots of the same file with cquery enabled and disabled. Left side frame is with cquery enabled and right side frame is with cquery disabled.

screenshot from 2018-01-22 19-02-20

MaskRay commented 6 years ago

It shouldn't impact invalid region. Does cross reference (definition,references,$cquery/vars,...) work in the buffer? Are these checklist items satisfied?

The LSP rootUri is now decided by the following function:

(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")
                        default-directory)))

It may work in project roots where neither compile_commands.json nor .cquery is found. But i'm unclear if this is robust enough.

kvaneesh commented 6 years ago

I was expecting cquery to not do anything if it doesn't find compile_commands.json. That is those #ifdef CONFIG_NUMA I want it to render as on the right side frame.

MaskRay commented 6 years ago

Sorry I don't quite get your point.

kvaneesh commented 6 years ago

So now I am calling lsp-cquery-enable in the c-mode-hook . and I also have cquery-use-default-rainbow-sem-highlight in the :config part of use-package macro. The below is what I do to get it configured.

(defun lsp-cquery/init-cquery () (use-package cquery :init (progn (spacemacs/add-to-hooks #'lsp-cquery-enable '(c-mode-hook c++-mode-hook)) (dolist (mode '(c-mode c++-mode)) (evil-leader/set-key-for-mode mode "r." 'xref-find-definitions "r," 'xref-find-references "rs" 'xref-pop-marker-stack "rl" 'helm-imenu ))) :config (progn (setq cquery-executable "/abc/cquery/bin/cquery") (cquery-use-default-rainbow-sem-highlight)) ))

My expectation was if the project root doesn't have compile_commands.json cquery should not introduce any change because it clearly doesn't have enough info to parse the file. Is that assumption wrong? If so how I should configure cquery on different projects, some having compile_commands.json and some not.

For projects without compile_commands.json I am using gtags for symbol lookup and references.

MaskRay commented 6 years ago

I recommend you to check out https://github.com/jacobdufault/cquery/wiki/Emacs , 'xref-pop-marker-stack is actually very bad and should be replaced with lsp-ui-peek-jump-{backward,forward}

Some recent commits in cquery make it able to handle a single file without .cquery or compile_commands.json. I think it is quite handy so I removed user-error from cquery--get-root when these marker files are not found.

Adding lsp-cquery-enable unconditionally to c-mode-hook is a bad idea. I'm thinking adding a cquery layer after https://github.com/syl20bnr/spacemacs/pull/10211 is checked in.

Filed https://github.com/emacs-lsp/lsp-mode/issues/255 , which may be related.

MaskRay commented 6 years ago

https://github.com/syl20bnr/spacemacs/pull/10236

cquery-project-blacklist might be handy

MaskRay commented 6 years ago

I've also sent out a patch to make lsp-project-whitelist lsp-project-blacklist flexible so you can have regex patterns to exclude (say whole /tmp/.*)

https://github.com/emacs-lsp/lsp-mode/pull/256