[−][src]Function racer::find_definition
pub fn find_definition<P, C>(
filepath: P,
cursor: C,
session: &Session
) -> Option<Match> where
P: AsRef<Path>,
C: Into<Location>,
Find the definition for item at given a file, source, and cursor index
Examples
extern crate racer; extern crate env_logger; use std::path::Path; let _ = env_logger::init(); let cache = racer::FileCache::default(); let session = racer::Session::new(&cache); // This is the file where we request completion from let src = stringify! { mod sub; use sub::foo; fn main() { foo(); }; }; // This is the submodule where the definition is found let sub = stringify! { pub fn foo() {} }; // Load files into cache to prevent trying to read from disk session.cache_file_contents("sub.rs", sub); session.cache_file_contents("lib.rs", src); // Search for the definition. 45 is the byte offset // in `src` after stringify! runs. Specifically, this asks // for the definition of `foo()`. let m = racer::find_definition("lib.rs", racer::Location::from(45), &session) .expect("find definition returns a match"); // Should have found definition in the "sub.rs" file assert_eq!(m.filepath, Path::new("sub.rs")); // The definition should be for foo assert_eq!(&m.matchstr[..], "foo"); // The definition should be a function assert_eq!(m.mtype, racer::MatchType::Function);