Nercury / rust-and-opengl-lessons

Collection of example code for learning OpenGL in Rust
Apache License 2.0
381 stars 52 forks source link

Autocomplete in IntelliJ IDEA #11

Open lukas-shawford opened 4 years ago

lukas-shawford commented 4 years ago

Hey, I'm following your excellent tutorial series. Thank you for writing these!

Towards the end of lesson 6, there is a suggestion about how to get autocomplete to work, which involves copying the auto-generated bindings.rs from the output directory back into the project. That didn't actually work for me (maybe I wasn't copying it to the right place, not sure - I'm completely new to Rust).

But regardless, it seems there is now a better way, at least for IntelliJ. I thought it might be worth updating the lesson with these instructions, since AutoComplete is so immensely helpful for someone who is learning Rust and OpenGL (the target audience of this blog series).

There is an experimental feature of the intellij-rust plugin which allows for auto-completion to work when using:

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

To enable it, open the Maintenance Menu using Ctrl+Shift+Alt+/, select "Experimental Features", then enable the following feature:

org.rust.cargo.fetch.out.dir

intellij_rust_out_dir

Then restart the IDE.

Worked beautifully for me. There is some discussion here as to why the feature is designated as Experimental and disabled by default:

https://github.com/intellij-rust/intellij-rust/pull/4573

And the original issue from intellij-rust is here:

https://github.com/intellij-rust/intellij-rust/issues/1908

Nercury commented 4 years ago

Thank you, this looks really useful!

Trikzon commented 4 years ago

@Nercury I'm using neovim with coc-rust-analyzer, so the above change doesn't work for me.

Could you specify where you would copy bindings.rs to?

I'm relatively new to rust, so it would be helpful instead of the vague explanation currently in the tutorial

Nercury commented 4 years ago

You could copy-paste the contents of the generated file to where the include! macro is, this is what the include macro basically does.

FakeDomi commented 3 years ago

You need to tick org.rust.cargo.evaluate.build.scripts in newer versions of the plugin