Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add treesitter textobjects #728

Merged
merged 7 commits into from
Oct 23, 2021

Conversation

sudormrfbin
Copy link
Member

@sudormrfbin sudormrfbin commented Sep 8, 2021

helix-tree-sitter-textobject

f for functions and c for classes, so for example mac will select around the current class. Currently only queries for Rust, Python and Golang are included.

TODO

  • Parameter object (inner only)
  • Add docs

Future Works

  • Parameter around object

helix-core/src/syntax.rs Outdated Show resolved Hide resolved
helix-core/src/textobject.rs Outdated Show resolved Hide resolved
runtime/queries/rust/textobjects.scm Outdated Show resolved Hide resolved
@sudormrfbin sudormrfbin force-pushed the treesitter-objects branch 2 times, most recently from 3704d71 to a6a3724 Compare September 9, 2021 11:16
Only parameter.inside is implemented now, parameter.around
will probably require custom predicates akin to nvim' `make-range`
since we want to select a trailing comma too (a comma will be
an anonymous node and matching against them doesn't work similar
to named nodes)
@sudormrfbin
Copy link
Member Author

I've added parameter.inside for now. parameter.around is probably best left as a future addition.

@sudormrfbin
Copy link
Member Author

The default binding for parameter object is p, which will conflict with paragraph objects when they are implemented. I was considering changing parameter to a (for "argument").

Copy link
Member

@archseer archseer left a comment

Choose a reason for hiding this comment

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

Great work on this! Just some minor comments

helix-core/src/syntax.rs Show resolved Hide resolved
helix-core/src/syntax.rs Outdated Show resolved Hide resolved
let selection = doc.selection(view.id).clone().transform(|range| {
match ch {
'w' => textobject::textobject_word(text, range, objtype, count),
'c' => textobject_treesitter("class", range),
Copy link
Member

Choose a reason for hiding this comment

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

I still think we want a better name than class here, maybe type?

Copy link
Member Author

Choose a reason for hiding this comment

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

I left a comment up here about the naming, and I think we should aim for an intuitive name. I think "type" might be a bit misleading ? Though I guess the same can be said for "class" :|

Copy link
Member

@archseer archseer left a comment

Choose a reason for hiding this comment

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

Let's go ahead and merge this 👍🏻

I would still like to find a better keyword than class but we can always replace that later.

@archseer archseer merged commit 4ee92ca into helix-editor:master Oct 23, 2021
@sudormrfbin sudormrfbin deleted the treesitter-objects branch February 1, 2022 14:33
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.

3 participants