Skip to content

ltk_ritobin: Extend Visitor API surface #175

Description

@Crauzer

We should extend the Visitor API to make it easily consumable downstream.

Proposal

pub struct VisitCtx<'a> {
    pub cst: &'a Cst,
    text: &'a str,
    ancestors: &'a [NodeId],
}

impl VisitCtx<'_> {
    pub fn text(&self, span: Span) -> &str;
    pub fn ancestors(&self) -> &[NodeId];
    pub fn parent(&self) -> Option<NodeId>;
    pub fn depth(&self) -> usize;
}
// Visitor 
fn enter_tree(&mut self, ctx: &VisitCtx, node: &Node, id: NodeId) -> Visit;
fn exit_tree(&mut self, ctx: &VisitCtx, node: &Node, id: NodeId) -> Visit;
fn visit_token(&mut self, ctx: &VisitCtx, token: &Token, id: TokenId, parent: NodeId) -> Visit;
// Cst
pub fn walk_range<V: Visitor>(&self, range: Span, text: &str, visitor: &mut V)

Related to alanpq/ritobin-lsp#57

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions