Skip to content

Doom Emacs code suggestions do not work for std, works for rls #11580

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

Closed
Schievel1 opened this issue Feb 28, 2022 · 18 comments
Closed

Doom Emacs code suggestions do not work for std, works for rls #11580

Schievel1 opened this issue Feb 28, 2022 · 18 comments

Comments

@Schievel1
Copy link

Schievel1 commented Feb 28, 2022

rust-analyzer version: (eg. output of "Rust Analyzer: Show RA Version" command)
dev-util/rust-analyzer
Latest version available: 20220222
Latest version installed: 20220222
Size of files: 33.387 KiB
Homepage: https://rust-analyzer.github.io
Description: An implementation of Language Server Protocol for the Rust programming language
License: 0BSD Apache-2.0 Artistic-2 BSD Boost-1.0 CC0-1.0 ISC MIT Unlicense ZLIB

rustc version: (eg. output of rustc -V)
rustc 1.58.1-nightly (gentoo)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)
which rustc
/usr/bin/rustc

which cargo
/usr/bin/cargo

Steps to reproduce:

  • install rust via portage with use flags clippy, nightly, rls, rust-src and rustfmt
  • install fresh emacs via portage
  • install doom emacs on top of that with ~/.emacs.d/bin/doom install
  • enable lsp and (rust +lsp) in ~/.doom.d/init.el (company mode code suggestion are already enabled by default)
  • put (after! rustic
    (setq rustic-lsp-server 'rust-analyzer)) into ~/.doom.d/config.el so rust-analyzer is loaded instead of rls when opening a .rs
  • run ~/.emacs.d/bin/doom

So I do not get code suggestions from company-mode for std things. It works for code snippets like fn, if etc.
I tried changing RUST_SRC_PATH to
/usr/lib/rust/1.58.1/lib/rustlib/src/rust/library/ and /usr/lib/rust/1.58.1/lib/rustlib/src/rust/src via export in zsh, then doing the ~/.emacs.d/bin/doom env dance to have this environment variable in doom emacs as well. The environment variable exists in ~/.emacs.d/.local/env.

In the minibuffer it says LSP :: Error from the Language Server: waiting for cargo metadata or cargo check (Unknown error) [2 times]

@flodiebold
Copy link
Member

Is there any output in the *rust-analyzer: stderr* buffer? What does ls $(rustc --print sysroot)/lib/rustlib/src/rust/library print?

@apmanol
Copy link

apmanol commented Feb 28, 2022

Similar issue here with the upgrade to the latest:

rust-analyzer --version 
rust-analyzer 4e72700e3 2022-02-28 dev

and plain emacs with lsp and rustic-mode

cargo init tttt
cd ttt && emacs src/main.rs 
LSP :: Connected to [rust-analyzer:28488/starting]. [2 times]
LSP :: rust-analyzer:28488 initialized successfully in folders: (/tmp/ttt)
LSP :: Error from the Language Server: waiting for cargo metadata or cargo check (Unknown error) [8 times]

There is nothing *rust-analyzer: stderr*

ls $(rustc --print sysroot)/lib/rustlib/src/rust/library 
alloc  backtrace  core  panic_abort  panic_unwind  portable-simd  proc_macro  profiler_builtins  rtstartup  rustc-std-workspace-alloc  rustc-std-workspace-core  rustc-std-workspace-std  std  stdarch  test  unwind

@flodiebold
Copy link
Member

Do you get completions for e.g. local variables? You only mentioned snippets.

@TheEros
Copy link

TheEros commented Feb 28, 2022

Normal output does not affect use

@Schievel1
Copy link
Author

Is there any output in the *rust-analyzer: stderr* buffer? What does ls $(rustc --print sysroot)/lib/rustlib/src/rust/library print?

Nothing in rust-analyzer: stderr.

ls $(rustc --print sysroot)/lib/rustlib/src/rust/library

alloc      core         panic_unwind   proc_macro         rtstartup                  rustc-std-workspace-core  std      test
backtrace  panic_abort  portable-simd  profiler_builtins  rustc-std-workspace-alloc  rustc-std-workspace-std   stdarch  unwind

@Schievel1
Copy link
Author

Do you get completions for e.g. local variables? You only mentioned snippets.

no, only keywords and snippets

@flodiebold
Copy link
Member

Can you show an example of the completions you're getting? Also it'd be interesting to do lsp-toggle-trace-io, then get completions, and then provide the results from lsp-switch-to-io-log-buffer.

@Schievel1
Copy link
Author

I get a completion for if:
Screenshot from 2022-02-28 12-08-16
but nothing for a local variable or for println!:
Screenshot from 2022-02-28 12-08-54

@Schievel1
Copy link
Author

also here is the result from lsp-toggle-trace-io, typing prin, deleting it then typing if and enter.
https://pastebin.com/x9zzS3ai

@bjorn3
Copy link
Member

bjorn3 commented Feb 28, 2022

LSP :: Error from the Language Server: waiting for cargo metadata or cargo check (Unknown error) [8 times]

What does running cargo metadata show?

@Schievel1
Copy link
Author

LSP :: Error from the Language Server: waiting for cargo metadata or cargo check (Unknown error) [8 times]

What does running cargo metadata show?
https://pastebin.com/pYykNhrX

@Schievel1
Copy link
Author

I also installed toolchain nightly, installed rust-src and clippy for it, unset RUST_SRC_PATH, did export PATH="/home/pascal/.cargo/bin:$PATH" and doom env.
Same result.
Same when it set export RUST_SRC_PATH=/home/pascal/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library and doom env again.

@Schievel1
Copy link
Author

wait a sec. this has something to do with rustlings. If I do cargo new ./bla and edit ./bla/src/main.rs it suggests println! just fine.

@lnicola
Copy link
Member

lnicola commented Feb 28, 2022

Yeah, Rustlings has a weird project structure, it doesn't work very well with RA (and had trouble with RLS in the past, I think).

@Schievel1
Copy link
Author

sorry about that then. And thanks for your time and help.
I am going to close this here.

@flodiebold
Copy link
Member

There's a PR that generates a rust-analyzer project file for rustlings.

@jackos
Copy link
Contributor

jackos commented Mar 1, 2022

You can do this to fix your project to work with rust analyzer until that PR is merged:

# Install rustlings-fix from cargo
cargo install rustlings-fix

# Change directory into wherever rustlings is cloned
cd ~/src/rustlings

# Run the binary
rustlings-fix

@Schievel1
Copy link
Author

You can do this to fix your project to work with rust analyzer until that PR is merged:

# Install rustlings-fix from cargo
cargo install rustlings-fix

# Change directory into wherever rustlings is cloned
cd ~/src/rustlings

# Run the binary
rustlings-fix

works like a charm. you guys are awesome! thanks

but now I have to learn some rust then instead of playing around with emacs all day long... :D

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

7 participants