Skip to content
7 changes: 1 addition & 6 deletions crates/ruff_python_ast/src/visitor/source_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,7 @@ impl TraversalSignal {
}

pub fn walk_annotation<'a, V: SourceOrderVisitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
let node = AnyNodeRef::from(expr);
if visitor.enter_node(node).is_traverse() {
visitor.visit_expr(expr);
}

visitor.leave_node(node);
visitor.visit_expr(expr);
}

pub fn walk_decorator<'a, V>(visitor: &mut V, decorator: &'a Decorator)
Expand Down
10 changes: 7 additions & 3 deletions crates/ty_ide/src/find_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ pub(crate) fn covering_node(root: AnyNodeRef, range: TextRange) -> CoveringNode
if visitor.ancestors.is_empty() {
visitor.ancestors.push(root);
}
CoveringNode {
nodes: visitor.ancestors,
}
CoveringNode::from_ancestors(visitor.ancestors)
}

/// The node with a minimal range that fully contains the search range.
Expand All @@ -67,6 +65,12 @@ pub(crate) struct CoveringNode<'a> {
}

impl<'a> CoveringNode<'a> {
/// Creates a new `CoveringNode` from a list of ancestor nodes.
/// The ancestors should be ordered from root to the covering node.
pub(crate) fn from_ancestors(ancestors: Vec<AnyNodeRef<'a>>) -> Self {
Self { nodes: ancestors }
}

/// Returns the covering node found.
pub(crate) fn node(&self) -> AnyNodeRef<'a> {
*self
Expand Down
416 changes: 267 additions & 149 deletions crates/ty_ide/src/goto.rs

Large diffs are not rendered by default.

34 changes: 23 additions & 11 deletions crates/ty_ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod goto_type_definition;
mod hover;
mod inlay_hints;
mod markup;
mod references;
mod semantic_tokens;
mod signature_help;
mod stub_mapping;
Expand All @@ -18,6 +19,7 @@ pub use goto::{goto_declaration, goto_definition, goto_type_definition};
pub use hover::hover;
pub use inlay_hints::inlay_hints;
pub use markup::MarkupKind;
pub use references::references;
pub use semantic_tokens::{
SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens, semantic_tokens,
};
Expand Down Expand Up @@ -86,6 +88,15 @@ pub struct NavigationTarget {
}

impl NavigationTarget {
/// Creates a new `NavigationTarget` where the focus and full range are identical.
pub fn new(file: File, range: TextRange) -> Self {
Self {
file,
focus_range: range,
full_range: range,
}
}

pub fn file(&self) -> File {
self.file
}
Expand Down Expand Up @@ -291,6 +302,7 @@ mod tests {
));

let mut cursor: Option<Cursor> = None;

for &Source {
ref path,
ref contents,
Expand All @@ -299,19 +311,19 @@ mod tests {
{
db.write_file(path, contents)
.expect("write to memory file system to be successful");
let Some(offset) = cursor_offset else {
continue;
};

let file = system_path_to_file(&db, path).expect("newly written file to existing");
// This assert should generally never trip, since
// we have an assert on `CursorTestBuilder::source`
// to ensure we never have more than one marker.
assert!(
cursor.is_none(),
"found more than one source that contains `<CURSOR>`"
);
cursor = Some(Cursor { file, offset });

if let Some(offset) = cursor_offset {
// This assert should generally never trip, since
// we have an assert on `CursorTestBuilder::source`
// to ensure we never have more than one marker.
assert!(
cursor.is_none(),
"found more than one source that contains `<CURSOR>`"
);
cursor = Some(Cursor { file, offset });
}
}

let search_paths = SearchPathSettings::new(vec![SystemPathBuf::from("/")])
Expand Down
Loading
Loading