LefterisJP/malinka

(malinka--rtags-invoke-with "-W" directory)

Closed this issue · 2 comments

Hey,

Was wondering what the -W was intended for in this snippet.

(defun malinka--select-project (directory)
  "Select a malinka project at DIRECTORY.
A compilecommands.json compilation database must already exist there.
This feeds the compilation database to rtags."
  (let ((cdb-file (f-join directory "compile_commands.json")))
  (when (malinka--rtags-assert-rdm-runs)
    (if (f-exists? cdb-file)
        (progn
          (malinka--info "Feeding compile database file: \"%s\" to RTAGS" cdb-file)
          (malinka--rtags-invoke-with "-W" directory)
          (malinka--rtags-invoke-with "-J" directory))
      ;; else
      (malinka-user-error "Could not find a compilation database file in directory %s" directory)))))

I think -W deletes the project from Rtags' cache so this would probably trigger a re-index of the project.

Also noticed

(defun malinka--rtags-invoke-with (&rest args)
  "Invoke rc (rtags executable) with ARGS as arguments.

Returns the output of the command as a string or nil in case of error"
  (when (malinka--rtags-assert-rdm-runs)
    (let* ((rc (rtags-executable-find "rc"))
           (cmd (s-join " " (cons rc args))))
      (when rc
        (shell-command-to-string cmd)))))

I think this will block Emacs if the call takes a while. (I was stalling a bit at some points when this runs.. I think).

Some trace of something I had to C-g out of because Emacs was hanging.

