Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
deb0ch opened this issue Mar 1, 2020 · 0 comments

Comments

@deb0ch
Copy link

deb0ch commented Mar 1, 2020

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant