Vscode & code completion for external crates - inferred types?


I'm trying to write a simple GUI using fltk crate.
Getting lib working seems like a no problem task -> Cargo.toml, use:: statements, example code compiles & runs/works just fine.

Problem however i run into is with code-completion, and how to be able to work realistically with the crate and its API... (without manually reading API manual in separate window, i might be a bit too spoiled after years in other languages)

this seems to be basically identical to e.g. this extension issue reported on rust-lang - i observe very same with rust-analyzer.

Example code excerpt:

let mut window = window::Window::default()
.with_size(width: consts::WX, height: consts::WY)

I can see that some parts do have correctly inferred types:

  • vscode shows parts wrapped in <> (blue color) above as inferred names etc.
  • mouse hover shows hints for functions/parameters
  • click-through works to navigate to library .rs files, finds function definitions etc. (with_size, center_screen, ...)

When i navigate to the "problematic" methods/functions, i see:

/// Defines the methods implemented by all window widgets
pub unsafe trait WindowExt: GroupExt {
    /// Positions the window to the center of the screen
    fn center_screen(self) -> Self;

So far, so good, resp. i understand that there's some dark magic to be done due to type inference etc.
Code completion however does not offer any of the WindowExt trait's methods.

Here, i start to lose track a bit lot, and do not understand whether this is:

  • issue of the library not being written "properly" to allow type inference for provided example code (that is from lib's own manual/pages)
  • issue of rust-analyser / rls (tried both) or some of their settings

I do not have more advanced in-depth understanding of Rust as such yet.
When I tried to work around with various rather brute-force attempts, i run into various errors depending on attampt/wrapper function i tried to write around Window.default() from above excerpt... (Box<>, impl Trait, &dyn ref).

Is it possible to "enable" the explicit type-inference and code completion by some artificial extra code/wrappers when using lib's functions/methods? Or is this up to IDE/ language servers to add some functionality to allow such code completion?

meanwhile, i'm going back to munch through the book and "advanced" sections like object traits, dynamic dispatch etc. that seem to be relevant, but out of my understanding yet..

thanks to all for potential pointers and/or references to terms to be googled/read about. :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.