pub struct MethodQuery<'a> { /* private fields */ }Expand description
A chainable builder for method queries.
Construct with MethodQuery::new, optionally set deps
and filter, then call run or
run_with_definitions to execute.
§Example
use rust_meth_lib::query::MethodQuery;
use rust_meth_lib::analyzer::find_rust_analyzer;
let ra_path = find_rust_analyzer().unwrap();
let methods = MethodQuery::new("String")
.filter("push")
.run(&ra_path)
.unwrap();
for m in methods {
println!("{}", m.name);
}Implementations§
Source§impl<'a> MethodQuery<'a>
impl<'a> MethodQuery<'a>
Sourcepub const fn new(type_name: &'a str) -> Self
pub const fn new(type_name: &'a str) -> Self
Creates a new query for the given Rust type expression.
§Example
use rust_meth_lib::query::MethodQuery;
let q = MethodQuery::new("Vec<u8>");Sourcepub const fn deps(self, deps: &'a str) -> Self
pub const fn deps(self, deps: &'a str) -> Self
Sets the TOML dependency string for third-party crate types.
Accepts the same format as query_methods, a raw TOML snippet that
would appear under [dependencies]. Multiple crates are
newline-separated.
§Example
use rust_meth_lib::query::MethodQuery;
use rust_meth_lib::analyzer::find_rust_analyzer;
let ra_path = find_rust_analyzer().unwrap();
let methods = MethodQuery::new("serde_json::Value")
.deps(r#"serde_json = "1.0""#)
.run(&ra_path)
.unwrap();Sourcepub const fn filter(self, query: &'a str) -> Self
pub const fn filter(self, query: &'a str) -> Self
Applies a filter to the results after the query completes.
Uses the same scoring as filter_methods: exact > prefix > substring.
Methods that don’t match are excluded from results.
§Example
use rust_meth_lib::query::MethodQuery;
use rust_meth_lib::analyzer::find_rust_analyzer;
let ra_path = find_rust_analyzer().unwrap();
let methods = MethodQuery::new("HashMap<String, u32>")
.filter("get")
.run(&ra_path)
.unwrap();Sourcepub fn run(self, ra_path: &Path) -> Result<Vec<Method>>
pub fn run(self, ra_path: &Path) -> Result<Vec<Method>>
Executes the query and returns matching methods.
Runs query_methods then applies the filter if one was set.
Returns owned Method values.
§Errors
Propagates any error from the underlying LSP session.
Sourcepub fn run_with_definitions(self, ra_path: &Path) -> Result<Vec<MethodResult>>
pub fn run_with_definitions(self, ra_path: &Path) -> Result<Vec<MethodResult>>
Executes the query, applies the filter, and resolves source locations for each matching method sequentially.
Methods where rust-analyzer has no source location are included with
definition: None rather than being silently dropped.
Note: For third-party crate types, each definition query requires Cargo to resolve dependencies inside an ephemeral probe project. With many matching methods this can be slow. Use a tight
filterto limit the number of definition queries, or prefer stdlib types where Cargo resolution is not required.
§Errors
Propagates any fatal LSP error. Per-method Ok(None) definition
results are not errors.