Stream: t-compiler/wg-rls-2.0

Topic: vim support


Andrew Chin (Jul 05 2019 at 18:20, on Zulip):

Hello all! I have a question about rust-analyzer with coc.vim. I've got it setup and working correctly as far as I can see (things like tab completion and go-to definition are working well), but I'm stuck trying to get it to report errors. Does anyone know if this is supported at the moment, and if so, is any special config needed?

matklad (Jul 05 2019 at 18:24, on Zulip):

We just don't report a ton of errors at the moment: only syntax errors and some semnatic errors, like a missing field in a struct literal

matklad (Jul 05 2019 at 18:25, on Zulip):

the best way to get the full set of errors is using cargo watch

Andrew Chin (Jul 05 2019 at 18:26, on Zulip):

ahh, ok. well that answers my question then. thanks!

matklad (Jul 05 2019 at 18:33, on Zulip):

Do you get syntax errors though?

Andrew Chin (Jul 05 2019 at 18:37, on Zulip):

no, i didn't seem to get those either

Andrew Chin (Jul 05 2019 at 18:40, on Zulip):

hmm, well now that i try it again, i do see syntax errors reported

Andrew Chin (Jul 05 2019 at 18:42, on Zulip):

and i confirm that i do see errors on missing struct fields.

Andrew Chin (Jul 05 2019 at 18:43, on Zulip):

so it seems like it's all working correctly

Andrew Chin (Jul 05 2019 at 18:44, on Zulip):

this is pretty cool!

Ihor Antonov (Jul 10 2019 at 00:41, on Zulip):

Hi guys, I am trying to look into https://github.com/autozimu/LanguageClient-neovim/issues/848 but the first problem I encountered is that I don't know how to setup all the moving bits and pieces together for productive debugging. Let me explain a bit : it is a complicated setup of editor (nvim), language client plugin, and language server. Problems can potentially happen in any of the three main components. It is not clear for me what is the most effective way of monitoring the communication between server and client? Does anybody have experience of setting dev environment for fast and efficient dev-test cycles with rust analyzer? Any advice, even most general, is appreciated!

matklad (Jul 10 2019 at 08:52, on Zulip):

For VS Code, the thing that really helps is client-side logging. VS Code shows the trace of all LSP messages, as well as any additional stderr from the server

matklad (Jul 10 2019 at 08:52, on Zulip):

I think setting up something like this for VIM would be wise

Ihor Antonov (Jul 10 2019 at 18:56, on Zulip):

@matklad

We just don't report a ton of errors at the moment: only syntax errors and some semantic errors, like a missing field in a struct literal

