Add support for clangd for c languages in emacs.

This commit is contained in:
Tom Alexander 2024-06-02 12:09:45 -04:00
parent e469ed8b9a
commit c36568462f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
9 changed files with 65 additions and 9 deletions

View File

@ -1,6 +1,6 @@
- name: Install packages
package:
name:
- py39-ansible
- py311-ansible
- ansible-sshjail
state: present

View File

@ -1,3 +1,8 @@
.idea
.python-version
# Emacs per-directory settings
.dir-locals.el
# C/C++ Language Server compile commands
compile_commands.json

View File

@ -0,0 +1,49 @@
(require 'common-lsp)
(require 'util-tree-sitter)
(defun locate-compile-commands-file ()
"See if compile_commands.json exists."
;; This can be generated by prefixing the make command with `intercept-build15 --append`
(let ((compile-commands-file (locate-dominating-file (buffer-file-name) "compile_commands.json")))
compile-commands-file
)
)
(defun activate-c-eglot ()
"Activate eglot for the c family of languages."
(when (locate-compile-commands-file)
(eglot-ensure)
(defclass my/eglot-c (eglot-lsp-server) ()
:documentation
"Own eglot server class.")
(add-to-list 'eglot-server-programs
'(c-ts-mode . (my/eglot-c "/usr/local/bin/clangd15")))
(add-hook 'before-save-hook 'eglot-format-buffer nil 'local)
)
)
(use-package c-mode
:mode (
("\\.c\\'" . c-ts-mode)
("\\.h\\'" . c-or-c++-ts-mode)
)
:commands (c-mode c-ts-mode)
:pin manual
:ensure nil
:hook (
(c-ts-mode . (lambda ()
(activate-c-eglot)
))
)
:init
(add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode))
(add-to-list 'major-mode-remap-alist '(c++-mode . c++-ts-mode))
(add-to-list 'major-mode-remap-alist '(c-or-c++-mode . c-or-c++-ts-mode))
(add-to-list 'treesit-language-source-alist '(c "https://github.com/tree-sitter/tree-sitter-c"))
(add-to-list 'treesit-language-source-alist '(cpp "https://github.com/tree-sitter/tree-sitter-cpp"))
(unless (treesit-ready-p 'c) (treesit-install-language-grammar 'c))
(unless (treesit-ready-p 'cpp) (treesit-install-language-grammar 'cpp))
)
(provide 'lang-c)

View File

@ -57,7 +57,7 @@
:init
(add-to-list 'major-mode-remap-alist '(rust-mode . rust-ts-mode))
(add-to-list 'treesit-language-source-alist '(rust "https://github.com/tree-sitter/tree-sitter-rust"))
(unless (treesit-ready-p 'yaml) (treesit-install-language-grammar 'rust))
(unless (treesit-ready-p 'rust) (treesit-install-language-grammar 'rust))
:config
;; Add keybindings for interacting with Cargo
(use-package cargo

View File

@ -32,4 +32,6 @@
(require 'lang-dockerfile)
(require 'lang-c)
(load-directory autoload-directory)

View File

@ -16,20 +16,20 @@
when: 'emacs_flavor == "full"'
package:
name:
- py39-pygments
- py311-pygments
- inkscape # to support SVGs in LaTeX
# - prettier # typescript formatting
- aspell
- en-aspell
- unzip # for extracting mspyls
- py39-isort
- py39-black
- py311-isort
- py311-black
- zip # for odt export from org-mode
- gnuplot # used for exporting graphs from org-mode
# - pyright
- sqlite3 # for sqlite code blocks in org-mode
# - terraform-ls # Terraform language server
- py39-ptvsd
- py311-ptvsd
- hs-ShellCheck
# - gopls
state: present

View File

@ -1,5 +1,5 @@
- name: Install packages
package:
name:
- py39-yamllint
- py311-yamllint
state: present

View File

@ -3,7 +3,7 @@
package:
name:
- zsh
- py39-jmespath # Needed on machine running ansible for json_query
- py311-jmespath # Needed on machine running ansible for json_query
state: present
- name: Install packages

View File

@ -4,7 +4,7 @@
- zsh
- sqlite3
- git
- py39-jmespath # Needed on machine running ansible for json_query
- py311-jmespath # Needed on machine running ansible for json_query
state: present
- include_tasks: