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

Completion doesn't work #27

Closed
nlamirault opened this issue Jun 16, 2016 · 23 comments
Closed

Completion doesn't work #27

nlamirault opened this issue Jun 16, 2016 · 23 comments

Comments

@nlamirault
Copy link

Hi
i try to configure Emacs for rust :

(use-package rust-mode
    :mode (("\\.rs\\'" . rust-mode))
    :config (setq tab-width 4))

  (use-package racer
    :init (progn
            (setq racer-rust-src-path (getenv "RUST_SRC_PATH"))
            (setq racer-cmd (executable-find "racer")))
    :config (progn
              (add-hook 'rust-mode-hook #'racer-mode)
              (add-hook 'rust-mode-hook #'company-mode)
              (add-hook 'racer-mode-hook #'eldoc-mode)
              (add-hook 'rust-mode-hook
                        '(lambda ()
                           (local-set-key (kbd "M-.") #'racer-find-definition)
                           (local-set-key (kbd "TAB") #'company-indent-or-complete-common)))))

I press TAB after use std::io::B, i've got into minubuffer: No completion found

Variable racer-rust-src-path is correctly set.
i try the shell command, it works :

M-x shell-command RET racer complete std::io::B
MATCH BufReader,48,11,/home/nlamirault/Apps/rust/src/libstd/io/buffered.rs,Struct,pub struct BufReader<R>
MATCH BufWriter,300,11,/home/nlamirault/Apps/rust/src/libstd/io/buffered.rs,Struct,pub struct BufWriter<W: Write>
MATCH BufRead,1200,10,/home/nlamirault/Apps/rust/src/libstd/io/mod.rs,Trait,pub trait BufRead: Read
MATCH Bytes,1528,11,/home/nlamirault/Apps/rust/src/libstd/io/mod.rs,Struct,pub struct Bytes<R>

Any idea why it doesn't work ?

@doppioslash
Copy link

doppioslash commented Jul 26, 2016

Same for me, Os X 10.10.5, emacs 24.5.1, with .emacs:

(add-hook 'rust-mode-hook 'cargo-minor-mode)

(add-hook 'rust-mode-hook
          (lambda ()
            (local-set-key (kbd "C-c <tab>") #'rust-format-buffer)))

(setq racer-cmd "~/.cargo/bin/racer") ;; Rustup binaries PATH
(setq racer-rust-src-path (getenv "RUST_SRC_PATH"))

(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'company-mode)

(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
(setq company-tooltip-align-annotations t)

(add-hook 'flycheck-mode-hook #'flycheck-rust-setup)

@kovrik
Copy link

kovrik commented Aug 4, 2016

Same for me, doesn't work from Emacs, but works from CLI.
OSX 10.11.6, Emacs 25.0.50.1, racer 1.2.10

@doppioslash
Copy link

doppioslash commented Aug 4, 2016

Eventually I managed to make it work by fiddling with the config:

(add-hook 'rust-mode-hook
          '(lambda ()
             (setq tab-width 2)
             (setq racer-cmd (concat (getenv "HOME") "/.cargo/bin/racer")) ;; Rustup binaries PATH
             (setq racer-rust-src-path (concat (getenv "HOME") "/.rust/rust/src"))
             (setq company-tooltip-align-annotations t)
         (add-hook 'rust-mode-hook #'racer-mode)
             (add-hook 'racer-mode-hook #'eldoc-mode)
             (add-hook 'racer-mode-hook #'company-mode)
             (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)
         (add-hook 'rust-mode-hook 'cargo-minor-mode)
             (local-set-key (kbd "TAB") #'company-indent-or-complete-common)
             (local-set-key (kbd "C-c <tab>") #'rust-format-buffer)))

My hypothesis is that it wasn't getting the rust src directory with the old conf.

@kovrik
Copy link

kovrik commented Aug 4, 2016

Didn't work for me.
I can see that it gets correct racer-rust-src-path.
The error occurs during completion:

Company: An error occurred in auto-begin
Company: backend company-capf error "Wrong type argument: stringp, nil" with args (candidates std)
eldoc error: (wrong-type-argument stringp nil)

@kovrik
Copy link

kovrik commented Aug 4, 2016

Doesn't work on Windows either (same error, racer from CLI works though).

Config:

(use-package racer
  :config (progn
            (setq racer-cmd (expand-file-name "~/.cargo/bin/racer") 
                  racer-rust-src-path (expand-file-name "~/git/rust/src/")
                  company-tooltip-align-annotations t)
            (add-hook 'rust-mode-hook #'racer-mode)
            (add-hook 'racer-mode-hook #'eldoc-mode)
            (add-hook 'racer-mode-hook #'company-mode)
            (define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)))

@adasfan
Copy link

adasfan commented Aug 5, 2016

I don't get an error but just the message "no completion found". I am using the copy of @doppioslash 's latest post. I can see the racer-rust-src-path variable is set correctly. Any ideas?

@kovrik
Copy link

kovrik commented Aug 7, 2016

Finally, I've just installed Rust plugin for Intellij (https://github.com/intellij-rust/intellij-rust) and it works fine (not perfect, but at least it works).
emacs-racer looks a bit abandoned...

@wmealing
Copy link

i'm also getting this issue, I think I upgraded from emacs 24 to 25, now see it.. no extra messages in debug window.

@ane
Copy link
Member

ane commented Aug 12, 2016

Works fine here on Emacs 25.1 and master of emacs-racer and racer, compiled using Rust 1.10. What versions are you using?

FWIW, this is my config:

(setq racer-cmd "~/.cargo/bin/racer")
(setq racer-rust-src-path "~/Downloads/rustc-1.10.0/src")

(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'company-mode)

@wmealing
Copy link

wmealing commented Aug 12, 2016

I've just checked out emacs head.. as I thought it might have been that.

Emacs : 25.1.90
emacs-racer: racer-20160720.1416 (also tried master)
racer: racer 1.2.10
rustc 1.10.0 (cfcb716cf 2016-07-03)

@wmealing
Copy link

removed ~/.emacs.d/ restarted emacs, followed instructions as per readme.md and still no completion..

@wmealing
Copy link

Gday Ane,

After spending a few nights trying to diagnose what is gone wrong, my patience has worn thin and I have decided to pursue other matters. I have too much muscle memory to abandon emacs and it looks like I can't get emacs to work as an IDE how I would expect.

Thanks for your time in helping me.

@kovrik
Copy link

kovrik commented Aug 16, 2016

Well, it is sort of working for me now.

.zshrc:

# Rust
export PATH=${PATH}:~/.cargo/bin
export PATH=${PATH}:/usr/local/Cellar/rust/1.10.0/bin
export RUST_SRC_PATH=~/.cargo/rust-1.10.0/src

Config:

(use-package racer
  :config (progn
            (setq company-tooltip-align-annotations t ;
                  racer-cmd (expand-file-name "~/.cargo/bin/racer") 
                  racer-rust-src-path (expand-file-name (getenv "RUST_SRC_PATH")))
            (add-hook 'rust-mode-hook  #'racer-mode)
            (add-hook 'racer-mode-hook #'eldoc-mode)
            (add-hook 'racer-mode-hook #'company-mode)))

Now I don't get error messages, but I also can't say that it is very useful:

  • it does complete use std:: statement
  • it does complete variable names used
  • but it does not complete anything else:

printl<tab> - nothing (expected: println!). Is that because println! is a macro?
le<tab> - nothing (expected: let)
whi<tab> - nothing (expected: while)
and so on.

So, basically, nothing apart from use statements and var names. Not very useful.
Not sure if that is a racer issue or this plugin's.

Still using Intellij IDEA Plugin.

@ane
Copy link
Member

ane commented Aug 16, 2016

Hm. I'm trying to figure out what everyone has in common here, could it be OSX? I'll need to find a OSX machine to test this on in that case (I'm on Fedora 24 myself).

@kovrik
Copy link

kovrik commented Aug 16, 2016

@ane
Yes, most probably that is OSX-specific issue.
And I think it is not with emacs-racer package, but with racer itself.
Should racer complete, for example, printl to println! from command line (racer complete printl)?

UPD:

Yeah, looks like racer can't complete macros from std (https://doc.rust-lang.org/std/index.html#macros).
And it doesn't support type inference:

  let v1: Vec<T> = vec![1, 2, 3];
  let v2 = vec![1, 2, 3];

  v1.as_<tab>  // completion works fine
  v2.as_<tab>  // no completion :(

See:
racer-rust/racer#310
racer-rust/racer#304

Which is weird and sad, honestly.

@wmealing
Copy link

I'm not sure what changed, however now its autocompleting use std::io:B as one would expect.. I can't talk for macros.. but at least this part works now.

  • Emacs : 25.1.90
  • racer 20160812.2308
  • racer: 1.2.10
  • rust-mode 20160726.720
  • rustc 1.10.0 (cfcb716cf 2016-07-03)

(require 'flymake-rust)
(add-hook 'rust-mode-hook 'flymake-rust-load)

;; If you want to use rustc compiler, you must add following string:
(setq flymake-rust-use-cargo 1)

(setq racer-rust-src-path "/.cargo/rust/src/")
(setq racer-cmd "
/.cargo/bin/racer")

(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'company-mode)

(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
(setq company-tooltip-align-annotations t)

Wilfred added a commit that referenced this issue Aug 27, 2016
@Wilfred
Copy link
Member

Wilfred commented Aug 27, 2016

I'm closing this, as most users have reported successful completion.

macros: this is a known limitation of racer, and racer.el can't do anything about it I'm afraid. I've added a note in the readme about this.

The readme now states what we complete. I think @kovrik was expecting keyword completion too -- this would belong in the company-keywords backend.

If you're not getting completion for use std::io::B, feel free to respond or (preferably) open a new issue.

@Wilfred Wilfred closed this as completed Aug 27, 2016
@Wilfred
Copy link
Member

Wilfred commented Aug 27, 2016

I've opened a PR on company-keywords to add rust support.

I think #27 (comment) is a duplicate of #33.

@bsed
Copy link

bsed commented May 29, 2017

oh, i have same problem

@SerialDev
Copy link

Minor modification based on doppioslash's reply

(add-hook 'rust-mode-hook
          '(lambda ()
             (setq tab-width 2)
             (setq racer-cmd (concat (getenv "HOME") "/cargo/bin/racer")) ;; Rustup binaries PATH
             (setq racer-rust-src-path (concat (getenv "HOME") (shell-command-to-string "echo `rustc --print sysroot`/lib/rustlib/src/rust/src")))
             (setq company-tooltip-align-annotations t)
         (add-hook 'rust-mode-hook #'racer-mode)
             (add-hook 'racer-mode-hook #'eldoc-mode)
             (add-hook 'racer-mode-hook #'company-mode)
             (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)
         (add-hook 'rust-mode-hook 'cargo-minor-mode)
             (local-set-key (kbd "TAB") #'company-indent-or-complete-common)
             (local-set-key (kbd "C-c <tab>") #'rust-format-buffer)))

(shell-command-to-string "echo rustc --print sysroot/lib/rustlib/src/rust/src") should get the right path every-time, can come in handy for some of us.

@azzamsa
Copy link

azzamsa commented Aug 7, 2018

After adding these code as mentioned here #27 (comment). racer completion works great for me.

(setq racer-cmd "~/.cargo/bin/racer")
  (setq racer-rust-src-path (expand-file-name (getenv "RUST_SRC_PATH")))

printl - nothing (expected: println!). Is that because println! is a macro?

@kovrik but it's works well on my machine.

racer-works

@kngwyu
Copy link
Collaborator

kngwyu commented Aug 8, 2018

@azzamsa
Completion for std macros is a new feature since 2.1 🙂

@azzamsa
Copy link

azzamsa commented Aug 9, 2018

@kngwyu :). That's great, just jump to rust this week.
So this is racer-rust/racer#389 the remaining feature.

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