Debugger entered--Lisp error: (quit)
  call-process("/bin/zsh" nil t nil "-c" "/Users/james/.emacs.d/elpa/rtags-20170408.1642/rtags-2.9/bin/rc -W ~/Code/testappworld/cpp/testapp/")
  apply(call-process "/bin/zsh" nil t nil ("-c" "/Users/james/.emacs.d/elpa/rtags-20170408.1642/rtags-2.9/bin/rc -W ~/Code/testappworld/cpp/testapp/"))
  process-file("/bin/zsh" nil t nil "-c" "/Users/james/.emacs.d/elpa/rtags-20170408.1642/rtags-2.9/bin/rc -W ~/Code/testappworld/cpp/testapp/")
  shell-command-to-string("/Users/james/.emacs.d/elpa/rtags-20170408.1642/rtags-2.9/bin/rc -W ~/Code/testappworld/cpp/testapp/")
  (progn (shell-command-to-string cmd))
  (if rc (progn (shell-command-to-string cmd)))
  (let* ((rc (rtags-executable-find "rc")) (cmd (s-join " " (cons rc args)))) (if rc (progn (shell-command-to-string cmd))))
  (progn (let* ((rc (rtags-executable-find "rc")) (cmd (s-join " " (cons rc args)))) (if rc (progn (shell-command-to-string cmd)))))
  (if (malinka--rtags-assert-rdm-runs) (progn (let* ((rc (rtags-executable-find "rc")) (cmd (s-join " " (cons rc args)))) (if rc (progn (shell-command-to-string cmd))))))
  malinka--rtags-invoke-with("-W" "~/Code/testappworld/cpp/testapp/")
  (progn (if malinka-print-info\? (progn (message (concat "Malinka-info: " "Feeding compile database file: \"%s\" to RTAGS") cdb-file))) (malinka--rtags-invoke-with "-W" directory) (malinka--rtags-invoke-with "-J" directory))
  (if (f-exists\? cdb-file) (progn (if malinka-print-info\? (progn (message (concat "Malinka-info: " "Feeding compile database file: \"%s\" to RTAGS") cdb-file))) (malinka--rtags-invoke-with "-W" directory) (malinka--rtags-invoke-with "-J" directory)) (user-error (concat "Malinka-user-error: " "Could not find a compilation database file in directory %s") directory))
  (progn (if (f-exists\? cdb-file) (progn (if malinka-print-info\? (progn (message (concat "Malinka-info: " "Feeding compile database file: \"%s\" to RTAGS") cdb-file))) (malinka--rtags-invoke-with "-W" directory) (malinka--rtags-invoke-with "-J" directory)) (user-error (concat "Malinka-user-error: " "Could not find a compilation database file in directory %s") directory)))
  (if (malinka--rtags-assert-rdm-runs) (progn (if (f-exists\? cdb-file) (progn (if malinka-print-info\? (progn (message (concat "Malinka-info: " "Feeding compile database file: \"%s\" to RTAGS") cdb-file))) (malinka--rtags-invoke-with "-W" directory) (malinka--rtags-invoke-with "-J" directory)) (user-error (concat "Malinka-user-error: " "Could not find a compilation database file in directory %s") directory))))
  (let ((cdb-file (f-join directory "compile_commands.json"))) (if (malinka--rtags-assert-rdm-runs) (progn (if (f-exists\? cdb-file) (progn (if malinka-print-info\? (progn (message ... cdb-file))) (malinka--rtags-invoke-with "-W" directory) (malinka--rtags-invoke-with "-J" directory)) (user-error (concat "Malinka-user-error: " "Could not find a compilation database file in directory %s") directory)))))
  malinka--select-project("~/Code/testappworld/cpp/testapp/")
  (progn (malinka--select-project build-dir))
  (unwind-protect (progn (malinka--select-project build-dir)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (malinka--select-project build-dir)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (malinka--select-project build-dir)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
  (let* ((project-map (process-get process (quote malinka-project-map))) (project-name (malinka--project-name project-map)) (build-dir (malinka--project-build-directory project-map)) (root-dir (malinka--project-root-directory project-map)) (buffer (process-buffer process)) (compile-database (f-join build-dir "compile_commands.json")) (output (save-current-buffer (set-buffer buffer) (save-excursion (goto-char (point-min)) (s-replace "\\\"" "\"" (buffer-string)))))) (malinka--info "Cmake command for \"%s\" finished. Proceeding to process the output" project-name) (kill-buffer buffer) (if (string-equal root-dir build-dir) nil (let ((root-cdb (f-join root-dir "compile_commands.json"))) (if (f-exists\? root-cdb) (progn (f-delete root-cdb))) (f-copy compile-database root-cdb))) (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (malinka--select-project build-dir)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))
  (progn (let* ((project-map (process-get process (quote malinka-project-map))) (project-name (malinka--project-name project-map)) (build-dir (malinka--project-build-directory project-map)) (root-dir (malinka--project-root-directory project-map)) (buffer (process-buffer process)) (compile-database (f-join build-dir "compile_commands.json")) (output (save-current-buffer (set-buffer buffer) (save-excursion (goto-char (point-min)) (s-replace "\\\"" "\"" (buffer-string)))))) (malinka--info "Cmake command for \"%s\" finished. Proceeding to process the output" project-name) (kill-buffer buffer) (if (string-equal root-dir build-dir) nil (let ((root-cdb (f-join root-dir "compile_commands.json"))) (if (f-exists\? root-cdb) (progn (f-delete root-cdb))) (f-copy compile-database root-cdb))) (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (malinka--select-project build-dir)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))))
  (if (memq (process-status process) (quote (signal exit))) (progn (let* ((project-map (process-get process (quote malinka-project-map))) (project-name (malinka--project-name project-map)) (build-dir (malinka--project-build-directory project-map)) (root-dir (malinka--project-root-directory project-map)) (buffer (process-buffer process)) (compile-database (f-join build-dir "compile_commands.json")) (output (save-current-buffer (set-buffer buffer) (save-excursion (goto-char ...) (s-replace "\\\"" "\"" ...))))) (malinka--info "Cmake command for \"%s\" finished. Proceeding to process the output" project-name) (kill-buffer buffer) (if (string-equal root-dir build-dir) nil (let ((root-cdb (f-join root-dir "compile_commands.json"))) (if (f-exists\? root-cdb) (progn (f-delete root-cdb))) (f-copy compile-database root-cdb))) (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (malinka--select-project build-dir)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))))
  malinka--handle-cmake-finish(#<process malinka-cmake-command-testapp> "finished\n")

Tweaking the function a little to something that looks like this works for me (haven't put too~ much testing into it yet).

(defun malinka--select-project (directory)
  "Select a malinka project at DIRECTORY.
A compilecommands.json compilation database must already exist there.
This feeds the compilation database to rtags."
  (let ((cdb-file (f-join directory "compile_commands.json")))
  (when (malinka--rtags-assert-rdm-runs)
    (if (f-exists? cdb-file)
        (progn
          (malinka--info "Feeding compile database file: \"%s\" to RTAGS" cdb-file)
          (if (get-process "rdm")
              (with-current-buffer (get-buffer "*rdm*")
                (rtags-call-rc "-J" directory))
            (with-temp-buffer
              (rtags-call-rc "-J" directory))))
      ;; else
      (malinka-user-error "Could not find a compilation database file in directory %s" directory)))))

What do you think?

BTW: I didn't realize rtags has to quit cleanly for the project to be cached properly.

(rtags-quit-rdm)

Yes you are correct. Malinka was not made to be async while waiting for rtags.

BTW: I didn't realize rtags has to quit cleanly for the project to be cached properly.

Where did you see this?

I'll close this in favor of the pull request.

^I read it somewhere that Rtags doesn't handle an improper kill very well. (I'm not sure how correct that is).