6

I figured out how to make Diesel work with my project, but when I try to use a functionality from the schema module, I get no code completion suggestions from VS Code with the RLS extension installed.

I also tried to get suggestions with the IntelliJ Rust plugin without any success; maybe I'm missing something. The problem seems to come from macro usage.

#[macro_use]
extern crate diesel;
use diesel::prelude::*;

mod db;
mod models;
mod schema;

use models::post::Post;

#[get("/")]
fn main() {
    use schema::posts::dsl::*;

    let connection = db::establish_connection();
    let results = posts.load::<Post>(&connection).unwrap();

    for post in results {
        println!("{}", post.content);
    }
}

The code works but I get nothing from VS Code after I write posts. or schema::.

This seems to me to be a big feature from Diesel and I can't believe code completion is impossible with it.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
carlOS
  • 61
  • 2

1 Answers1

1

Intellij-rust has very poor macro/generated code support right now. While diesel generated a file that is in idea's indexing path, its use of macro internally makes it unable to expand and get autocompletion, because running the macro requires executing the diesel procedural macro, which spawns an actual process, rendering it impractical to automatically be done in terms of performance.

If you really want such a thing, something very troublesome yet marginally usable would be to use cargo expand to expand the diesel-generated module, then copy and paste the result in place of the diesel macro call. Nevertheless, it is impractical to do this every time, especially with VCS, but it might be useful for learning the diesel API.

SOFe
  • 7,867
  • 4
  • 33
  • 61