Skip to content

4/11: feat(treesitter): add helper module with navigation utilities#657

Merged
juleswritescode merged 3 commits intostacked/pr629-3-benchmarksfrom
stacked/pr629-4-helper-module
Jan 25, 2026
Merged

4/11: feat(treesitter): add helper module with navigation utilities#657
juleswritescode merged 3 commits intostacked/pr629-3-benchmarksfrom
stacked/pr629-4-helper-module

Conversation

@juleswritescode
Copy link
Collaborator

@juleswritescode juleswritescode commented Jan 24, 2026

Summary

  • Add goto_node_at_position, goto_previous_leaf, goto_closest_unfinished_parent_clause
  • Add previous_sibling_completed, last_children_completed
  • Add SINGLE_TOKEN_RULES constant
  • Export functions from lib.rs

Part of stacked PRs for #629

This is PR 4/11 in the keyword completion feature stack.

@juleswritescode juleswritescode changed the title 4/8: feat(treesitter): add helper module with navigation utilities 4/11: feat(treesitter): add helper module with navigation utilities Jan 24, 2026
@@ -0,0 +1,120 @@
use tree_sitter::{Node, Tree};

pub static SINGLE_TOKEN_RULES: &[&'static str] = &[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be generated?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like what is this list / how is it defined?

Copy link
Collaborator Author

@juleswritescode juleswritescode Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some treesitter nodes only ever have one child, such as literal:

program [0..12] 'select true;'
  statement [0..11] 'select true'
    select [0..11] 'select true'
      keyword_select [0..6] 'select'
      select_expression [7..11] 'true'
        term [7..11] 'true'
          literal [7..11] 'true'
            keyword_true [7..11] 'true'
  ; [11..12] ';'

So we're basically saying, "these token rules are always completed".

Alternatively, we could mark all children with an @end tag; I might do that later:

literal: ($) =>
      field("end", prec(
        2,
        choice(
          $._integer,
          $._decimal_number,
          $._literal_string,
          $._bit_string,
          $._string_casting,
          $.keyword_true,
          $.keyword_false,
          $.keyword_null
        )
      )),

@juleswritescode juleswritescode merged commit a78e1e7 into stacked/pr629-3-benchmarks Jan 25, 2026
5 of 8 checks passed
@juleswritescode juleswritescode deleted the stacked/pr629-4-helper-module branch January 25, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants