[][src]Function racer::is_use_stmt

pub fn is_use_stmt<P, C>(file_path: P, cursor: C, session: &Session<'_>) -> bool where
    P: AsRef<Path>,
    C: Into<Location>, 

Finds if the statement where cursor lies is a use statement.

Examples

extern crate racer;
extern crate env_logger;


let _ = env_logger::init();
let cache = racer::FileCache::default();
let session = racer::Session::new(&cache, None);

// This is the file where we request completion from
let src = stringify! {
   use sub::foo;
   use sub::{
        bar
   };
   pub(crate) use sub::baz;
};

// Load files into cache to prevent trying to read from disk
session.cache_file_contents("lib.rs", src);

assert_eq!(racer::is_use_stmt("lib.rs", racer::Location::from(9), &session), true);
assert_eq!(racer::is_use_stmt("lib.rs", racer::Location::from(28), &session), true);
assert_eq!(racer::is_use_stmt("lib.rs", racer::Location::from(5000), &session), false);