Unreal项目生成compile_commands.json

linux要改到unreal目录下的build.sh的路径。

补全和错误检查正常工作。 image

(defun my-project-root ()
  "Return project root by `project'"
  (car (last (project-current))))

(defun pas-extract-last-directory (path)
  "Extract the last directory name between the last two slashes in PATH."
  (let ((regex "\\([^/]+\\)/$"))
    (when (string-match regex path)
      (match-string 1 path))))

;; no pop up
(add-to-list 'display-buffer-alist
  (cons "\\*Async Shell Command\\*.*" (cons #'display-buffer-no-window nil)))

(setq unreal-dir "C:/Program Files/Unreal/UE_5.4")

(defun pas-cp-ue-compilecommands-json (process signal)
  (when (memq (process-status process) '(exit signal))
	(let ((default-directory (my-project-root)))
	  (eshell-command(format "cp \"%s/compile_commands.json\" ./compile_commands.json" unreal-dir)))
	  )
	(shell-command-sentinel process signal)))

(defun pas-unreal-generate-compilecommands ()
  (interactive)
  (let* ((output-buffer-name "*Async Shell Command*")
		 (output-buffer
		  (if (get-buffer output-buffer-name)
			  (get-buffer output-buffer-name)
			(generate-new-buffer output-buffer-name)
			))
		 (project-dir (my-project-root))
		 (project-name (pas-extract-last-directory project-dir))
		 (proc (progn
				 (async-shell-command (format "\"%s/Engine/Binaries/DotNET/AutomationTool/UnrealBuildTool.exe\" -project=\"%s%s.uproject\" -mode=GenerateClangDatabase -NoExecCodeGenActions -game -engine -target=UnrealEditor Development Win64 " unreal-dir project-dir project-name) output-buffer)
				 (get-buffer-process output-buffer))))

	(if (process-live-p proc)
		(set-process-sentinel proc #'pas-cp-ue-compilecommands-json)
	  (message "No process running."))
	)
  )