emacs-lsp / emacs-ccls

Emacs client for ccls, a C/C++ language server
200 stars 29 forks source link

Is there a way to reload the compile_commands.json? (Especially if one did not exist previously) #55

Closed DougBeney closed 5 years ago

DougBeney commented 5 years ago

I am trying to reload ccls whenever the compile_commands.json file is changed.

Steps to Reproduce:

In this example, I create a really basic Qt5 project. Feel free to reproduce using a library/framework that you are more familiar with.

Step 1.: Create hello.cpp in empty directory with emacs:

#include <QString>
int main() { }

Result so far: flycheck should display an error on line 1. This is expected.

Step 2.: Generate a compile_commands.json and place it in the project root.

MyProject.pro:

QT += core gui widgets
TARGET = hello
SOURCES += hello.cpp

Commands:

mkdir build
cd build
qmake ../MyProject.pro
bear make # This generates the compile_commands.json
cp compile_commands.json ..

Step 3: Attempt to reload/restart lsp (or ccls) so your new compile_commands.json is picked up.

I have tried the Emacs functions lsp-restart-workspace and ccls-reload. I've even tried killing the ccls process to force a restart.

The only solution I have right now is to completely restart emacs.

My lsp config:

(use-package lsp-mode
  :hook ((c-mode
          c++-mode
          javascript-mode
          vue-mode
          css-mode) . lsp)
  :config
  (require 'lsp-clients) ;; Multiple language configurations out of the box
  (use-package ccls) ;; C/C++ language server

  (use-package lsp-ui
    :hook (lsp-mode . lsp-ui-mode)
    :config
    ;; Don't use flymake; we'll use flycheck.
    (setq lsp-prefer-flymake nil))

  (use-package company-lsp
    :init
    (push 'company-lsp company-backends)))
DougBeney commented 5 years ago

I'm not sure what I did, differently, but it works fine now. My latest config is above. Will re-open if the issue comes up again and is reproducible.

MaskRay commented 5 years ago

https://github.com/MaskRay/ccls/wiki/FAQ#reload