LoginSignup
5
2

More than 5 years have passed since last update.

[Emacs] eglot + ccls

Last updated at Posted at 2019-03-04

ここに公式ドキュメント以上の情報はない。ただの備忘録。

C/C++/Objective-CのLanguage ServerであるcclsをEmacsから使ってみた。
問題なく動くようであればrtagsからおさらばとなるかも。

ビルド

$ git clone https://github.com/MaskRay/ccls.git
$ cd ccls
$ mkdir build
$ cd build
$ cmake --config Release --target install .. -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7
$ make
$ sudo make install

Emacs設定

私はLSPクライアントとしてeglotを使っているので以下のように設定。(lsp-modeを使うという手もある)

(use-package projectile
  :config
  (defun projectile-project-find-function (dir)
    (let* ((root (projectile-project-root dir)))
      (and root (cons 'transient root))))
  (with-eval-after-load 'project
    (add-to-list 'project-find-functions 'projectile-project-find-function))
  )

(use-package eglot
  :bind (:map eglot-mode-map
              ("C-c C-d" . eglot-help-at-point)
              ("C-c C-r" . eglot-code-actions))
  :hook
  ((c-mode-common . eglot-ensure))
  )

いい感じにプロジェクトのルートを探してくれるprojectileを使用している。
手動でルートを設定したいときには空の.projectileファイルを置く。

プロジェクト設定

cmakeを使用している場合は-DCMAKE_EXPORT_COMPILE_COMMANDS=1でcompile_commands.jsonを作成し、プロジェクト直下にシンボリックリンクを張る。

その他の方法は公式ドキュメント参照のこと。
https://github.com/MaskRay/ccls/wiki/Project-Setup

操作

定義参照等はxref系コマンドが使用可能。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2