I have noticed that RLS reports a lot of errors (I'd say everything that cargo shows). Is that because RLS has cargo "embedded"? For obvious reasons running cargo watch on the side is not super convenient. Is there a plan for ra to report all errors and what is the planned architecture?

qmx (Jul 12 2019 at 01:43, on Zulip):

Hello all! I have a question about rust-analyzer with coc.vim. I've got it setup and working correctly as far as I can see (things like tab completion and go-to definition are working well), but I'm stuck trying to get it to report errors. Does anyone know if this is supported at the moment, and if so, is any special config needed?

do you get a freeze and further 30s timeout after using jump to definition?

qmx (Jul 12 2019 at 01:45, on Zulip):

@matklad what's the policy for things like vim-integration problems? Should we file gh issues too? Just discuss them here?

matklad (Jul 12 2019 at 07:23, on Zulip):

It probably makes sense to file issues, yeah. Looking into the problems would also help ;) Neither me nor Florian are using vim :(

matklad (Jul 12 2019 at 07:25, on Zulip):

For obvious reasons running cargo watch on the side is not super convenient. Is there a plan for ra to report all errors and what is the planned architecture?

@Ihor Antonov For starters, we plan to just run cargo watch: that's simple and is actually faster than RLS. Currently this is implemented in VS Code on the client side. We plan to move cargo watch management to the language server

Ihor Antonov (Jul 12 2019 at 11:21, on Zulip):

@matklad

For obvious reasons running cargo watch on the side is not super convenient. Is there a plan for ra to report all errors and what is the planned architecture?

Ihor Antonov For starters, we plan to just run cargo watch: that's simple and is actually faster than RLS. Currently this is implemented in VS Code on the client side. We plan to move cargo watch management to the language server

So does this mean that RA will run cargo watch as a child process and then bubble up errors to the editor in form of LSP diagnostics?

matklad (Jul 12 2019 at 11:22, on Zulip):

More or less yes. Most likely though, we will be calling cargo as a subprocess, not cargo watch, and that we might also ask it to produce save-analysis data, in addition to just diagnostics

matklad (Jul 12 2019 at 11:23, on Zulip):

to clarify, the end game here is absolutely to just produce all errors on the fly from withing rust-analyze itself, using a salsa-based incremental compiler. We are very far from that at the moment though, so leveraging cargo check seems like a good idea in the meantime

Ihor Antonov (Jul 12 2019 at 11:37, on Zulip):

I agree and I like it, it follows Unix philosophy

Ihor Antonov (Jul 12 2019 at 11:37, on Zulip):

Thanks for the clarifications

Jane Lusby (Aug 17 2019 at 20:09, on Zulip):

I'm having some trouble figuring out how to enable cargo watch integration with rust-analyzer. This is already available right? I'm using coc.nvim and tried

```{
"languageserver": {
"rust": {
"command": "ra_lsp_server",
"filetypes": ["rust"],
"rootPatterns": ["Cargo.toml"]
}
},
"rust-analyzer.enableCargoWatchOnStartup": "ask"
}


Jane Lusby (Aug 17 2019 at 20:09, on Zulip):

but nothing seems to happen, I've tried using vscode and it will give me a prompt to enable cargo watch, but after clicking yes nothing visibly happens

Jane Lusby (Aug 17 2019 at 20:10, on Zulip):

running cargo watch independently seems to work wel

Jane Lusby (Aug 17 2019 at 20:27, on Zulip):

I've also tried "enabled" instead of "ask"

Pascal (Aug 17 2019 at 21:19, on Zulip):

i think the settings listed on https://github.com/rust-analyzer/rust-analyzer/blob/2bac1bdf174a053f0727e982f0f92d068ef3c208/docs/user/README.md#settings are only for the vscode ext. from what i can tell cargo-watch run completely separate to ra_lsp_server

Jane Lusby (Aug 17 2019 at 21:35, on Zulip):

Ooh, sad face

Pascal (Aug 18 2019 at 16:57, on Zulip):

maybe you can make a cargo-watch vim extension based on this impl? https://github.com/rust-analyzer/rust-analyzer/tree/2bac1bdf174a053f0727e982f0f92d068ef3c208/editors/code/src/utils/diagnostics

Jane Lusby (Aug 19 2019 at 17:47, on Zulip):

I was going to set up ale-vim to just run cargo for me on save because that composes well with coc.nvim + rust-analyzer

Jane Lusby (Aug 19 2019 at 17:48, on Zulip):

a vim extension for cargo watch would eventually be deprecated anyways right? My understanding is that ra-lsp will eventually have an incremental compiler built in

simlay (Apr 09 2020 at 03:13, on Zulip):

Anyone know how to make https://github.com/autozimu/LanguageClient-neovim work with the rust-analyzer.additionalOutDirs key?

simlay (Apr 09 2020 at 03:42, on Zulip):

hmm, looks like "rust-analyzer.cargoFeatures.loadOutDirsFromCheck": true

simlay (Apr 09 2020 at 03:43, on Zulip):

Well, after reading a bunch of the neovim client's docs, the file to modify is .vim/settings.json in your project directory but you can change that if you want

simlay (Apr 09 2020 at 03:43, on Zulip):

You'll need let g:LanguageClient_loadSettings = 1 in your vimrc as well.

simlay (Apr 09 2020 at 03:44, on Zulip):

My actual goal is to get expansions for the include!(concat!(env!("OUT_DIR"), "/foo.rs")) pattern.

simlay (Apr 09 2020 at 03:46, on Zulip):

I can't seem to get that working

simlay (Apr 09 2020 at 03:46, on Zulip):

One fear I have is that because I'm targeting x86_64-apple-ios, it doesn't expand

matklad (Apr 09 2020 at 07:07, on Zulip):

One fear I have is that because I'm targeting x86_64-apple-ios, it doesn't expand

Hm, interesting! I haven't tried rust-analyzer in cross-compilation scenarios, it might be that you need to pass --target flag somehow, but I am not sure if we can override it in any case

matklad (Apr 09 2020 at 07:07, on Zulip):

I think that for loadOutDirs functionality we are running cargo for host

matklad (Apr 09 2020 at 07:09, on Zulip):

If you happen to feel like diving into the source code, the out dir loading happens here: https://github.com/rust-analyzer/rust-analyzer/blob/080c983498afcac3eb54028af5c9f8bfe7f2c826/crates/ra_project_model/src/cargo_workspace.rs#L275-L319

simlay (Apr 09 2020 at 18:17, on Zulip):

Yeah, so I've got the default target for this project set in .cargo/config as x86_64-apple-ios. I've verified that this works by doing a cargo clean and then opening vim (which opens rust-analyzer), which then I assume runs cargo check through the load_extern_resources function.

simlay (Apr 09 2020 at 19:59, on Zulip):

At which point my version of include!(concat!(env!("OUT_DIR"), "/foo.rs")) is built but I can't seem to jump to definitions in it.

Edwin Cheng (Apr 09 2020 at 21:01, on Zulip):

Jump to definitions for include! macro is not implemented yet but completion should works.

simlay (Apr 09 2020 at 21:43, on Zulip):

ah, that's good to know.

Last update: Sep 30 2020 at 16:15UTC