fix(cc): ffap in C modes (and ts-modes)

This commit is contained in:
Henrik Lissner
2025-09-29 16:51:19 -04:00
parent c63b207e4f
commit bc9618d744
2 changed files with 11 additions and 5 deletions

View File

@@ -145,17 +145,17 @@ the children of class at point."
"Takes the local project include paths and registers them with ffap. "Takes the local project include paths and registers them with ffap.
This way, `find-file-at-point' (and `+lookup/file') will know where to find most This way, `find-file-at-point' (and `+lookup/file') will know where to find most
header files." header files."
(when-let (project-root (and (featurep 'lsp) (when-let* ((project-root (or (and (fboundp 'lsp-workspace-root)
(or (lsp-workspace-root) (lsp-workspace-root))
(doom-project-root)))) (doom-project-root))))
(require 'ffap) (require 'ffap)
(make-local-variable 'ffap-c-path) (make-local-variable 'ffap-c-path)
(make-local-variable 'ffap-c++-path) (make-local-variable 'ffap-c++-path)
(cl-loop for dir in (or (cdr (assoc project-root +cc--project-includes-alist)) (cl-loop for dir in (or (cdr (assoc project-root +cc--project-includes-alist))
(+cc-resolve-include-paths)) (+cc-resolve-include-paths))
do (add-to-list (pcase major-mode do (add-to-list (pcase major-mode
(`c-mode 'ffap-c-path) ((or `c-mode `c-ts-mode) 'ffap-c-path)
(`c++-mode 'ffap-c++-path)) ((or `c++-mode `c++-ts-mode) 'ffap-c++-path))
(expand-file-name dir project-root))))) (expand-file-name dir project-root)))))

View File

@@ -35,6 +35,12 @@ This is ignored by ccls.")
(set-tree-sitter! 'c++-mode 'c++-ts-mode (set-tree-sitter! 'c++-mode 'c++-ts-mode
'((cpp :url "https://github.com/tree-sitter/tree-sitter-cpp" '((cpp :url "https://github.com/tree-sitter/tree-sitter-cpp"
:rev "v0.23.4")))) :rev "v0.23.4"))))
(after! ffap
(add-to-list 'ffap-alist '(c-mode . ffap-c-mode))
(add-to-list 'ffap-alist '(c-ts-mode . ffap-c-mode))
(add-to-list 'ffap-alist '(c++-ts-mode . ffap-c++-mode)))
:config :config
;; HACK: cc-mode adds null entries to `major-mode-remap-defaults', which ;; HACK: cc-mode adds null entries to `major-mode-remap-defaults', which
;; overrides our tree-sitter remappings, causing the first remap to succeed, ;; overrides our tree-sitter remappings, causing the first remap to succeed,