Search code examples
c++emacsindentation

emacs c++ indent wrong with c-ts-mode and eglot


I'm editing a C++ project in emacs with both c++-ts-mode and eglot(clangd) turned on, and I've noticed that when I finish typing {} and hit enter, this is what happens

enter image description here

my configuration is:

(use-package cc-mode
  :init
  (add-to-list 'auto-mode-alist '("\\.isa\\'" . c++-mode))
  :config
  (setq c-basic-offset 4)
  (c-set-offset 'case-label '+)
  )

(use-package c-ts-mode
  :init
  (add-to-list 'auto-mode-alist '("\\.isa\\'" . c++-ts-mode))
  :config
  (setq c-ts-mode-indent-offset 4)
  (setq c-ts-mode-indent-style 'linux)
  )

(use-package eglot
  ;; :hook ((c-ts-mode c++-ts-mode) . eglot-ensure)
  :bind
  ("C-c l" . hydra-eglot/body)
  :config
  (setq eglot-events-buffer-size 0
        eglot-connect-timeout 10
        eglot-autoshutdown t
        ;; use global completion styles
        completion-category-defaults nil)
  (defhydra hydra-eglot (:color blue :columns 3)
    "Eglot Menu"
    ("f" eglot-format "Format selection")
    ("b" eglot-format-buffer "Format buffer")
    ("r" eglot-rename "Rename symbol at point")
    ("d" eglot-find-declaration "Find declaration")
    ("i" eglot-find-implementation "Find implementation")
    ("t" eglot-find-typeDefinition "Find type definition")
    ("s" eglot-shutdown "Shutdown eglot server")
    ("c" consult-eglot-symbols "Consult Eglot Symbols")
    ("q" nil "Quit" :color blue))
  )

Is there any thing I can do to fix that? Thank you.


Solution

  • Finally I fixed it by forbiddening some lsp function like this:

    (use-package eglot
      :custom
      (eglot-ignored-server-capabilities '(:documentOnTypeFormattingProvider))
    

    I guess the bug was caused by the overlap of the functions of lsp and treesit.

    Is there a way to forbidden treesit function?