mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 04:45:05 +00:00
Add fuel to find_path
This commit is contained in:
parent
f94d34bd72
commit
f1dbb958c8
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
//! An algorithm to find a path to refer to a certain item.
|
//! An algorithm to find a path to refer to a certain item.
|
||||||
|
|
||||||
use std::{cmp::Ordering, iter};
|
use std::{cell::Cell, cmp::Ordering, iter};
|
||||||
|
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
name::{known, AsName, Name},
|
name::{known, AsName, Name},
|
||||||
|
@ -49,6 +49,7 @@ pub fn find_path(
|
||||||
ignore_local_imports,
|
ignore_local_imports,
|
||||||
from,
|
from,
|
||||||
from_def_map: &from.def_map(db),
|
from_def_map: &from.def_map(db),
|
||||||
|
fuel: Cell::new(FIND_PATH_FUEL),
|
||||||
},
|
},
|
||||||
item,
|
item,
|
||||||
MAX_PATH_LEN,
|
MAX_PATH_LEN,
|
||||||
|
@ -70,6 +71,7 @@ fn zip_stability(a: Stability, b: Stability) -> Stability {
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_PATH_LEN: usize = 15;
|
const MAX_PATH_LEN: usize = 15;
|
||||||
|
const FIND_PATH_FUEL: usize = 10000;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum PrefixKind {
|
pub enum PrefixKind {
|
||||||
|
@ -101,6 +103,7 @@ struct FindPathCtx<'db> {
|
||||||
ignore_local_imports: bool,
|
ignore_local_imports: bool,
|
||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
from_def_map: &'db DefMap,
|
from_def_map: &'db DefMap,
|
||||||
|
fuel: Cell<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to find a path to refer to the given `item` visible from the `from` ModuleId
|
/// Attempts to find a path to refer to the given `item` visible from the `from` ModuleId
|
||||||
|
@ -314,6 +317,17 @@ fn calculate_best_path(
|
||||||
// the item's name itself.
|
// the item's name itself.
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
let fuel = ctx.fuel.get();
|
||||||
|
if fuel == 0 {
|
||||||
|
// we ran out of fuel, so we stop searching here
|
||||||
|
tracing::warn!(
|
||||||
|
"ran out of fuel while searching for a path for item {item:?} of krate {:?} from krate {:?}",
|
||||||
|
item.krate(ctx.db),
|
||||||
|
ctx.from.krate()
|
||||||
|
);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
ctx.fuel.set(fuel - 1);
|
||||||
|
|
||||||
let mut best_path = None;
|
let mut best_path = None;
|
||||||
let mut best_path_len = max_len;
|
let mut best_path_len = max_len;
|
||||||
|
|
Loading…
Reference in a new issue