emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/beardbolt 33c687fae5 151/323: Implement helpers for com


From: ELPA Syncer
Subject: [elpa] externals/beardbolt 33c687fae5 151/323: Implement helpers for compile_commands parsing
Date: Thu, 9 Mar 2023 10:58:26 -0500 (EST)

branch: externals/beardbolt
commit 33c687fae541fdd88df19af6e422bc0ba166dc24
Author: Jay Kamat <jaygkamat@gmail.com>
Commit: Jay Kamat <jaygkamat@gmail.com>

    Implement helpers for compile_commands parsing
---
 rmsbolt.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/rmsbolt.el b/rmsbolt.el
index 8e50fd3b84..04062ee9f9 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -72,6 +72,7 @@
 (require 'cc-defs)
 (require 'compile)
 (require 'disass)
+(require 'json)
 
 (require 'rmsbolt-java)
 
@@ -626,6 +627,34 @@ https://github.com/derickr/vld";
           (and (1+ (1+ lower) (opt (or "64" "32" "8" "16")) (opt "_"))))
       eol))
 
+;;;;; Language Integrations
+(defun rmsbolt--parse-compile-commands (comp-cmds file)
+  "Parse COMP-CMDS and extract a compilation dir and command for FILE."
+  (when-let* ((json-object-type 'alist)
+              (json-array-type 'vector)
+              (cmds (json-read-file comp-cmds))
+              (stripped-file (file-name-nondirectory file))
+              (entry (cl-find-if
+                      (lambda (elt)
+                        (string=
+                         stripped-file
+                         (file-name-nondirectory
+                          (alist-get 'file elt ""))))
+                      cmds))
+              (dir (alist-get 'directory entry))
+              (cmd (alist-get 'command entry)))
+    (list dir cmd)))
+(defun rmsbolt--default-c-compile-cmd (src-buffer)
+  "Handle compile_commands.json for c/c++ for a given SRC-BUFFER."
+  (when-let* ((ccj "compile_commands.json")
+              (compile-cmd-file
+               (locate-dominating-file
+                (buffer-file-name src-buffer)
+                ccj))
+              (compile-cmd-file (expand-file-name ccj compile-cmd-file))
+              (to-ret (rmsbolt--parse-compile-commands
+                       compile-cmd-file (buffer-file-name src-buffer))))
+    to-ret))
 ;;;; Language Definitions
 (defvar rmsbolt-languages)
 (setq



reply via email to

[Prev in Thread] Current Thread [Next in Thread]