mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
make parent module cancelable
This commit is contained in:
parent
61518580ed
commit
c4b0d3cd56
3 changed files with 16 additions and 6 deletions
|
@ -20,7 +20,7 @@ use crate::{
|
||||||
descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem},
|
descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem},
|
||||||
roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
|
roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
|
||||||
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position,
|
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position,
|
||||||
Query, SourceChange, SourceFileEdit,
|
Query, SourceChange, SourceFileEdit, Cancelable,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -157,10 +157,10 @@ impl AnalysisImpl {
|
||||||
}
|
}
|
||||||
query.search(&buf, token)
|
query.search(&buf, token)
|
||||||
}
|
}
|
||||||
pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> {
|
pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
let root = self.root(file_id);
|
let root = self.root(file_id);
|
||||||
let module_tree = root.module_tree();
|
let module_tree = root.module_tree();
|
||||||
module_tree
|
let res = module_tree
|
||||||
.parent_modules(file_id)
|
.parent_modules(file_id)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|link| {
|
.map(|link| {
|
||||||
|
@ -174,7 +174,8 @@ impl AnalysisImpl {
|
||||||
};
|
};
|
||||||
(file_id, sym)
|
(file_id, sym)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect();
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
|
pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
|
||||||
let module_tree = self.root(file_id).module_tree();
|
let module_tree = self.root(file_id).module_tree();
|
||||||
|
|
|
@ -42,6 +42,15 @@ pub struct Cancel;
|
||||||
|
|
||||||
pub type Cancelable<T> = Result<T, Cancel>;
|
pub type Cancelable<T> = Result<T, Cancel>;
|
||||||
|
|
||||||
|
impl std::fmt::Display for Cancel {
|
||||||
|
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
fmt.write_str("Canceled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Cancel {
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct FileId(pub u32);
|
pub struct FileId(pub u32);
|
||||||
|
|
||||||
|
@ -225,7 +234,7 @@ impl Analysis {
|
||||||
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, TextRange)> {
|
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, TextRange)> {
|
||||||
self.imp.find_all_refs(file_id, offset, token)
|
self.imp.find_all_refs(file_id, offset, token)
|
||||||
}
|
}
|
||||||
pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> {
|
pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
self.imp.parent_module(file_id)
|
self.imp.parent_module(file_id)
|
||||||
}
|
}
|
||||||
pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
|
pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
|
||||||
|
|
|
@ -238,7 +238,7 @@ pub fn handle_parent_module(
|
||||||
) -> Result<Vec<Location>> {
|
) -> Result<Vec<Location>> {
|
||||||
let file_id = params.try_conv_with(&world)?;
|
let file_id = params.try_conv_with(&world)?;
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
for (file_id, symbol) in world.analysis().parent_module(file_id) {
|
for (file_id, symbol) in world.analysis().parent_module(file_id)? {
|
||||||
let line_index = world.analysis().file_line_index(file_id);
|
let line_index = world.analysis().file_line_index(file_id);
|
||||||
let location = to_location(file_id, symbol.node_range, &world, &line_index)?;
|
let location = to_location(file_id, symbol.node_range, &world, &line_index)?;
|
||||||
res.push(location);
|
res.push(location);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue