Skip to content

racer-complete-at-point fails even when $ racer complete use std::io::B works from terminal #134

@deb0ch

Description

@deb0ch

I feel like there is a missed opportunity at emacs-racer working automagically without extra install steps.

From the terminal $ racer complete use std::io::B works just fine, even though I did not explicitly install Rust sources using $ rustup component add rust-src. However, from Emacs I get the following error when trying to complete:

completion--some: No such directory: /usr/local/Cellar/rust/1.34.0/lib/rustlib/src/rust/src. Please set ‘racer-rust-src-path’ or ‘RUST_SRC_PATH’.

My feeling that there is a missed opportunity stems from the fact that, when I remove the check causing this error from racer--call, I get the right completions.

I changed:

(defun racer--call (command &rest args)
  "Call racer command COMMAND with args ARGS.
Return stdout if COMMAND exits normally, otherwise show an
error."
  (let ((rust-src-path (or (when racer-rust-src-path (expand-file-name racer-rust-src-path))
                           (getenv "RUST_SRC_PATH")))
        (cargo-home (or (when racer-cargo-home (expand-file-name racer-cargo-home))
                        (getenv "CARGO_HOME"))))
    (when (null rust-src-path)
      (user-error "You need to set `racer-rust-src-path' or `RUST_SRC_PATH'"))
    (unless (file-exists-p rust-src-path)
      (user-error "No such directory: %s. Please set `racer-rust-src-path' or `RUST_SRC_PATH'"
                  rust-src-path))
    (let ((default-directory (or (racer--cargo-project-root) default-directory))
          (process-environment (append (list
                                        (format "RUST_SRC_PATH=%s" rust-src-path)
                                        (format "CARGO_HOME=%s" cargo-home))
                                       process-environment)))
      (-let [(exit-code stdout _stderr)
             (racer--shell-command racer-cmd (cons command args))]
        ;; Use `equal' instead of `zero' as exit-code can be a string
        ;; "Aborted" if racer crashes.
        (unless (equal 0 exit-code)
          (user-error "%s exited with %s. `M-x racer-debug' for more info"
                      racer-cmd exit-code))
        stdout))))

to:

(defun racer--call (command &rest args)
  "Call racer command COMMAND with args ARGS.
Return stdout if COMMAND exits normally, otherwise show an
error."
  (let ((rust-src-path (or (when racer-rust-src-path (expand-file-name racer-rust-src-path))
                           (getenv "RUST_SRC_PATH")))
        (cargo-home (or (when racer-cargo-home (expand-file-name racer-cargo-home))
                        (getenv "CARGO_HOME"))))
    (let ((default-directory (or (racer--cargo-project-root) default-directory)))
      (-let [(exit-code stdout _stderr)
             (racer--shell-command racer-cmd (cons command args))]
        ;; Use `equal' instead of `zero' as exit-code can be a string
        ;; "Aborted" if racer crashes.
        (unless (equal 0 exit-code)
          (user-error "%s exited with %s. `M-x racer-debug' for more info"
                      racer-cmd exit-code))
        stdout))))

and started getting the right completions when pressing after use std::io::B.

I am not sure what to think about it as I don't have global knowledge about Racer, Emacs-racer, and even about Rust as I am a beginner.

I need insight from someone more experienced with this codebase. Am I right in thinking that there is room for improvement ? If so, how, and would there be tradeoffs ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions