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,8 +145,8 @@ the children of class at point."
"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
header files."
(when-let (project-root (and (featurep 'lsp)
(or (lsp-workspace-root)
(when-let* ((project-root (or (and (fboundp 'lsp-workspace-root)
(lsp-workspace-root))
(doom-project-root))))
(require 'ffap)
(make-local-variable 'ffap-c-path)
@@ -154,8 +154,8 @@ header files."
(cl-loop for dir in (or (cdr (assoc project-root +cc--project-includes-alist))
(+cc-resolve-include-paths))
do (add-to-list (pcase major-mode
(`c-mode 'ffap-c-path)
(`c++-mode 'ffap-c++-path))
((or `c-mode `c-ts-mode) 'ffap-c-path)
((or `c++-mode `c++-ts-mode) 'ffap-c++-path))
(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
'((cpp :url "https://github.com/tree-sitter/tree-sitter-cpp"
: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
;; HACK: cc-mode adds null entries to `major-mode-remap-defaults', which
;; overrides our tree-sitter remappings, causing the first remap to succeed,