conf-rust.el 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. ;;; Code:
  2. (require 'rust-mode)
  3. (require 'ggtags)
  4. (require 'eglot)
  5. (defun distopico:rust-mode-hook()
  6. "The `rust-mode' hook."
  7. (ggtags-mode 1)
  8. (eglot-ensure))
  9. (defun distopico:try-cargo-toml(dir)
  10. "Find rust workspace root for `project' based in the current `DIR'."
  11. (when-let* (((eq major-mode 'rust-mode))
  12. (output
  13. (let ((default-directory dir))
  14. (shell-command-to-string "cargo metadata --no-deps --format-version 1")))
  15. (json (ignore-errors (json-read-from-string output)))
  16. (found (cdr (assq 'workspace_root json))))
  17. (cons 'transient found)))
  18. (defun distopico:eglot--managed-mode-hook ()
  19. "Hooks for eglot managed-mode to disable `eglot-inlay-hints-mode'."
  20. ;; Too noise for me
  21. (eglot-inlay-hints-mode -1))
  22. ;; Hooks
  23. (add-hook 'rust-mode-hook #'distopico:rust-mode-hook)
  24. (add-hook 'project-find-functions #'distopico:try-cargo-toml)
  25. (add-hook 'eglot-managed-mode-hook #'distopico:eglot--managed-mode-hook)
  26. (provide 'conf-rust)
  27. ;;; conf-rust.el ends here