rtags 使用手册

额,其实直接参照 wiki 就可以了

第一步:先下载 cquery 并且编译

$ git clone https://github.com/cquery-project/cquery --single-branch --depth=1
2 $ cd cquery
3 $ git submodule update --init && ./waf configure build

第二步:配置 emacs, 我的 emacs 是用 use-package 管理的

(use-package cquery
  :commands lsp-cquey-enable
  :init
  (setq cquery-executable
        "/home/zmqc/backups/src/cquery/build/release/bin/cquery")
  (add-hook 'c-mode-hook
            '(lambda ()
               (use-package company-lsp
                 :config
                 (setq company-transformers nil company-lsp-async t
                       company-lsp-cache-candidates nil))
               (lsp-cquery-enable)
               (setq cquery--get-init-params
                     '(:index (:comment 2) :cacheFormat "msgpack" :completion (:detailedLabel t)))
               (lsp-common-set))))
(defun lsp-common-set ()
  (use-package lsp-ui
    :config
    (setq lsp-ui-doc-enable nil)
    (setq lsp-ui-sideline-enable nil)
    (lsp-ui-mode)
    (define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references))
  (use-package flycheck
    :bind (:map flycheck-mode-map
                ("M-g l" . flycheck-list-errors))
    :config
    (flycheck-mode))
  (use-package ivy-xref
    :init
    (setq xref-show-xrefs-function #'ivy-xref-show-xrefs))
  (set (make-local-variable 'company-backends)
       '(company-lsp  company-dabbrev-code
                      company-dabbrev
                      company-files))
  (add-hook 'lsp-after-open-hook #'lsp-enable-imenu)
  (global-set-key (kbd "S-<f2>") #'lsp-rename))

我稍微解释一下:
(setq cquery-executable “/home/zmqc/backups/src/cquery/build/release/bin/cquery”) 这行就是设置你第一步编译 cquery 时产生的二进制文件的路径

里面的 (use-package company-lsp) 是配合 company 用来补全的,效果很好,注意其必须在 lsp-cquery-enable 之前被调用

lsp-ui 就是 lsp 的一个 ui 包,目前我主要就用一个 lsp-ui-peek-find-references

就这样吧,有啥问题你在问我好了

对了,使用的时候简单点的方法就是在项目的根目录建立一个 .cquery 文件里面这样子写就可以了

%clang
%c -std=gnu11
%cpp -std=gnu++14

指定包含的头文件位置

%clang
%c -std=gnu11
%cpp -std=gnu++14
-I/usr/include/         #你要加载的头文件的位置
2 个赞

mark, 现在在用 ycmd,以后试试 lsp。

(setq ccls-extra-init-params
        '(
                 :completion (:detailedLabel t)     ;; company-mode顯示內容有所變化
                 :diagnostics (:frequencyMs 5000)      ;; 連續編輯時防止diagnostics反覆變更
                 :index (:initialReparseForDependency :json-false)))     ;; 防止公共.h變更,導致所有dependent .cc reparse

其他cquery-改成ccls-就是ccls的了……

有人試圖給cquery加全局配置~/.config/cquery。不知道你們有什麼看法。對於Emacs用戶,處於實用性考慮projectile不可少,用projectile定位專案根目錄比找.ccls .cquery compile_commands.json準確度高(注意compile_commands.json可以在build目錄中,.ccls可以在子目錄出現)

projectile找不到.git等專案目錄標誌時,默認會用default-directory,有可能會定位到$HOME,導致ccls/cquery索引整個$HOME。這往往是不想要的。我傾向於不在ccls中引入這個。實在需要的話可以在initialization options追加選項(非預設)指向這個~/.config/ccls路徑

对 cmake 不是太熟,请教一个问题,我用的系统是 debian 9,gcc 的最高版本是 6.3, clang 版本是 6,但是我每次编译 ccls 的时候他都是调用的 gcc(然后就是失败),有啥办法指定用 clang 来编译吗(gcc, clang 我都有安装)

Getting started加了一条…

Linux with gcc < 7 but clang >= 5, cmake -H. -Brelease -DCMAKE_CXX_COMPILER=clang++

谢谢,我试一下

请问我能把我的安装经历发上来吗,刚刚安装完,我是用Fedora 28 安装的…rtags。我觉得可以帮助更多的人…

额,我不是楼主啊

不过我觉得楼主应该不会介意的吧😁

哈哈哈,那你编译成功没?

我编译不成功的是 ccls 不是 rtags 啊😂

我知道阿:joy:

对,差不多就是这个,我刚刚重新编译了一下

 -- The CXX compiler identification is Clang 6.0.0
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'Release' as none was specified.
-- Using downloaded Clang
-- Found Curses: /usr/lib/x86_64-linux-gnu/libcurses.so
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8")
-- Clang already downloaded
-- Found Clang: /home/zmqc/backups/src/ccls/release/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/lib/libclang.so (found suitable version "6.0.0", minimum required is
"6.0.0")
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
CMake Error in CMakeLists.txt:
  Target "ccls" requires the language dialect "CXX17" , but CMake does not
  know the compile flags to use to enable it.


-- Generating done
-- Build files have been written to: /home/zmqc/backups/src/ccls/release

这里复制的,哈哈哈,我刚刚在编译其他东西无聊去看的,哈哈哈~ As mentioned is c++17 only supported by cmake version > 3.8, so I had to update it.

恩,感谢,我的 cmake 是 3.7.2

祝你顺利,我在看你的lsp配置,感谢~哈哈哈

恩,谢谢

不客气

lsp-mode可以像rtags一样结合tramp远程索引了吗?

比如:Run lsp-mode in Tramp buffers · Issue #197 · emacs-lsp/lsp-mode · GitHub

想请教一下.ccls就是项目的根目录吗,那么.ccls-root是啥,这个在wiki里没说,之前也装过.cquery,感觉.cquery和.ccls没有作用,但.ccls-root可以

这货会把服务端卡崩溃,代码有bug,越写越卡光标

这里